diff options
Diffstat (limited to 'src/xine-utils')
-rw-r--r-- | src/xine-utils/utils.c | 21 | ||||
-rw-r--r-- | src/xine-utils/xineutils.h | 10 |
2 files changed, 27 insertions, 4 deletions
diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c index f5d5a0ff3..25e8cc2b0 100644 --- a/src/xine-utils/utils.c +++ b/src/xine-utils/utils.c @@ -35,7 +35,9 @@ #include <errno.h> #include <pwd.h> +#include <sys/types.h> #include <sys/time.h> +#include <sys/socket.h> #include <time.h> #include <unistd.h> #include <fcntl.h> @@ -714,7 +716,7 @@ static int set_close_on_execute(int fd) } -int open_cloexec(const char *name, int flags) +int xine_open_cloexec(const char *name, int flags) { int fd = open(name, (flags | O_CLOEXEC)); @@ -725,7 +727,7 @@ int open_cloexec(const char *name, int flags) return fd; } -int create_cloexec(const char *name, int flags, mode_t mode) +int xine_create_cloexec(const char *name, int flags, mode_t mode) { int fd = open(name, (flags | O_CREAT | O_CLOEXEC), mode); @@ -736,3 +738,18 @@ int create_cloexec(const char *name, int flags, mode_t mode) return fd; } +int xine_socket_cloexec(int domain, int type, int protocol) +{ + int s = socket(domain, type, protocol); + + if (s >= 0) { +#ifndef WIN32 + fcntl(s, F_SETFD, FD_CLOEXEC); +#else + SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0); +#endif + } + + return s; +} + diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h index 5fe1fb7e5..d0946e471 100644 --- a/src/xine-utils/xineutils.h +++ b/src/xine-utils/xineutils.h @@ -219,13 +219,19 @@ char *xine_strcat_realloc (char **dest, char *append) XINE_PROTECTED; * opens a file, ensuring that the descriptor will be closed * automatically after a fork/execute. */ -int open_cloexec(const char *name, int flags) XINE_PROTECTED; +int xine_open_cloexec(const char *name, int flags) XINE_PROTECTED; /** * creates a file, ensuring that the descriptor will be closed * automatically after a fork/execute. */ -int create_cloexec(const char *name, int flags, mode_t mode) XINE_PROTECTED; +int xine_create_cloexec(const char *name, int flags, mode_t mode) XINE_PROTECTED; + +/** + * creates a socket, ensuring that the descriptor will be closed + * automatically after a fork/execute. + */ +int xine_socket_cloexec(int domain, int type, int protocol) XINE_PROTECTED; /* * Color Conversion Utility Functions |