浏览代码

silenced a -Wunused-but-set-variable warning.

Ozkan Sezer 3 年之前
父节点
当前提交
0d4e9aac45
共有 1 个文件被更改,包括 13 次插入7 次删除
  1. 13 7
      src/physfs_platform_posix.c

+ 13 - 7
src/physfs_platform_posix.c

@@ -155,18 +155,27 @@ int __PHYSFS_platformMkDir(const char *path)
 } /* __PHYSFS_platformMkDir */
 } /* __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)
 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
 #ifdef O_CLOEXEC
     /* Add O_CLOEXEC if defined */
     /* Add O_CLOEXEC if defined */
     mode |= O_CLOEXEC;
     mode |= O_CLOEXEC;
@@ -178,10 +187,7 @@ static void *doOpen(const char *filename, int mode)
     BAIL_IF(fd < 0, errcodeFromErrno(), NULL);
     BAIL_IF(fd < 0, errcodeFromErrno(), NULL);
 
 
 #if !defined(O_CLOEXEC) && defined(FD_CLOEXEC)
 #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
 #endif
 
 
     if (appending)
     if (appending)