fix error code on time conversion overflows
authorRich Felker <dalias@aerifal.cx>
Wed, 17 Jul 2013 14:39:11 +0000 (10:39 -0400)
committerRich Felker <dalias@aerifal.cx>
Wed, 17 Jul 2013 14:39:11 +0000 (10:39 -0400)
POSIX mandates EOVERFLOW for this condition.

src/time/gmtime_r.c
src/time/localtime_r.c
src/time/mktime.c
src/time/timegm.c

index 0272870d6e46eb49019239bc8cd938aae7d40f93..fee01bd6ee866434df7c9efe13e21f1fd99572a2 100644 (file)
@@ -5,7 +5,7 @@
 struct tm *__gmtime_r(const time_t *restrict t, struct tm *restrict tm)
 {
        if (__secs_to_tm(*t, tm) < 0) {
-               errno = EINVAL;
+               errno = EOVERFLOW;
                return 0;
        }
        tm->tm_isdst = 0;
index b36c1d825f077f2f53c427b6f683fb03f475b936..c52678fdfeb38fde2684f93cb8a58eaabda3ac1b 100644 (file)
@@ -6,7 +6,7 @@ struct tm *__localtime_r(const time_t *restrict t, struct tm *restrict tm)
 {
        __secs_to_zone(*t, 0, &tm->tm_isdst, &tm->__tm_gmtoff, 0, &tm->__tm_zone);
        if (__secs_to_tm((long long)*t - tm->__tm_gmtoff, tm) < 0) {
-               errno = EINVAL;
+               errno = EOVERFLOW;
                return 0;
        }
        return tm;
index e38b46191c50b1346cb8cafddfe0b85f5ecd14ac..ef1fb4256e76700309cc3ed62cd90d444446bc98 100644 (file)
@@ -25,6 +25,6 @@ time_t mktime(struct tm *tm)
        return t;
 
 error:
-       errno = EINVAL;
+       errno = EOVERFLOW;
        return -1;
 }
index 7148fca32b1c35f8e57ec062465d5be9a878d3d1..e7a7939b3da2dfee380864357519be9a572d039e 100644 (file)
@@ -7,7 +7,7 @@ time_t timegm(struct tm *tm)
        struct tm new;
        long long t = __tm_to_secs(tm);
        if (__secs_to_tm(t, &new) < 0) {
-               errno = EINVAL;
+               errno = EOVERFLOW;
                return -1;
        }
        *tm = new;