diff options
author | Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr> | 2017-09-08 00:41:55 +0200 |
---|---|---|
committer | Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr> | 2018-04-11 22:39:44 +0200 |
commit | 640aac54c154fcc298bf2cc7d3ab26454c535363 (patch) | |
tree | 4bfc07cc883070273a935cc207a78bda93fdc4e1 | |
parent | 6435e375f7014d9191d4240294cbb0914e9d06f2 (diff) | |
download | glibc-640aac54c154fcc298bf2cc7d3ab26454c535363.tar.gz |
Y2038: add function __time64
These implementations use only 32-bit time kernel syscalls.
Therefore, stime() will always set errno to EOVERFLOW and return -1 for dates beyond Y2038.
-rw-r--r-- | sysdeps/posix/time64.c | 41 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/time64.c | 44 | ||||
-rw-r--r-- | time/Makefile | 1 | ||||
-rw-r--r-- | time/Versions | 1 | ||||
-rw-r--r-- | time/time.c | 13 |
5 files changed, 100 insertions, 0 deletions
diff --git a/sysdeps/posix/time64.c b/sysdeps/posix/time64.c new file mode 100644 index 0000000000..ba6e5727d0 --- /dev/null +++ b/sysdeps/posix/time64.c @@ -0,0 +1,41 @@ +/* Copyright (C) 1991-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <stddef.h> /* For NULL. */ +#include <time.h> +#include <sys/time.h> + + +/* Return the current time as a `time_t' and also put it in *T if T is + not NULL. Time is represented as seconds from Jan 1 00:00:00 1970. */ + +__time64_t +__time64 (__time64_t *t) +{ + struct timeval tv32; + __time64_t result; + + if (__gettimeofday (&tv32, (struct timezone *) NULL)) + result = (__time64_t) -1; + else + result = (__time64_t) tv32.tv_sec; + + if (t != NULL) + *t = result; + + return result; +} diff --git a/sysdeps/unix/sysv/linux/time64.c b/sysdeps/unix/sysv/linux/time64.c new file mode 100644 index 0000000000..772246bfd1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/time64.c @@ -0,0 +1,44 @@ +/* Copyright (C) 2005-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <stddef.h> +#include <time.h> + +#include <sysdep.h> + +/* Use 32-bit 'time' syscall until a 64-bit one exists */ + +#ifdef __NR_time + +__time64_t +__time64 (__time64_t *t) +{ + INTERNAL_SYSCALL_DECL (err); + __time64_t res; + + res = INTERNAL_SYSCALL (time, err, 1, NULL); + /* There cannot be any error. */ + if (t != NULL) + *t = res; + return res; +} + +#else + +# include <sysdeps/posix/time64.c> + +#endif diff --git a/time/Makefile b/time/Makefile index 0db1206820..172e8438f2 100644 --- a/time/Makefile +++ b/time/Makefile @@ -31,6 +31,7 @@ headers := time.h sys/time.h sys/timeb.h bits/time.h \ routines := offtime asctime clock ctime ctime_r difftime \ gmtime localtime mktime time \ + time64 \ gettimeofday settimeofday adjtime tzset \ tzfile getitimer setitimer \ stime dysize timegm ftime \ diff --git a/time/Versions b/time/Versions index ac92d742c3..503a4f46cc 100644 --- a/time/Versions +++ b/time/Versions @@ -84,5 +84,6 @@ libc { __sigtimedwait64; __futimes64; __lutimes64; + __time64; } } diff --git a/time/time.c b/time/time.c index 4996d26f13..9703c72464 100644 --- a/time/time.c +++ b/time/time.c @@ -31,3 +31,16 @@ time (time_t *timer) libc_hidden_def (time) stub_warning (time) + +/* 64-bit time version */ + +__time64_t +__time64 (__time64_ *timer) +{ + __set_errno (ENOSYS); + + if (timer != NULL) + *timer = (__time64_t) -1; + return (__time64_t) -1; +} +libc_hidden_def (__time64) |