aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc/posix/usleep.c
blob: cc1b3140860b64fe611ff86e138b32ac350c18d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* libc/posix/usleep.c - usleep function */

/* Written 2002 by Jeff Johnston */

#ifdef HAVE_NANOSLEEP

#include <errno.h>
#include <time.h>
#include <unistd.h>

int usleep(useconds_t useconds)
{
    struct timespec ts;

    ts.tv_sec = (long int)useconds / 1000000;
    ts.tv_nsec = ((long int)useconds % 1000000) * 1000;
    if (!nanosleep(&ts,&ts)) return 0;
    return -1;
}

#endif