aboutsummaryrefslogtreecommitdiff
path: root/time
diff options
context:
space:
mode:
Diffstat (limited to 'time')
-rw-r--r--time/mktime.c14
-rw-r--r--time/tst-mktime.c36
2 files changed, 47 insertions, 3 deletions
diff --git a/time/mktime.c b/time/mktime.c
index 5632f14b78..1aec223e0e 100644
--- a/time/mktime.c
+++ b/time/mktime.c
@@ -259,8 +259,10 @@ __mktime_internal (struct tm *tp,
int sec_requested = sec;
- /* Only years after 1970 are defined. */
- if (year < 70)
+ /* Only years after 1970 are defined.
+ If year is 69, it might still be representable due to
+ timezone differences. */
+ if (year < 69)
return -1;
#if LEAP_SECONDS_POSSIBLE
@@ -370,6 +372,14 @@ __mktime_internal (struct tm *tp,
return -1;
}
+ if (year == 69)
+ {
+ /* If year was 69, need to check whether the time was representable
+ or not. */
+ if (t < 0 || t > 2 * 24 * 60 * 60)
+ return -1;
+ }
+
*tp = tm;
return t;
}
diff --git a/time/tst-mktime.c b/time/tst-mktime.c
index 70c123c3f9..7ce1d45dd5 100644
--- a/time/tst-mktime.c
+++ b/time/tst-mktime.c
@@ -5,7 +5,8 @@
int
main (void)
{
- struct tm time_str;
+ struct tm time_str, *tm;
+ time_t t;
char daybuf[20];
int result;
@@ -29,5 +30,38 @@ main (void)
result = strcmp (daybuf, "Wednesday") != 0;
}
+ setenv ("TZ", "EST", 1);
+#define EVENING69 1 * 60 * 60 + 2 * 60 + 29
+ t = EVENING69;
+ tm = localtime (&t);
+ if (tm == NULL)
+ {
+ (void) puts ("localtime returned NULL");
+ result = 1;
+ }
+ else
+ {
+ time_str = *tm;
+ t = mktime (&time_str);
+ if (t != EVENING69)
+ {
+ printf ("mktime returned %ld, expected %ld\n",
+ (long) t, EVENING69);
+ result = 1;
+ }
+ else
+ (void) puts ("Dec 31 1969 EST test passed");
+
+ setenv ("TZ", "CET", 1);
+ t = mktime (&time_str);
+ if (t != (time_t) -1)
+ {
+ printf ("mktime returned %ld, expected -1\n", (long) t);
+ result = 1;
+ }
+ else
+ (void) puts ("Dec 31 1969 CET test passed");
+ }
+
return result;
}