1 /* Copied from libc/posix/usleep.c, removed the check for HAVE_NANOSLEEP */ 2 3 /* Copyright (c) 2002 by Jeff Johnston */ 4 5 #include <errno.h> 6 #include <time.h> 7 #include <unistd.h> 8 usleep(useconds_t useconds)9int usleep(useconds_t useconds) 10 { 11 struct timespec ts; 12 13 ts.tv_sec = (long int)useconds / 1000000; 14 ts.tv_nsec = ((long int)useconds % 1000000) * 1000; 15 if (!nanosleep(&ts,&ts)) return 0; 16 if (errno == EINTR) return ts.tv_sec; 17 return -1; 18 } 19