From 0d4e9aac4575744ddaae56b146f1be19f064f0e5 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Thu, 16 Jun 2022 14:55:50 +0300 Subject: [PATCH] silenced a -Wunused-but-set-variable warning. --- src/physfs_platform_posix.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/physfs_platform_posix.c b/src/physfs_platform_posix.c index 24ff594..7ba5e10 100644 --- a/src/physfs_platform_posix.c +++ b/src/physfs_platform_posix.c @@ -155,18 +155,27 @@ int __PHYSFS_platformMkDir(const char *path) } /* __PHYSFS_platformMkDir */ +#if !defined(O_CLOEXEC) && defined(FD_CLOEXEC) +static inline void set_CLOEXEC(int fildes) +{ + int flags = fcntl(fildes, F_GETFD); + if (flags != -1) { + fcntl(fildes, F_SETFD, flags | FD_CLOEXEC); + } +} +#endif + 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; @@ -178,10 +187,7 @@ static void *doOpen(const char *filename, int mode) 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); - } + set_CLOEXEC(fd); #endif if (appending)