util: add fd_set_close_on_exec()

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-04-02 13:32:35 +02:00
parent 40d821354a
commit 9a7381d02a
2 changed files with 16 additions and 0 deletions

View File

@ -24,6 +24,7 @@
#include <sys/wait.h>
#include <unistd.h>
#include <limits.h>
#include <fcntl.h>
#include "util.h"
#include "tokenize.h"
@ -273,4 +274,18 @@ a_strsplit(const char *str, ssize_t len, char delim)
return retval;
}
/** Mark a file descriptor as close-on-exec.
* \param fd The file descriptor.
* \return The fcntl() return value.
*/
int
fd_set_close_on_exec(int fd)
{
int flags = fcntl(fd, F_GETFD, 0);
/* ignore errors */
if(flags < 0)
return flags;
return fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -339,6 +339,7 @@ void *name_func_lookup(const char *, size_t, const name_func_link_t *);
const char * name_func_rlookup(void *, const name_func_link_t *);
void a_exec(const char *);
char ** a_strsplit(const char *, ssize_t, char);
int fd_set_close_on_exec(int);
#define a_asprintf(strp, fmt, ...) \
do { \