sleep.c 360 B

123456789101112131415161718192021222324
  1. #include <sys/time.h>
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4. int usleep (__useconds_t usec)
  5. {
  6. struct timeval tv;
  7. tv.tv_sec = usec / 1000000;
  8. tv.tv_usec = usec % 1000000;
  9. return(select(0, 0, 0, 0, &tv));
  10. }
  11. unsigned int sleep(unsigned int sec)
  12. {
  13. struct timeval tv;
  14. tv.tv_sec = sec;
  15. tv.tv_usec = 0;
  16. select(0, 0, 0, 0, &tv);
  17. return tv.tv_sec;
  18. }