1 /* libc/sys/linux/usleep.c - usleep function */ 2 3 /* Written 2002 by Jeff Johnston */ 4 5 6 #include <errno.h> 7 #include <sys/types.h> 8 #include <sys/time.h> 9 #include <linux/times.h> 10 usleep(__useconds_t useconds)11int usleep(__useconds_t useconds) 12 { 13 struct timespec ts; 14 15 ts.tv_sec = (long int)useconds / 1000000; 16 ts.tv_nsec = ((long int)useconds % 1000000) * 1000; 17 if (!nanosleep(&ts,&ts)) return 0; 18 if (errno == EINTR) return ts.tv_sec; 19 return -1; 20 } 21