diff options
Diffstat (limited to 'libc-top-half/musl/src/ipc/semtimedop.c')
-rw-r--r-- | libc-top-half/musl/src/ipc/semtimedop.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/ipc/semtimedop.c b/libc-top-half/musl/src/ipc/semtimedop.c new file mode 100644 index 0000000..1632e7b --- /dev/null +++ b/libc-top-half/musl/src/ipc/semtimedop.c @@ -0,0 +1,35 @@ +#define _GNU_SOURCE +#include <sys/sem.h> +#include <errno.h> +#include "syscall.h" +#include "ipc.h" + +#define IS32BIT(x) !((x)+0x80000000ULL>>32) +#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) + +#if !defined(SYS_semtimedop) && !defined(SYS_ipc) +#define NO_TIME32 1 +#else +#define NO_TIME32 0 +#endif + +int semtimedop(int id, struct sembuf *buf, size_t n, const struct timespec *ts) +{ +#ifdef SYS_semtimedop_time64 + time_t s = ts ? ts->tv_sec : 0; + long ns = ts ? ts->tv_nsec : 0; + int r = -ENOSYS; + if (NO_TIME32 || !IS32BIT(s)) + r = __syscall(SYS_semtimedop_time64, id, buf, n, + ts ? ((long long[]){s, ns}) : 0); + if (NO_TIME32 || r!=-ENOSYS) return __syscall_ret(r); + ts = ts ? (void *)(long[]){CLAMP(s), ns} : 0; +#endif +#if defined(SYS_ipc) + return syscall(SYS_ipc, IPCOP_semtimedop, id, n, 0, buf, ts); +#elif defined(SYS_semtimedop) + return syscall(SYS_semtimedop, id, buf, n, ts); +#else + return __syscall_ret(-ENOSYS); +#endif +} |