Port: Add compat for dirfd
authorMichael Jeanson <mjeanson@efficios.com>
Fri, 9 Oct 2015 16:24:20 +0000 (12:24 -0400)
committerMichael Jeanson <mjeanson@efficios.com>
Fri, 16 Oct 2015 19:40:31 +0000 (15:40 -0400)
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
configure.ac
converter/babeltrace-log.c
include/Makefile.am
include/babeltrace/compat/dirent.h [new file with mode: 0644]
tests/lib/test_ctf_writer.c

index 9757663f47f9aba70edebaf6550535a83928facb..29636c8a9a2308fda195890e9a77011c22681a1c 100644 (file)
@@ -81,7 +81,7 @@ AC_TYPE_SIZE_T
 # Checks for library functions.
 AC_FUNC_MALLOC
 AC_FUNC_MMAP
 # Checks for library functions.
 AC_FUNC_MALLOC
 AC_FUNC_MMAP
-AC_CHECK_FUNCS([gettimeofday munmap strtoul strndup strnlen mkdtemp])
+AC_CHECK_FUNCS([gettimeofday munmap strtoul strndup strnlen mkdtemp dirfd])
 
 # Check for MinGW32.
 MINGW32=no
 
 # Check for MinGW32.
 MINGW32=no
index b724ccd67ebd5aecbb26d671d2e858e2d978b533..55eabf2d1e39015910b4e1c1991627f51205c7ae 100644 (file)
@@ -34,7 +34,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/mman.h>
-#include <dirent.h>
+#include <babeltrace/compat/dirent.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -415,7 +415,7 @@ int main(int argc, char **argv)
                perror("opendir");
                goto error_rmdir;
        }
                perror("opendir");
                goto error_rmdir;
        }
-       dir_fd = dirfd(dir);
+       dir_fd = bt_dirfd(dir);
        if (dir_fd < 0) {
                perror("dirfd");
                goto error_closedir;
        if (dir_fd < 0) {
                perror("dirfd");
                goto error_closedir;
index 513194efa745dc0a1e2db78cbab36979d0fd4a2c..9884ac2cbb5dd376b70b03841daabbdcfb6fecf9 100644 (file)
@@ -56,5 +56,6 @@ noinst_HEADERS = \
        babeltrace/compat/send.h \
        babeltrace/compat/fcntl.h \
        babeltrace/compat/stdlib.h \
        babeltrace/compat/send.h \
        babeltrace/compat/fcntl.h \
        babeltrace/compat/stdlib.h \
+       babeltrace/compat/dirent.h \
        babeltrace/endian.h \
        babeltrace/mmap-align.h
        babeltrace/endian.h \
        babeltrace/mmap-align.h
diff --git a/include/babeltrace/compat/dirent.h b/include/babeltrace/compat/dirent.h
new file mode 100644 (file)
index 0000000..5373c66
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef _BABELTRACE_COMPAT_DIRENT_H
+#define _BABELTRACE_COMPAT_DIRENT_H
+
+/*
+ * babeltrace/compat/dirent.h
+ *
+ * Copyright (C) 2015 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <dirent.h>
+
+#ifdef HAVE_DIRFD
+static inline
+int bt_dirfd(DIR *dir) {
+       return dirfd(dir);
+}
+#else
+# ifndef __XOPEN_OR_POSIX
+static inline
+int bt_dirfd(DIR *dir) {
+       return dir->dd_fd;
+}
+# else
+static inline
+int bt_dirfd(DIR *dir) {
+       return dir->d_fd;
+}
+# endif
+#endif
+
+#endif /* _BABELTRACE_COMPAT_DIRENT_H */
index ce656b318c3320740bebbe0241a73de97750508c..eb4b1b4def548be74949a7124f210425a6cacf45 100644 (file)
@@ -37,7 +37,7 @@
 #include <unistd.h>
 #include <sys/wait.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/wait.h>
 #include <fcntl.h>
-#include <dirent.h>
+#include <babeltrace/compat/dirent.h>
 #include "tap/tap.h"
 
 #define METADATA_LINE_SIZE 512
 #include "tap/tap.h"
 
 #define METADATA_LINE_SIZE 512
@@ -847,7 +847,7 @@ int main(int argc, char **argv)
        struct dirent *entry;
        while ((entry = readdir(trace_dir))) {
                if (entry->d_type == DT_REG) {
        struct dirent *entry;
        while ((entry = readdir(trace_dir))) {
                if (entry->d_type == DT_REG) {
-                       unlinkat(dirfd(trace_dir), entry->d_name, 0);
+                       unlinkat(bt_dirfd(trace_dir), entry->d_name, 0);
                }
        }
 
                }
        }
 
This page took 0.028735 seconds and 4 git commands to generate.