From 2e0521804d26f0804f86fbba9d06884b82720cc8 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Wed, 3 Jun 2015 12:34:37 -0700 Subject: [PATCH] tests: Use readdir64 when _FILE_OFFSET_BITS set On 32 bit systems, _FILE_OFFSET_BITS will be set to 64 by AC_SYS_LARGEFILE. This causes the glibc headers to use readdir64 rather than readdir. Emulate that behavior in the preloader or the tests will all fail with "No such file or directory". --- tests/readdir-rand.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/readdir-rand.c b/tests/readdir-rand.c index bf37b111..527d4a3a 100644 --- a/tests/readdir-rand.c +++ b/tests/readdir-rand.c @@ -30,6 +30,17 @@ #include #include +/* Glibc uses readdir64 when _FILE_OFFSET_BITS == 64 as set by + * AC_SYS_LARGEFILE on 32 bit systems. + */ +#if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64) +# define READDIR "readdir64" +# define READDIR_R "readdir64_r" +#else +# define READDIR "readdir" +# define READDIR_R "readdir_r" +#endif + static GHashTable *direntcache; static GMutex direntcache_lock; static gsize initialized; @@ -69,7 +80,7 @@ ensure_initialized (void) struct dirent * readdir (DIR *dirp) { - struct dirent *(*real_readdir)(DIR *dirp) = dlsym (RTLD_NEXT, "readdir"); + struct dirent *(*real_readdir)(DIR *dirp) = dlsym (RTLD_NEXT, READDIR); struct dirent *ret; gboolean cache_another = TRUE; @@ -186,7 +197,7 @@ rewinddir (DIR *dirp) int readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result) { - int (*real_readdir_r)(DIR *dirp, struct dirent *entry, struct dirent **result) = dlsym (RTLD_NEXT, "readdir_r"); + int (*real_readdir_r)(DIR *dirp, struct dirent *entry, struct dirent **result) = dlsym (RTLD_NEXT, READDIR_R); ensure_initialized ();