From 41ec922d4512900d13148fc61c9af11996d77ad1 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Tue, 1 Jul 2008 19:40:41 +0000 Subject: [PATCH] As it turns out, glob is also an offender... --- source/libc-opendir-hack.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) 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); + } +} -- 2.47.0