[vlc-commits] linux: split out Linux-specific stuff from filesystem.c

Rémi Denis-Courmont git at videolan.org
Mon Feb 12 18:45:51 CET 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Feb 12 19:29:05 2018 +0200| [037cd828565da3c027553046ceb7bc52a705001c] | committer: Rémi Denis-Courmont

linux: split out Linux-specific stuff from filesystem.c

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=037cd828565da3c027553046ceb7bc52a705001c
---

 src/Makefile.am        |  1 +
 src/linux/filesystem.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 src/posix/filesystem.c | 27 ++-------------------------
 3 files changed, 49 insertions(+), 25 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 99509b8a3f..4cadd7c503 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -428,6 +428,7 @@ if HAVE_LINUX
 libvlccore_la_SOURCES += \
 	linux/cpu.c \
 	linux/dirs.c \
+	linux/filesystem.c \
 	linux/thread.c
 endif
 if HAVE_LIBANL
diff --git a/src/linux/filesystem.c b/src/linux/filesystem.c
new file mode 100644
index 0000000000..6634c3d374
--- /dev/null
+++ b/src/linux/filesystem.c
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ * filesystem.c: Linux file system helpers
+ *****************************************************************************
+ * Copyright © 2018 Rémi Denis-Courmont
+ *
+ * Authors: Rémi Denis-Courmont <rem # videolan.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <errno.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#include <vlc_common.h>
+#include <vlc_fs.h>
+
+int vlc_memfd(void)
+{
+#ifdef HAVE_MEMFD_CREATE
+    int fd = memfd_create(PACKAGE_NAME"-memfd",
+                          MFD_CLOEXEC | MFD_ALLOW_SEALING);
+    if (fd != -1 || errno != ENOSYS)
+        return fd;
+#endif
+    return open("/tmp", O_RDWR | O_CLOEXEC | O_TMPFILE, S_IRUSR | S_IWUSR);
+}
diff --git a/src/posix/filesystem.c b/src/posix/filesystem.c
index 0fde2aa40d..6d3e8964c6 100644
--- a/src/posix/filesystem.c
+++ b/src/posix/filesystem.c
@@ -36,16 +36,12 @@
 #include <sys/uio.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <sys/mman.h>
 #include <sys/stat.h>
 #ifndef HAVE_LSTAT
 # define lstat(a, b) stat(a, b)
 #endif
 #include <dirent.h>
 #include <sys/socket.h>
-#ifndef O_TMPFILE
-# define O_TMPFILE 0
-#endif
 
 #include <vlc_common.h>
 #include <vlc_fs.h>
@@ -110,29 +106,10 @@ int vlc_mkstemp (char *template)
 #endif
 }
 
-int vlc_memfd (void)
+VLC_WEAK int vlc_memfd(void)
 {
-    int fd;
-
-#ifdef HAVE_MEMFD_CREATE
-    fd = memfd_create(PACKAGE_NAME"-memfd", MFD_CLOEXEC | MFD_ALLOW_SEALING);
-    if (fd != -1 || errno != ENOSYS)
-        return fd;
-#endif
-
-#ifdef O_TMPFILE
-    fd = vlc_open ("/tmp", O_RDWR|O_TMPFILE, S_IRUSR|S_IWUSR);
-    if (fd != -1)
-        return fd;
-    /* ENOENT means either /tmp is missing (!) or the kernel does not support
-     * O_TMPFILE. EISDIR means /tmp exists but the kernel does not support
-     * O_TMPFILE. EOPNOTSUPP means the kernel supports O_TMPFILE but the /tmp
-     * filesystem does not. Do not fallback on other errors. */
-    if (errno != ENOENT && errno != EISDIR && errno != EOPNOTSUPP)
-        return -1;
-#endif
-
     char bufpath[] = "/tmp/"PACKAGE_NAME"XXXXXX";
+    int fd;
 
     fd = vlc_mkstemp (bufpath);
     if (fd != -1)



More information about the vlc-commits mailing list