diff options
Diffstat (limited to 'src/ls.c')
-rw-r--r-- | src/ls.c | 23 |
1 files changed, 8 insertions, 15 deletions
@@ -3720,20 +3720,20 @@ long_time_expected_width (void) if (width < 0) { time_t epoch = 0; - struct tm const *tm = localtime (&epoch); + struct tm tm; char buf[TIME_STAMP_LEN_MAXIMUM + 1]; - /* In case you're wondering if localtime can fail with an input time_t + /* In case you're wondering if localtime_rz can fail with an input time_t value of 0, let's just say it's very unlikely, but not inconceivable. The TZ environment variable would have to specify a time zone that is 2**31-1900 years or more ahead of UTC. This could happen only on a 64-bit system that blindly accepts e.g., TZ=UTC+20000000000000. However, this is not possible with Solaris 10 or glibc-2.3.5, since their implementations limit the offset to 167:59 and 24:00, resp. */ - if (tm) + if (localtime_rz (localtz, &epoch, &tm)) { size_t len = - align_nstrftime (buf, sizeof buf, long_time_format[0], tm, + align_nstrftime (buf, sizeof buf, long_time_format[0], &tm, localtz, 0); if (len != 0) width = mbsnwidth (buf, len, 0); @@ -3856,7 +3856,7 @@ print_long_format (const struct fileinfo *f) size_t s; char *p; struct timespec when_timespec; - struct tm *when_local; + struct tm when_local; /* Compute the mode string, except remove the trailing space if no file in this directory has an ACL or security context. */ @@ -3983,11 +3983,10 @@ print_long_format (const struct fileinfo *f) p[-1] = ' '; } - when_local = localtime (&when_timespec.tv_sec); s = 0; *p = '\1'; - if (f->stat_ok && when_local) + if (f->stat_ok && localtime_rz (localtz, &when_timespec.tv_sec, &when_local)) { struct timespec six_months_ago; bool recent; @@ -3997,13 +3996,7 @@ print_long_format (const struct fileinfo *f) time, in case the file happens to have been modified since the last time we checked the clock. */ if (timespec_cmp (current_time, when_timespec) < 0) - { - /* Note that gettime may call gettimeofday which, on some non- - compliant systems, clobbers the buffer used for localtime's result. - But it's ok here, because we use a gettimeofday wrapper that - saves and restores the buffer around the gettimeofday call. */ - gettime (¤t_time); - } + gettime (¤t_time); /* Consider a time to be recent if it is within the past six months. A Gregorian year has 365.2425 * 24 * 60 * 60 == 31556952 seconds @@ -4019,7 +4012,7 @@ print_long_format (const struct fileinfo *f) /* We assume here that all time zones are offset from UTC by a whole number of seconds. */ s = align_nstrftime (p, TIME_STAMP_LEN_MAXIMUM + 1, fmt, - when_local, localtz, when_timespec.tv_nsec); + &when_local, localtz, when_timespec.tv_nsec); } if (s || !*p) |