changeset 4982:87f0b7b6d498

cloexec returns int not bool, to be more consistent with Unix conventions.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 30 Mar 2004 23:59:03 +0000
parents 9b063b4d1dae
children 1ade121b7fb9
files lib/ChangeLog lib/cloexec.c lib/cloexec.h
diffstat 3 files changed, 18 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,9 @@
+2004-03-30  Paul Eggert  <eggert@twinsun.com>
+
+	* 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  <bruno@clisp.org>
 
 	* getloadavg.c (getloadavg): Don't assume setlocale returns
--- 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
 }
--- a/lib/cloexec.h
+++ b/lib/cloexec.h
@@ -1,2 +1,2 @@
 #include <stdbool.h>
-bool set_cloexec_flag (int desc, bool value);
+int set_cloexec_flag (int desc, bool value);