summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2019-07-27 17:48:32 -0400
committerRich Felker <dalias@aerifal.cx>2019-07-27 17:48:32 -0400
commit2c2c3605d3b3ff32902c406d17ac44e7544be4e2 (patch)
treeb1c46673ab96ca3a5b1b8bff042dfa0e24ddffba /src
parent4bbd7baea7c8538b3fb8e30f7b022a1eee071450 (diff)
downloadmusl-2c2c3605d3b3ff32902c406d17ac44e7544be4e2.tar.gz
implement settimeofday in terms of clock_settime, not old syscall
this is yet another place where special handling of time syscalls can and should be avoided by implementing legacy functions in terms of their modern replacements. in theory a fallback to SYS_settimeofday could be added to clock_settime, but SYS_clock_settime has been available since Linux 2.6.0 or earlier, i.e. all the way back to the minimum supported version.
Diffstat (limited to 'src')
-rw-r--r--src/linux/settimeofday.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/linux/settimeofday.c b/src/linux/settimeofday.c
index 15c18c63..860fb5de 100644
--- a/src/linux/settimeofday.c
+++ b/src/linux/settimeofday.c
@@ -1,8 +1,13 @@
#define _BSD_SOURCE
#include <sys/time.h>
+#include <time.h>
+#include <errno.h>
#include "syscall.h"
int settimeofday(const struct timeval *tv, const struct timezone *tz)
{
- return syscall(SYS_settimeofday, tv, 0);
+ if (!tv) return 0;
+ if (tv->tv_usec >= 1000000ULL) return __syscall_ret(-EINVAL);
+ return clock_settime(CLOCK_REALTIME, &((struct timespec){
+ .tv_sec = tv->tv_sec, .tv_nsec = tv->tv_usec * 1000}));
}