openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/sys-utils/hwclock.c
static int read_adjtime(const struct hwclock_control* ctl,
                        struct adjtime* adjtime_p)
{
    FILE* adjfile;
    char line1[81]; /* String: first line of adjtime file */
    char line2[81]; /* String: second line of adjtime file */
    char line3[81]; /* String: third line of adjtime file */

    if (access(ctl->adj_file_name, R_OK) != 0)
        return EXIT_SUCCESS;

    adjfile = fopen(ctl->adj_file_name, "r"); /* open file for reading */
    if (adjfile == NULL)
    {
        warn(_("cannot open %s"), ctl->adj_file_name);
        return EXIT_FAILURE;
    }

    if (!fgets(line1, sizeof(line1), adjfile))
        line1[0] = '\0'; /* In case fgets fails */
    if (!fgets(line2, sizeof(line2), adjfile))
        line2[0] = '\0'; /* In case fgets fails */
    if (!fgets(line3, sizeof(line3), adjfile))
        line3[0] = '\0'; /* In case fgets fails */

    fclose(adjfile);

    sscanf(line1, "%lf %ld %lf", &adjtime_p->drift_factor,
           &adjtime_p->last_adj_time, &adjtime_p->not_adjusted);

    sscanf(line2, "%ld", &adjtime_p->last_calib_time);

    if (!strcmp(line3, "UTC\n"))
    {
        adjtime_p->local_utc = UTC;
    }
    else if (!strcmp(line3, "LOCAL\n"))
    {
        adjtime_p->local_utc = LOCAL;
    }
    else
    {
        adjtime_p->local_utc = UNKNOWN;
        if (line3[0])
        {
            warnx(_("Warning: unrecognized third line in adjtime file\n"
                    "(Expected: `UTC' or `LOCAL' or nothing.)"));
        }
    }

    if (ctl->verbose)
    {
        printf(_("Last drift adjustment done at %ld seconds after 1969\n"),
               (long)adjtime_p->last_adj_time);
        printf(_("Last calibration done at %ld seconds after 1969\n"),
               (long)adjtime_p->last_calib_time);
        printf(_("Hardware clock is on %s time\n"),
               (adjtime_p->local_utc == LOCAL)
                   ? _("local")
                   : (adjtime_p->local_utc == UTC) ? _("UTC") : _("unknown"));
    }

    return EXIT_SUCCESS;
}
/*
 * Read the adjustment parameters out of the /etc/adjtime file.
 *
 * Return them as the adjtime structure <*adjtime_p>. Its defaults are
 * initialized in main().
 */
Read the adjustment parameters out of the /etc/adjtime file.
Return them as the adjtime structure <*adjtime_p>. Its defaults are
initialized in main().
Read the adjustment parameters out of the / etc / adjtime file . Return them as the adjtime structure < * adjtime_p > . Its defaults are initialized in main () .
static int read_adjtime(const struct hwclock_control* ctl,
                        struct adjtime* adjtime_p)
{
    FILE* adjfile;
    char line1[81]; 
    char line2[81]; 
    char line3[81]; 
    if (access(ctl->adj_file_name, R_OK) != 0)
        return EXIT_SUCCESS;
    adjfile = fopen(ctl->adj_file_name, "r"); 
    if (adjfile == NULL)
    {
        warn(_("cannot open %s"), ctl->adj_file_name);
        return EXIT_FAILURE;
    }
    if (!fgets(line1, sizeof(line1), adjfile))
        line1[0] = '\0'; 
    if (!fgets(line2, sizeof(line2), adjfile))
        line2[0] = '\0'; 
    if (!fgets(line3, sizeof(line3), adjfile))
        line3[0] = '\0'; 
    fclose(adjfile);
    sscanf(line1, "%lf %ld %lf", &adjtime_p->drift_factor,
           &adjtime_p->last_adj_time, &adjtime_p->not_adjusted);
    sscanf(line2, "%ld", &adjtime_p->last_calib_time);
    if (!strcmp(line3, "UTC\n"))
    {
        adjtime_p->local_utc = UTC;
    }
    else if (!strcmp(line3, "LOCAL\n"))
    {
        adjtime_p->local_utc = LOCAL;
    }
    else
    {
        adjtime_p->local_utc = UNKNOWN;
        if (line3[0])
        {
            warnx(_("Warning: unrecognized third line in adjtime file\n"
                    "(Expected: `UTC' or `LOCAL' or nothing.)"));
        }
    }
    if (ctl->verbose)
    {
        printf(_("Last drift adjustment done at %ld seconds after 1969\n"),
               (long)adjtime_p->last_adj_time);
        printf(_("Last calibration done at %ld seconds after 1969\n"),
               (long)adjtime_p->last_calib_time);
        printf(_("Hardware clock is on %s time\n"),
               (adjtime_p->local_utc == LOCAL)
                   ? _("local")
                   : (adjtime_p->local_utc == UTC) ? _("UTC") : _("unknown"));
    }
    return EXIT_SUCCESS;
}
static int read_adjtime ( const struct hwclock_control * ctl , struct adjtime * adjtime_p ) { FILE * adjfile ; char line1 [ 81 ] ; char line2 [ 81 ] ; char line3 [ 81 ] ; if ( access ( ctl -> adj_file_name , R_OK ) != 0 ) return EXIT_SUCCESS ; adjfile = fopen ( ctl -> adj_file_name , " " ) ; if ( adjfile == NULL ) { warn ( _ ( " " ) , ctl -> adj_file_name ) ; return EXIT_FAILURE ; } if ( ! fgets ( line1 , sizeof ( line1 ) , adjfile ) ) line1 [ 0 ] = ' \0 ' ; if ( ! fgets ( line2 , sizeof ( line2 ) , adjfile ) ) line2 [ 0 ] = ' \0 ' ; if ( ! fgets ( line3 , sizeof ( line3 ) , adjfile ) ) line3 [ 0 ] = ' \0 ' ; fclose ( adjfile ) ; sscanf ( line1 , " " , & adjtime_p -> drift_factor , & adjtime_p -> last_adj_time , & adjtime_p -> not_adjusted ) ; sscanf ( line2 , " " , & adjtime_p -> last_calib_time ) ; if ( ! strcmp ( line3 , " \n " ) ) { adjtime_p -> local_utc = UTC ; } else if ( ! strcmp ( line3 , " \n " ) ) { adjtime_p -> local_utc = LOCAL ; } else { adjtime_p -> local_utc = UNKNOWN ; if ( line3 [ 0 ] ) { warnx ( _ ( " \n " " " ) ) ; } } if ( ctl -> verbose ) { printf ( _ ( " \n " ) , ( long ) adjtime_p -> last_adj_time ) ; printf ( _ ( " \n " ) , ( long ) adjtime_p -> last_calib_time ) ; printf ( _ ( " \n " ) , ( adjtime_p -> local_utc == LOCAL ) ? _ ( " " ) : ( adjtime_p -> local_utc == UTC ) ? _ ( " " ) : _ ( " " ) ) ; } return EXIT_SUCCESS ; }
Read the adjustment parameters out of the /etc/adjtime file.
Read the adjustment parameters out of the / etc / adjtime file .
/* String: first line of adjtime file */ /* String: second line of adjtime file */ /* String: third line of adjtime file */ /* open file for reading */ /* In case fgets fails */ /* In case fgets fails */ /* In case fgets fails */