From 8b6e94997aafef8af615bc11ebb51c54b18700f0 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 ed4b38b2..1ddfec06 100644 --- a/configure.ac +++ b/configure.ac @@ -95,7 +95,7 @@ AC_CHECK_FUNCS([ \ gettimeofday munmap strtoul ftruncate gethostbyname \ localtime_r memset mkdir rmdir setenv socket \ strchr strdup strerror strndup strrchr strtoull tzset \ - strnlen mkdtemp \ + strnlen mkdtemp dirfd \ ]) # Check for MinGW32. 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 981ad91e..a011b384 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -75,5 +75,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 a5b22d23..6617412c 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include "tap/tap.h" #include #include @@ -3299,7 +3299,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