commit | f8ebaa498562cfb199a9b28da5eae2770f9b3163 | [log] [tgz] |
---|---|---|
author | Elliott Hughes <enh@google.com> | Fri Aug 12 16:28:36 2016 -0700 |
committer | Elliott Hughes <enh@google.com> | Fri Aug 12 16:28:36 2016 -0700 |
tree | de04a55521fac877356a92a925b3b5487d39d46c | |
parent | cea5c8a6099cff4f3ceccb3309a522bb1cf377b4 [diff] [blame] |
Fix mktime's errno behavior. Don't touch errno on success, do set it to EOVERFLOW (the only allowed errno value according to POSIX: http://pubs.opengroup.org/onlinepubs/9699919799/functions/mktime.html) on failure. Bug: http://b/30477946 Change-Id: Ia915c7b9c3bfcd2f9025530cf5b068fe4dd4fd9e
diff --git a/libc/tzcode/localtime.c b/libc/tzcode/localtime.c index 0861015..cf0fd6b 100644 --- a/libc/tzcode/localtime.c +++ b/libc/tzcode/localtime.c
@@ -2174,6 +2174,10 @@ time_t mktime(struct tm *tmp) { +#if __ANDROID__ + int saved_errno = errno; +#endif + time_t t; int err = lock(); if (err) { @@ -2183,6 +2187,10 @@ tzset_unlocked(); t = mktime_tzname(lclptr, tmp, true); unlock(); + +#if __ANDROID__ + errno = (t == -1) ? EOVERFLOW : saved_errno; +#endif return t; }