readdir.c
changeset 0 7d3c07f8acfb
child 1 9ccc1574a367
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/readdir.c	Thu Dec 23 00:46:07 2010 +0100
@@ -0,0 +1,26 @@
+#include <dirent.h>
+#include "dl.h"
+
+/* shameless stolen from
+ * http://uberhip.com/people/godber/interception/html/slide_6.html
+ * and of course from the manpage of dlopen(3)
+ */
+
+
+struct dirent* readdir(DIR *dirp)
+{
+
+    static struct dirent* (*orig)(DIR *);
+    struct dirent *dent;
+
+    if (!orig) 
+	orig = get_original_function("libc.so.6", "readdir64");
+
+    dent = (*orig)(dirp);
+
+    /* skip selected entries */
+    if (dent && dent->d_name[0] == 'M') 
+	dent = (*orig)(dirp);
+
+    return dent;
+}