diff options
author | Darren Salt <linux@youmustbejoking.demon.co.uk> | 2011-10-04 23:41:41 +0100 |
---|---|---|
committer | Darren Salt <linux@youmustbejoking.demon.co.uk> | 2011-10-04 23:41:41 +0100 |
commit | 5be586e3025e72c1a1cef2a3ada6238486f7ed43 (patch) | |
tree | 2a5da19b632e9296e622e47c161062caec0b9b89 /src/xine-utils/utils.c | |
parent | d7c4d2bd622b1405ff520006dbeaf739e9725a89 (diff) | |
parent | 7e335173083e1fc91f27927a2d749f5a09773b32 (diff) | |
download | xine-lib-5be586e3025e72c1a1cef2a3ada6238486f7ed43.tar.gz xine-lib-5be586e3025e72c1a1cef2a3ada6238486f7ed43.tar.bz2 |
Merge from 1.1.
--HG--
rename : src/xine-utils/attributes.h => include/xine/attributes.h
rename : src/xine-engine/xine_internal.h => include/xine/xine_internal.h
rename : src/xine-utils/xineutils.h => include/xine/xineutils.h
Diffstat (limited to 'src/xine-utils/utils.c')
-rw-r--r-- | src/xine-utils/utils.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c index 75caaf09f..27c52c70d 100644 --- a/src/xine-utils/utils.c +++ b/src/xine-utils/utils.c @@ -35,9 +35,12 @@ #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> #if HAVE_EXECINFO_H #include <execinfo.h> @@ -56,6 +59,10 @@ #include <windows.h> #endif +#ifndef O_CLOEXEC +# define O_CLOEXEC 0 +#endif + typedef struct { const char language[16]; /* name of the locale */ const char encoding[16]; /* typical encoding */ @@ -717,3 +724,57 @@ char *xine_strcat_realloc (char **dest, char *append) strcat (*dest = newstr, append); return newstr; } + + +int _x_set_file_close_on_exec(int fd) +{ +#ifndef WIN32 + return fcntl(fd, F_SETFD, FD_CLOEXEC); +#else + return SetHandleInformation((HANDLE)_get_osfhandle(fd), HANDLE_FLAG_INHERIT, 0); +#endif +} + +int _x_set_socket_close_on_exec(int s) +{ +#ifndef WIN32 + return fcntl(s, F_SETFD, FD_CLOEXEC); +#else + return SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0); +#endif +} + + +int xine_open_cloexec(const char *name, int flags) +{ + int fd = open(name, (flags | O_CLOEXEC)); + + if (fd >= 0) { + _x_set_file_close_on_exec(fd); + } + + return fd; +} + +int xine_create_cloexec(const char *name, int flags, mode_t mode) +{ + int fd = open(name, (flags | O_CREAT | O_CLOEXEC), mode); + + if (fd >= 0) { + _x_set_file_close_on_exec(fd); + } + + return fd; +} + +int xine_socket_cloexec(int domain, int type, int protocol) +{ + int s = socket(domain, type, protocol); + + if (s >= 0) { + _x_set_socket_close_on_exec(s); + } + + return s; +} + |