util: add fd_set_close_on_exec()
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
40d821354a
commit
9a7381d02a
|
@ -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
|
||||
|
|
|
@ -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 { \
|
||||
|
|
Loading…
Reference in New Issue