physfs_platform_posix.c: Use O_CLOEXEC / FD_CLOEXEC
This commit is contained in:
parent
a9cb20772b
commit
b8fa8fdcac
|
@ -160,16 +160,30 @@ static void *doOpen(const char *filename, int mode)
|
||||||
const int appending = (mode & O_APPEND);
|
const int appending = (mode & O_APPEND);
|
||||||
int fd;
|
int fd;
|
||||||
int *retval;
|
int *retval;
|
||||||
|
int flags;
|
||||||
|
flags = -1;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
/* O_APPEND doesn't actually behave as we'd like. */
|
/* O_APPEND doesn't actually behave as we'd like. */
|
||||||
mode &= ~O_APPEND;
|
mode &= ~O_APPEND;
|
||||||
|
|
||||||
|
#ifdef O_CLOEXEC
|
||||||
|
/* Add O_CLOEXEC if defined */
|
||||||
|
mode |= O_CLOEXEC;
|
||||||
|
#endif
|
||||||
|
|
||||||
do {
|
do {
|
||||||
fd = open(filename, mode, S_IRUSR | S_IWUSR);
|
fd = open(filename, mode, S_IRUSR | S_IWUSR);
|
||||||
} while ((fd < 0) && (errno == EINTR));
|
} while ((fd < 0) && (errno == EINTR));
|
||||||
BAIL_IF(fd < 0, errcodeFromErrno(), NULL);
|
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 (appending)
|
||||||
{
|
{
|
||||||
if (lseek(fd, 0, SEEK_END) < 0)
|
if (lseek(fd, 0, SEEK_END) < 0)
|
||||||
|
|
Loading…
Reference in New Issue