| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 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 | |
| 7 | #include <time.h> |
| 8 | #include <sys/time.h> |
| 9 | #include <sys/types.h> |
| 10 | #include <unistd.h> |
| 11 | |
| 12 | #if defined __USE_BSD || defined __USE_POSIX98 |
| 13 | #if defined __UCLIBC_HAS_REALTIME__ |
| 14 | |
| 15 | int usleep (__useconds_t usec) |
| 16 | { |
| 17 | const struct timespec ts = { |
| 18 | .tv_sec = (long int) (usec / 1000000), |
| 19 | .tv_nsec = (long int) (usec % 1000000) * 1000ul |
| 20 | }; |
| 21 | return nanosleep(&ts, NULL); |
| 22 | } |
| 23 | #else /* __UCLIBC_HAS_REALTIME__ */ |
| 24 | int usleep (__useconds_t usec) |
| 25 | { |
| 26 | struct timeval tv; |
| 27 | |
| 28 | tv.tv_sec = (long int) (usec / 1000000); |
| 29 | tv.tv_usec = (long int) (usec % 1000000); |
| 30 | return select(0, NULL, NULL, NULL, &tv); |
| 31 | } |
| 32 | #endif /* __UCLIBC_HAS_REALTIME__ */ |
| 33 | #endif |