Add support for using time64 on big-endian machines.
[uclibc-ng.git] / libc / sysdeps / linux / common / clock_settime.c
blob3abc5f49bcd9c4dc830b77fb4e31d445dbd52b1d
1 /*
2 * clock_settime() for uClibc
4 * Copyright (C) 2005 by Peter Kjellerstedt <pkj@axis.com>
5 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
7 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
8 */
10 #include <sys/syscall.h>
11 #include <time.h>
14 #if defined(__UCLIBC_USE_TIME64__) && defined(__NR_clock_settime64)
15 #include "internal/time64_helpers.h"
17 int clock_settime(clockid_t clock_id, const struct timespec *tp)
19 return INLINE_SYSCALL(clock_settime64, 2, clock_id, TO_TS64_P(tp));
21 #elif defined(__NR_clock_settime)
22 _syscall2(int, clock_settime, clockid_t, clock_id, const struct timespec*, tp)
23 #else
24 # include <sys/time.h>
26 int clock_settime(clockid_t clock_id, const struct timespec* tp)
28 struct timeval tv;
29 int retval = -1;
31 if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000) {
32 errno = EINVAL;
33 return -1;
36 switch (clock_id) {
37 case CLOCK_REALTIME:
38 TIMESPEC_TO_TIMEVAL(&tv, tp);
39 retval = settimeofday(&tv, NULL);
40 break;
42 default:
43 errno = EINVAL;
44 break;
47 return retval;
49 #endif