]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
script: don't assume that time_t is compatible with long
authorIsaac Dunham <ibid.ag@gmail.com>
Fri, 16 Oct 2015 01:12:59 +0000 (18:12 -0700)
committerKarel Zak <kzak@redhat.com>
Fri, 16 Oct 2015 09:31:22 +0000 (11:31 +0200)
time_t may change to 64-bit on 32-bit Linux kernels at some point;
at that point, it may be desireable to test for issues with dates
past 2038.

[kzak@redhat.com: - use %jd rather than %lld]

Signed-off-by: Karel Zak <kzak@redhat.com>
term-utils/script.c

index eb4ddc3531f7826567bd5347eb8817f45a30d5e5..67ed8b9ca38e31fafbf042e515db5bf6a5be6c6c 100644 (file)
@@ -141,11 +141,13 @@ static void script_init_debug(void)
 static inline time_t script_time(time_t *t)
 {
        const char *str = getenv("SCRIPT_TEST_SECOND_SINCE_EPOCH");
-       time_t sec;
+       int64_t sec;
 
-       if (str && sscanf(str, "%ld", &sec) == 1)
-               return sec;
-       return time(t);
+       if (!str || sscanf(str, "%jd", &sec) != 1)
+               return time(t);
+       if (t)
+               *t = (time_t)sec;
+       return (time_t)sec;
 }
 #else  /* !TEST_SCRIPT */
 # define script_time(x) time(x)