Welcome to mirror list, hosted at ThFree Co, Russian Federation.

usleep.c « posix « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9322b6551efdbe216ad9c1f9a2acce831bf26578 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* 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;
    if (errno == EINTR) return ts.tv_sec;
    return -1;
}

#endif