summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/settimeofday.c
diff options
context:
space:
mode:
authorPeter S. Mazinger <ps.m@gmx.net>2011-04-16 11:55:10 +0200
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2012-06-15 14:00:39 +0200
commit1b11d19b60208e1dc932244aba6756eafa1e67ce (patch)
treec9e1f4a9893f09b65b82118eea67df39b239c6aa /libc/sysdeps/linux/common/settimeofday.c
parenta30f4f75a3e4e128594a35e7d6b7e001eee54cb7 (diff)
provide stime and settimeofday functions if at least one of the syscalls is available
Add hidden stime for possible use in settimeofday. Add stubs for both functions if none of the syscalls is present. Avoid circular dependency. Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'libc/sysdeps/linux/common/settimeofday.c')
-rw-r--r--libc/sysdeps/linux/common/settimeofday.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/libc/sysdeps/linux/common/settimeofday.c b/libc/sysdeps/linux/common/settimeofday.c
index 7e508aea0..e6b396e15 100644
--- a/libc/sysdeps/linux/common/settimeofday.c
+++ b/libc/sysdeps/linux/common/settimeofday.c
@@ -8,12 +8,36 @@
*/
#include <sys/syscall.h>
-#include <sys/time.h>
#ifdef __USE_BSD
+# include <sys/time.h>
+# ifdef __NR_settimeofday
+_syscall2(int, settimeofday, const struct timeval *, tv,
+ const struct timezone *, tz)
+# elif defined __USE_SVID && defined __NR_stime
+# define __need_NULL
+# include <stddef.h>
+# include <errno.h>
+# include <time.h>
+int settimeofday(const struct timeval *tv, const struct timezone *tz)
+{
+ time_t when;
+ if (tv == NULL) {
+ __set_errno(EINVAL);
+ return -1;
+ }
-_syscall2(int, settimeofday, const struct timeval *, tv,
- const struct timezone *, tz)
+ if (tz != NULL || tv->tv_usec % 1000000 != 0) {
+ __set_errno(ENOSYS);
+ return -1;
+ }
+
+ when = tv->tv_sec + (tv->tv_usec / 1000000);
+ return stime(&when);
+}
+# endif
+# if defined __NR_settimeofday || (defined __USE_SVID && defined __NR_stime)
libc_hidden_def(settimeofday)
+# endif
#endif