blob: 6ff2114a5e752938a9248e04bd8b5b2b5f4fe559 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
diff --git a/src/physfs_platform_posix.c b/src/physfs_platform_posix.c
--- a/src/physfs_platform_posix.c
+++ b/src/physfs_platform_posix.c
@@ -160,16 +160,30 @@ static void *doOpen(const char *filename, int mode)
const int appending = (mode & O_APPEND);
int fd;
int *retval;
+ int flags;
+ flags = -1;
errno = 0;
/* O_APPEND doesn't actually behave as we'd like. */
mode &= ~O_APPEND;
+
+#ifdef O_CLOEXEC
+ /* Add O_CLOEXEC if defined */
+ mode |= O_CLOEXEC;
+#endif
do {
fd = open(filename, mode, S_IRUSR | S_IWUSR);
} while ((fd < 0) && (errno == EINTR));
BAIL_IF(fd < 0, errcodeFromErrno(), NULL);
+#if !defined(O_CLOEXEC) && defined(FD_CLOEXEC)
+ flags = fcntl(fd, F_GETFD);
+ if (flags != -1) {
+ fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
+ }
+#endif
+
if (appending)
{
if (lseek(fd, 0, SEEK_END) < 0)
|