From: Daniel Hokka Zakrisson Date: Tue, 1 Jul 2008 19:40:41 +0000 (+0000) Subject: As it turns out, glob is also an offender... X-Git-Tag: BootManager-3.2-10~4 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=41ec922d4512900d13148fc61c9af11996d77ad1;p=bootmanager.git As it turns out, glob is also an offender... --- diff --git a/source/libc-opendir-hack.c b/source/libc-opendir-hack.c index 95786ef..ea735fa 100644 --- a/source/libc-opendir-hack.c +++ b/source/libc-opendir-hack.c @@ -1,11 +1,16 @@ #define _GNU_SOURCE 1 #include +#include +#include #include #include #include +#include -#define NAME "O_CLOEXEC-vs-O_ATOMICLOOKUP" +static int (*real_glob)(const char *pattern, int flags, + int (*errfunc) (const char *epath, int eerrno), + glob_t *pglob); DIR *opendir(const char *name) { @@ -14,3 +19,33 @@ DIR *opendir(const char *name) return NULL; return fdopendir(fd); } + +DIR *__opendir(const char *name) +{ + return opendir(name); +} + +int glob(const char *pattern, int flags, + int (*errfunc) (const char *epath, int eerrno), + glob_t *pglob) +{ + if (!(flags & GLOB_ALTDIRFUNC)) { + pglob->gl_closedir = closedir; + pglob->gl_readdir = readdir; + pglob->gl_opendir = opendir; + pglob->gl_lstat = lstat; + pglob->gl_stat = stat; + flags |= GLOB_ALTDIRFUNC; + } + return real_glob(pattern, flags, errfunc, pglob); +} + +static void _init() __attribute__((constructor)); +static void _init() +{ + real_glob = dlsym(RTLD_NEXT, "glob"); + if (!real_glob) { + fprintf(stderr, "Would the real glob please stand up? %s\n", dlerror()); + exit(1); + } +}