#include #include #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; }