/*
 * svnignore.c (C) 2007 Zevv
 *
 * Shared library to avoid .svn in grep, find, etc. Works by providing wrappers
 * around some library calls for reading directories, and hiding .svn
 * directories. Might interfere with proper subversion functioning !
 *
 * compile: gcc -shared -ldl svnignore.c -o svnignore.so
 *
 * then preload the library: export LD_PRELOAD=/path/to/svnignore.so
 */
 
#define _LARGEFILE64_SOURCE
#define _GNU_SOURCE

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <dlfcn.h>

static struct dirent *(*org_readdir)(DIR *dir);
static struct dirent64 *(*org_readdir64)(DIR *dir);

static void svnignore_init(void) __attribute__((constructor));

static void svnignore_init(void) 
{
	org_readdir = dlsym(RTLD_NEXT, "readdir");
	org_readdir64 = dlsym(RTLD_NEXT, "readdir64");
}

struct dirent *readdir(DIR *dir)
{
	struct dirent *de;

	do {
		de = org_readdir(dir);
	} while(de && strncmp(de->d_name, ".svn", 4) == 0);

	return de;
}
	

struct dirent64 *readdir64(DIR *dir)
{
	struct dirent64 *de;

	do {
		de = org_readdir64(dir);
	} while(de && strncmp(de->d_name, ".svn", 4) == 0);

	return de;
}

/*
 * End
 */


