# HG changeset patch # User Heiko Schlittermann # Date 1293062764 -3600 # Node ID 9ccc1574a367a0af0375f586d47753dc9a2ee80b # Parent 7d3c07f8acfb71327352a1be4ba85869ecc7d273 more instructive output - changed the selector (skipper) criterion for readdir - using the libc.so.6 as "default" library if no soname is passed to lib_function diff -r 7d3c07f8acfb -r 9ccc1574a367 README --- a/README Thu Dec 23 00:46:07 2010 +0100 +++ b/README Thu Dec 23 01:06:04 2010 +0100 @@ -10,12 +10,12 @@ the "hallo" should use the modified versions of the above funtions too. -The modification is visibable, as puts(3) prints an -extra string before the real output, and readdir(3) skips -any directory entry starting with 'M'. +The modification is visable, as puts(3) prints an XML-like marker around +the real output, and readdir(3) skips any directory entry containing a +dot. -No considerations done about race conditions and other nice things. -It is just an nice example… +No considerations are done about race conditions and other nice things. +It is just an example… -- Heiko Schlittermann diff -r 7d3c07f8acfb -r 9ccc1574a367 dl.c --- a/dl.c Thu Dec 23 00:46:07 2010 +0100 +++ b/dl.c Thu Dec 23 01:06:04 2010 +0100 @@ -3,18 +3,22 @@ #include #include "dl.h" -void *get_original_function(const char *soname, const char *name) +#define DEFAULT_LIB "libc.so.6" + +void *lib_function(const char *name, const char *soname) { + void *rc; const char* error; - void *handle = dlopen(soname, RTLD_LAZY); - void *rc; + void *handle; + - if (!handle) { + + if (!(handle = dlopen(soname ? soname : DEFAULT_LIB, RTLD_LAZY))) { fprintf(stderr, "dlopen on %s: %s\n", soname, dlerror()); exit(1); } - dlerror(); + dlerror(); /* clear the error flag */ rc = dlsym(handle, name); if ((error = dlerror())) { fprintf(stderr, "dlsym for %s: %s\n", name, error); diff -r 7d3c07f8acfb -r 9ccc1574a367 dl.h --- a/dl.h Thu Dec 23 00:46:07 2010 +0100 +++ b/dl.h Thu Dec 23 01:06:04 2010 +0100 @@ -1,4 +1,4 @@ #ifndef _DL_H_ #define _DL_H_ -void *get_original_function(const char *soname, const char *name); +void *lib_function(const char* name, const char *soname); #endif diff -r 7d3c07f8acfb -r 9ccc1574a367 puts.c --- a/puts.c Thu Dec 23 00:46:07 2010 +0100 +++ b/puts.c Thu Dec 23 01:06:04 2010 +0100 @@ -1,3 +1,4 @@ +#include #include "dl.h" /* shameless stolen from @@ -12,7 +13,7 @@ int rc; if (!orig) - orig = get_original_function("libc.so.6", "puts"); + orig = lib_function("puts", NULL); (*orig)(""); rc = (*orig)(s); diff -r 7d3c07f8acfb -r 9ccc1574a367 readdir.c --- a/readdir.c Thu Dec 23 00:46:07 2010 +0100 +++ b/readdir.c Thu Dec 23 01:06:04 2010 +0100 @@ -1,3 +1,5 @@ +#include +#include #include #include "dl.h" @@ -14,13 +16,14 @@ struct dirent *dent; if (!orig) - orig = get_original_function("libc.so.6", "readdir64"); + orig = lib_function("readdir64", NULL); dent = (*orig)(dirp); /* skip selected entries */ - if (dent && dent->d_name[0] == 'M') + while (dent && strchr(dent->d_name, '.')) { dent = (*orig)(dirp); + } return dent; }