From: Mathieu Desnoyers Date: Thu, 1 Oct 2015 20:26:20 +0000 (-0400) Subject: Port: Implement faccessat wrapper X-Git-Tag: v1.3.0~19 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=ff48c2b023858d7d2daa4a0b0f7e67b9861040c1 Port: Implement faccessat wrapper Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- diff --git a/configure.ac b/configure.ac index c4faf6e5..971cee55 100644 --- a/configure.ac +++ b/configure.ac @@ -140,11 +140,17 @@ AC_CHECK_LIB([c], [posix_fallocate], ] ) +# Check for faccessat +AC_CHECK_LIB([c], [faccessat], +[ + AC_DEFINE_UNQUOTED([BABELTRACE_HAVE_FACCESSAT], 1, [Has faccessat support.]) +] +) + AC_CHECK_LIB([popt], [poptGetContext], [], [AC_MSG_ERROR([Cannot find popt.])] ) - # For Python # SWIG version needed or newer: swig_version=2.0.0 diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index af1809ef..fb4ef730 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -2010,7 +2010,7 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags, snprintf(index_name, strlen(path) + sizeof(INDEX_PATH), INDEX_PATH, path); - if (faccessat(td->dirfd, index_name, O_RDONLY, flags) < 0) { + if (bt_faccessat(td->dirfd, td->parent.path, index_name, O_RDONLY, 0) < 0) { ret = create_stream_packet_index(td, file_stream); if (ret) { fprintf(stderr, "[error] Stream index creation error.\n"); diff --git a/include/babeltrace/compat/fcntl.h b/include/babeltrace/compat/fcntl.h index 59060ff5..e5232b4c 100644 --- a/include/babeltrace/compat/fcntl.h +++ b/include/babeltrace/compat/fcntl.h @@ -140,4 +140,44 @@ end: } #endif /* #else #ifdef BABELTRACE_HAVE_POSIX_FALLOCATE */ + +#ifdef BABELTRACE_HAVE_FACCESSAT + +#include +#include + +static inline +int bt_faccessat(int dirfd, const char *dirname, + const char *pathname, int mode, int flags) +{ + return faccessat(dirfd, pathname, mode, flags); +} + +#else /* #ifdef BABELTRACE_HAVE_FACCESSAT */ + +#include +#include + +static inline +int bt_faccessat(int dirfd, const char *dirname, + const char *pathname, int mode, int flags) +{ + char cpath[PATH_MAX]; + + if (flags != 0) { + errno = EINVAL; + return -1; + } + /* Includes middle / and final \0. */ + if (strlen(dirname) + strlen(pathname) + 2 > PATH_MAX) { + return -1; + } + strcpy(cpath, dirname); + strcat(cpath, "/"); + strcat(cpath, pathname); + return access(cpath, mode); +} + +#endif /* #else #ifdef BABELTRACE_HAVE_FACCESSAT */ + #endif /* _BABELTRACE_COMPAT_FCNTL_H */