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
34int
35nanosleep(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
45unsigned
46sleep(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
This header file is part of the C11 and POSIX compatibility library; it includes <time....
This is the internal header file of the C11 and POSIX compatibility library.
A time type with nanosecond resolution.
Definition time.h:88
time_t tv_sec
Whole seconds (>= 0).
Definition time.h:90
This header file is part of the C11 and POSIX compatibility library; it includes <unistd....
unsigned sleep(unsigned seconds)
Sleeps until the specified number of realtime seconds has elapsed or the calling thread is interrupte...