From d9769e2219715b10cd64cd94cfc67aff2381c572 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 10 Oct 2007 14:13:34 +0000 Subject: [PATCH] Patch by Vasilis Kaoutsis: select() and pselect() set errno correctly now. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22499 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/libroot/posix/sys/select.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/system/libroot/posix/sys/select.c b/src/system/libroot/posix/sys/select.c index fa293b9967..410cc54eab 100644 --- a/src/system/libroot/posix/sys/select.c +++ b/src/system/libroot/posix/sys/select.c @@ -1,22 +1,34 @@ /* -** Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2002-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the OpenBeOS License. + */ +#include #include #include +#define RETURN_AND_SET_ERRNO(err) \ + if (err < 0) { \ + errno = err; \ + return -1; \ + } \ + return err; + + int pselect(int numBits, struct fd_set *readBits, struct fd_set *writeBits, struct fd_set *errorBits, const struct timespec *tv, const sigset_t *sigMask) { + int status; bigtime_t timeout = -1LL; if (tv) timeout = tv->tv_sec * 1000000LL + tv->tv_nsec / 1000LL; - return _kern_select(numBits, readBits, writeBits, errorBits, timeout, sigMask); + status = _kern_select(numBits, readBits, writeBits, errorBits, timeout, sigMask); + + RETURN_AND_SET_ERRNO(status); } @@ -24,10 +36,12 @@ int select(int numBits, struct fd_set *readBits, struct fd_set *writeBits, struct fd_set *errorBits, struct timeval *tv) { + int status; bigtime_t timeout = -1LL; if (tv) timeout = tv->tv_sec * 1000000LL + tv->tv_usec; - return _kern_select(numBits, readBits, writeBits, errorBits, timeout, NULL); -} + status = _kern_select(numBits, readBits, writeBits, errorBits, timeout, NULL); + RETURN_AND_SET_ERRNO(status); +}