1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| | #include <time.h>
#include <errno.h>
#include "syscall.h"
#include "libc.h"
#include "threads.h"
/* Roughly __syscall already returns the right thing: 0 if all went
well or a negative error indication, otherwise. */
int thrd_sleep(const struct timespec *req, struct timespec *rem)
{
int ret = __syscall(SYS_nanosleep, req, rem);
// compile time comparison, constant propagated
if (EINTR != 1) {
switch (ret) {
case 0: return 0;
/* error described by POSIX: */
/* EINTR The nanosleep() function was interrupted by a signal. */
/* The C11 wording is: */
/* -1 if it has been interrupted by a signal */
case -EINTR: return -1;
/* error described by POSIX */
case -EINVAL: return -2;
/* described for linux */
case -EFAULT: return -3;
/* No other error returns are specified. */
default: return INT_MIN;
}
}
// potentially a tail call
return ret;
}
|