summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/gettimeofday.c
blob: 9b29fe5a098efd0f071b9b027e6ee836b770f956 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * gettimeofday() for uClibc
 *
 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
 *
 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
 */

#include <sys/syscall.h>
#include <sys/time.h>
#include <time.h>

#ifdef __VDSO_SUPPORT__
#include "ldso.h"
#endif

int gettimeofday(struct timeval * tv, __timezone_ptr_t tz) {
    if (!tv)
        return 0;
#if defined(__VDSO_SUPPORT__) && defined(ARCH_VDSO_GETTIMEOFDAY)
    return ARCH_VDSO_GETTIMEOFDAY(tv, tz);
#else
    struct timespec __ts;
    int __ret = clock_gettime(CLOCK_REALTIME, &__ts);
    tv->tv_sec = __ts.tv_sec;
    tv->tv_usec = (suseconds_t)__ts.tv_nsec / 1000;
    return __ret;
#endif
}


libc_hidden_def(gettimeofday)