diff options
-rw-r--r-- | lib/intercept/intercept.cpp | 31 | ||||
-rw-r--r-- | lib/intercept/intercept.h | 17 |
2 files changed, 39 insertions, 9 deletions
diff --git a/lib/intercept/intercept.cpp b/lib/intercept/intercept.cpp index 4208ce97..9a15971a 100644 --- a/lib/intercept/intercept.cpp +++ b/lib/intercept/intercept.cpp @@ -22,6 +22,7 @@ #endif #include <errno.h> +#include <stdarg.h> #ifdef HAVE_DLFCN_H #include <dlfcn.h> @@ -232,7 +233,11 @@ int intercept_reterr() } extern "C" int -open(const char *path, int flags, mode_t mode) +#ifdef DEFINE_ONLY_OPEN64 + open64(const char *path, int flags, ...) +#else + open(const char *path, int flags, ...) +#endif // DEFINE_ONLY_OPEN64 { if(intercept_count > 0) { @@ -245,6 +250,15 @@ open(const char *path, int flags, mode_t mode) } } + mode_t mode = 0; + if (flags & O_CREAT) + { + va_list ap; + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + } + #ifdef PLATFORM_NO_SYSCALL int r = TEST_open(path, flags, mode); #else @@ -266,14 +280,27 @@ open(const char *path, int flags, mode_t mode) return r; } +#ifndef DEFINE_ONLY_OPEN64 extern "C" int -open64(const char *path, int flags, mode_t mode) +// open64(const char *path, int flags, mode_t mode) +// open64(const char *path, int flags, ...) +open64 (__const char *path, int flags, ...) { + mode_t mode = 0; + if (flags & O_CREAT) + { + va_list ap; + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + } + // With _FILE_OFFSET_BITS set to 64 this should really use (flags | // O_LARGEFILE) here, but not actually necessary for the tests and not // worth the trouble finding O_LARGEFILE return open(path, flags, mode); } +#endif // !DEFINE_ONLY_OPEN64 extern "C" int close(int d) diff --git a/lib/intercept/intercept.h b/lib/intercept/intercept.h index 4722179d..66e8684b 100644 --- a/lib/intercept/intercept.h +++ b/lib/intercept/intercept.h @@ -23,14 +23,17 @@ extern "C" typedef struct dirent *(readdir_t) (DIR *dir); typedef int (closedir_t)(DIR *dir); #if defined __GNUC__ && __GNUC__ >= 2 -#define LINUX_WEIRD_LSTAT -#define STAT_STRUCT struct stat /* should be stat64 */ - typedef int (lstat_t) (int ver, const char *file_name, - STAT_STRUCT *buf); + #if _FILE_OFFSET_BITS == 64 + #define DEFINE_ONLY_OPEN64 + #endif + #define LINUX_WEIRD_LSTAT + #define STAT_STRUCT struct stat /* should be stat64 */ + typedef int (lstat_t) (int ver, const char *file_name, + STAT_STRUCT *buf); #else -#define STAT_STRUCT struct stat - typedef int (lstat_t) (const char *file_name, - STAT_STRUCT *buf); + #define STAT_STRUCT struct stat + typedef int (lstat_t) (const char *file_name, + STAT_STRUCT *buf); #endif } |