X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=include%2Fbabeltrace%2Fcompat%2Ffcntl.h;h=e5232b4cb69c9e446baf9b4fec30140e8e5ff06e;hp=59060ff563ce4714702b6b73784c09735c61d471;hb=ff48c2b023858d7d2daa4a0b0f7e67b9861040c1;hpb=edcad9c1c88e6e698040855d7518d0c27dfc4489 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 */