Port: Implement faccessat wrapper
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 1 Oct 2015 20:26:20 +0000 (16:26 -0400)
committerMichael Jeanson <mjeanson@efficios.com>
Fri, 16 Oct 2015 19:40:30 +0000 (15:40 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
configure.ac
formats/ctf/ctf.c
include/babeltrace/compat/fcntl.h

index c4faf6e58d6fbe4040f4d00a80c174f2ab752182..971cee55299827d25a72942dd4d2c36a03c1b2ea 100644 (file)
@@ -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
index af1809efc8a0390986027bded924e6d2b3bb932e..fb4ef730d7619c780c7797221ce625c755b08bd6 100644 (file)
@@ -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");
index 59060ff563ce4714702b6b73784c09735c61d471..e5232b4cb69c9e446baf9b4fec30140e8e5ff06e 100644 (file)
@@ -140,4 +140,44 @@ end:
 }
 #endif /* #else #ifdef BABELTRACE_HAVE_POSIX_FALLOCATE */
 
+
+#ifdef BABELTRACE_HAVE_FACCESSAT
+
+#include <fcntl.h>
+#include <unistd.h>
+
+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 <string.h>
+#include <unistd.h>
+
+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 */
This page took 0.027374 seconds and 4 git commands to generate.