diff options
author | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2016-09-28 17:32:31 -0400 |
---|---|---|
committer | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2016-09-28 17:32:31 -0400 |
commit | 9f518cd01a21ec5162ca83da8feee733d50e376f (patch) | |
tree | 123492edd53d8b66148cbd7de9a139c823f105fa /Python | |
parent | e0083e2b86a116857db41894ec3cc96112af768e (diff) | |
parent | 3e7a3cb903258321a17265a1c01976f88e7b72fc (diff) | |
download | cpython-git-9f518cd01a21ec5162ca83da8feee733d50e376f.tar.gz |
Merged from 3.6
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pytime.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Python/pytime.c b/Python/pytime.c index 02ef8ee7d6..3015a6be0b 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -766,3 +766,55 @@ _PyTime_Init(void) return 0; } + +int +_PyTime_localtime(time_t t, struct tm *tm) +{ +#ifdef MS_WINDOWS + int error; + + error = localtime_s(tm, &t); + if (error != 0) { + errno = error; + PyErr_SetFromErrno(PyExc_OSError); + return -1; + } + return 0; +#else /* !MS_WINDOWS */ + if (localtime_r(&t, tm) == NULL) { +#ifdef EINVAL + if (errno == 0) + errno = EINVAL; +#endif + PyErr_SetFromErrno(PyExc_OSError); + return -1; + } + return 0; +#endif /* MS_WINDOWS */ +} + +int +_PyTime_gmtime(time_t t, struct tm *tm) +{ +#ifdef MS_WINDOWS + int error; + + error = gmtime_s(tm, &t); + if (error != 0) { + errno = error; + PyErr_SetFromErrno(PyExc_OSError); + return -1; + } + return 0; +#else /* !MS_WINDOWS */ + if (gmtime_r(&t, tm) == NULL) { +#ifdef EINVAL + if (errno == 0) + errno = EINVAL; +#endif + PyErr_SetFromErrno(PyExc_OSError); + return -1; + } + return 0; +#endif /* MS_WINDOWS */ +} |