Lely core libraries  2.3.4
sleep.c
Go to the documentation of this file.
1 
23 #include "libc.h"
24 
25 #include <lely/libc/time.h>
26 #include <lely/libc/unistd.h>
27 
28 #if !LELY_NO_RT
29 
30 #if _WIN32 && !defined(__MINGW32__)
31 
32 #include <errno.h>
33 
34 int
35 nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
36 {
37  int errsv = clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rmtp);
38  if (errsv) {
39  errno = errsv;
40  return -1;
41  }
42  return 0;
43 }
44 
45 unsigned
46 sleep(unsigned seconds)
47 {
48  struct timespec rqtp = { seconds, 0 };
49  struct timespec rmtp = { 0, 0 };
50  int errsv = errno;
51  if (nanosleep(&rqtp, &rmtp) == -1) {
52  errno = errsv;
53  return (unsigned)rmtp.tv_sec;
54  }
55 
56  return 0;
57 }
58 
59 #endif // _WIN32 && !__MINGW32__
60 
61 #endif // !LELY_NO_RT
time.h
libc.h
unistd.h