7 /* set/clear close-on-exec flag
9 /* #include <iostuff.h>
11 /* int close_on_exec(int fd, int on)
13 /* the \fIclose_on_exec\fR() function manipulates the close-on-exec
14 /* flag for the specified open file, and returns the old setting.
20 /* Use CLOSE_ON_EXEC or PASS_ON_EXEC.
22 /* All errors are fatal.
26 /* The Secure Mailer license must be distributed with this software.
29 /* IBM T.J. Watson Research
31 /* Yorktown Heights, NY 10598, USA
34 /* System interfaces. */
39 /* Utility library. */
43 /* Application-specific. */
47 #define PATTERN FD_CLOEXEC
49 /* close_on_exec - set/clear close-on-exec flag */
51 int close_on_exec(fd
, on
)
57 if ((flags
= fcntl(fd
, F_GETFD
, 0)) < 0)
58 msg_fatal("fcntl: get flags: %m");
59 if (fcntl(fd
, F_SETFD
, on
? flags
| PATTERN
: flags
& ~PATTERN
) < 0)
60 msg_fatal("fcntl: set close-on-exec flag %s: %m", on
? "on" : "off");
61 return ((flags
& PATTERN
) != 0);