aft.c: Prefer localtime() over localtime_r().
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 5 Sep 2015 19:49:16 +0000 (21:49 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 13 Dec 2015 10:30:27 +0000 (11:30 +0100)
While localtime(3) is required to behave as though tzset(3) was
called, localtime_r(3) does not have this requirement, and portable
code should thus call tzset(3) before localtime_r(3). This is not
the case for get_local_time() of aft.c.

As we are single-threaded here, we don't need the thread-safe version,
so it is easiest to switch to localtime(3).

aft.c

diff --git a/aft.c b/aft.c
index 8df2bc6091e55945843e7a93b0eec7f4f5cbf2b3..35e513ffb8a76c099544ac865742810caac10abc 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -676,26 +676,27 @@ int load_afd(int shmid, struct audio_file_data *afd)
 static int get_local_time(uint64_t *seconds, char *buf, size_t size,
        time_t current_time, enum ls_listing_mode lm)
 {
 static int get_local_time(uint64_t *seconds, char *buf, size_t size,
        time_t current_time, enum ls_listing_mode lm)
 {
-       struct tm t;
+       struct tm *tm;
        /*
         * Omit year but show time if the given value is closer to the current
         * time than this many seconds.
         */
        const time_t m = 6 * 30 * 24 * 3600; /* six months */
 
        /*
         * Omit year but show time if the given value is closer to the current
         * time than this many seconds.
         */
        const time_t m = 6 * 30 * 24 * 3600; /* six months */
 
-       if (!localtime_r((time_t *)seconds, &t))
+       tm = localtime((time_t *)seconds);
+       if (!tm)
                return -E_LOCALTIME;
        if (lm == LS_MODE_MBOX) {
                return -E_LOCALTIME;
        if (lm == LS_MODE_MBOX) {
-               if (!strftime(buf, size, "%c", &t))
+               if (!strftime(buf, size, "%c", tm))
                        return -E_STRFTIME;
                return 1;
        }
        if (*seconds > current_time - m && *seconds < current_time + m) {
                        return -E_STRFTIME;
                return 1;
        }
        if (*seconds > current_time - m && *seconds < current_time + m) {
-               if (!strftime(buf, size, "%b %e %k:%M", &t))
+               if (!strftime(buf, size, "%b %e %k:%M", tm))
                        return -E_STRFTIME;
                return 1;
        }
                        return -E_STRFTIME;
                return 1;
        }
-       if (!strftime(buf, size, "%b %e %Y", &t))
+       if (!strftime(buf, size, "%b %e %Y", tm))
                return -E_STRFTIME;
        return 1;
 }
                return -E_STRFTIME;
        return 1;
 }