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

usleep.c « linux « sys « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fab6911f2576b8b08eaee0316b2874d2d512bcd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* libc/sys/linux/usleep.c - usleep function */

/* Written 2002 by Jeff Johnston */


#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include <linux/times.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;
}