vfs: check userland buffers before reading them.
[haiku.git] / src / system / libroot / posix / signal / sigtimedwait.cpp
blob7e1878748f18e62debf5046e57bc923f2ac7086d
1 /*
2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <signal.h>
9 #include <errno.h>
10 #include <pthread.h>
12 #include <syscall_utils.h>
14 #include <errno_private.h>
15 #include <syscalls.h>
18 int
19 sigtimedwait(const sigset_t* set, siginfo_t* info,
20 const struct timespec* timeout)
22 // make info non-NULL to simplify things
23 siginfo_t stackInfo;
24 if (info == NULL)
25 info = &stackInfo;
27 // translate the timeout
28 uint32 flags;
29 bigtime_t timeoutMicros;
30 if (timeout != NULL) {
31 timeoutMicros = system_time();
32 flags = B_ABSOLUTE_TIMEOUT;
33 timeoutMicros += (bigtime_t)timeout->tv_sec * 1000000
34 + timeout->tv_nsec / 1000;
35 } else {
36 flags = 0;
37 timeoutMicros = 0;
40 status_t error = _kern_sigwait(set, info, flags, timeoutMicros);
42 pthread_testcancel();
44 if (error != B_OK)
45 RETURN_AND_SET_ERRNO(error);
47 return info->si_signo;