From eafa875fe957520d62bab97aea8226e0d5bda51b Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Fri, 9 Oct 2015 12:24:20 -0400 Subject: [PATCH] Port: Add compat for dirfd MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- configure.ac | 2 +- converter/babeltrace-log.c | 4 +-- include/Makefile.am | 1 + include/babeltrace/compat/dirent.h | 49 ++++++++++++++++++++++++++++++ tests/lib/test_ctf_writer.c | 4 +-- 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 include/babeltrace/compat/dirent.h diff --git a/configure.ac b/configure.ac index 9757663f..29636c8a 100644 --- a/configure.ac +++ b/configure.ac @@ -81,7 +81,7 @@ AC_TYPE_SIZE_T # 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 diff --git a/converter/babeltrace-log.c b/converter/babeltrace-log.c index b724ccd6..55eabf2d 100644 --- a/converter/babeltrace-log.c +++ b/converter/babeltrace-log.c @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include #include @@ -415,7 +415,7 @@ int main(int argc, char **argv) perror("opendir"); goto error_rmdir; } - dir_fd = dirfd(dir); + dir_fd = bt_dirfd(dir); if (dir_fd < 0) { perror("dirfd"); goto error_closedir; diff --git a/include/Makefile.am b/include/Makefile.am index 513194ef..9884ac2c 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -56,5 +56,6 @@ noinst_HEADERS = \ babeltrace/compat/send.h \ babeltrace/compat/fcntl.h \ babeltrace/compat/stdlib.h \ + babeltrace/compat/dirent.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 index 00000000..5373c667 --- /dev/null +++ b/include/babeltrace/compat/dirent.h @@ -0,0 +1,49 @@ +#ifndef _BABELTRACE_COMPAT_DIRENT_H +#define _BABELTRACE_COMPAT_DIRENT_H + +/* + * babeltrace/compat/dirent.h + * + * Copyright (C) 2015 Michael Jeanson + * + * 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 + +#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 */ diff --git a/tests/lib/test_ctf_writer.c b/tests/lib/test_ctf_writer.c index ce656b31..eb4b1b4d 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -37,7 +37,7 @@ #include #include #include -#include +#include #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) { - unlinkat(dirfd(trace_dir), entry->d_name, 0); + unlinkat(bt_dirfd(trace_dir), entry->d_name, 0); } } -- 2.34.1