File indexing completed on 2026-05-03 08:14:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___SUPPORT_IBM_NANOSLEEP_H
0011 #define _LIBCPP___SUPPORT_IBM_NANOSLEEP_H
0012
0013 #include <unistd.h>
0014
0015 inline int nanosleep(const struct timespec* __req, struct timespec* __rem) {
0016
0017
0018
0019
0020 if (__req->tv_sec < 0 || __req->tv_nsec < 0 || __req->tv_nsec > 999999999) {
0021 errno = EINVAL;
0022 return -1;
0023 }
0024 long __micro_sec = (__req->tv_nsec + 999) / 1000;
0025 time_t __sec = __req->tv_sec;
0026 if (__micro_sec > 999999) {
0027 ++__sec;
0028 __micro_sec -= 1000000;
0029 }
0030 __sec = static_cast<time_t>(sleep(static_cast<unsigned int>(__sec)));
0031 if (__sec) {
0032 if (__rem) {
0033
0034 __rem->tv_sec = __sec;
0035 __rem->tv_nsec = __micro_sec * 1000;
0036 }
0037 errno = EINTR;
0038 return -1;
0039 }
0040 if (__micro_sec) {
0041 int __rt = usleep(static_cast<unsigned int>(__micro_sec));
0042 if (__rt != 0 && __rem) {
0043
0044
0045 __rem->tv_sec = 0;
0046 __rem->tv_nsec = __micro_sec * 1000;
0047
0048 return -1;
0049 }
0050 return __rt;
0051 }
0052 return 0;
0053 }
0054
0055 #endif