usleep.c 729 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <time.h>
  7. #include <sys/time.h>
  8. #include <sys/types.h>
  9. #include <unistd.h>
  10. #if defined __USE_BSD || defined __USE_POSIX98
  11. #if defined __UCLIBC_HAS_REALTIME__
  12. int usleep (__useconds_t usec)
  13. {
  14. const struct timespec ts = {
  15. .tv_sec = (long int) (usec / 1000000),
  16. .tv_nsec = (long int) (usec % 1000000) * 1000ul
  17. };
  18. return(nanosleep(&ts, NULL));
  19. }
  20. #else /* __UCLIBC_HAS_REALTIME__ */
  21. int usleep (__useconds_t usec)
  22. {
  23. struct timeval tv;
  24. tv.tv_sec = 0;
  25. tv.tv_usec = usec;
  26. return select(0, NULL, NULL, NULL, &tv);
  27. }
  28. #endif /* __UCLIBC_HAS_REALTIME__ */
  29. #endif