From: Paul Eggert Date: Tue, 30 Mar 2004 23:59:03 +0000 (+0000) Subject: cloexec returns int not bool, to be more consistent with Unix conventions. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8d12f1b53177f6e38e53de9dd48d58a5d41396b;p=pspp cloexec returns int not bool, to be more consistent with Unix conventions. --- diff --git a/lib/ChangeLog b/lib/ChangeLog index 75c4123fbb..863666ceb5 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,9 @@ +2004-03-30 Paul Eggert + + * lib/cloexec.h, lib/cloexec.c (set_cloexec_flag): Return int + not bool, to be more consistent with Unix conventions. + Suggested by Bruno Haible. + 2004-03-30 Bruno Haible * getloadavg.c (getloadavg): Don't assume setlocale returns diff --git a/lib/cloexec.c b/lib/cloexec.c index 20f30db45d..e07cdd3d5d 100644 --- a/lib/cloexec.c +++ b/lib/cloexec.c @@ -37,27 +37,29 @@ /* Set the `FD_CLOEXEC' flag of DESC if VALUE is true, or clear the flag if VALUE is false. - Return true on success, or false on error with `errno' set. */ + Return 0 on success, or -1 on error with `errno' set. */ -bool +int set_cloexec_flag (int desc, bool value) { #if defined F_GETFD && defined F_SETFD int flags = fcntl (desc, F_GETFD, 0); - int newflags; - if (flags < 0) - return false; + if (0 <= flags) + { + int newflags = (value ? flags | FD_CLOEXEC : flags & ~FD_CLOEXEC); - newflags = (value ? flags | FD_CLOEXEC : flags & ~FD_CLOEXEC); + if (flags == newflags + || fcntl (desc, F_SETFD, newflags) != -1) + return 0; + } - return (flags == newflags - || fcntl (desc, F_SETFD, newflags) != -1); + return -1; #else - return true; + return 0; #endif } diff --git a/lib/cloexec.h b/lib/cloexec.h index ecad8d712f..c25921d6b3 100644 --- a/lib/cloexec.h +++ b/lib/cloexec.h @@ -1,2 +1,2 @@ #include -bool set_cloexec_flag (int desc, bool value); +int set_cloexec_flag (int desc, bool value);