/* * ISA 563, Spring 2011 * Copyleft by Muhammad Abdulla */ #include #define __USE_GNU #include /* * ifile.c -- demonstrates interposition of file operations */ FILE *fopen(const char *path, const char *mode) { static FILE * (*func)(); if(!func) { func = (FILE *(*)()) dlsym(RTLD_NEXT, "fopen"); } printf("fopen is called with parameters: \"%s\", \"%s\"\n", path, mode); return(func(path, mode)); } char *fgets(char *buf, int size, FILE *fp) { static char * (*func)(); char *s; if(!func) { func = (char *(*)()) dlsym(RTLD_NEXT, "fgets"); } printf("fgets is called with size: %d\n", size); s = func(buf, size, fp); printf("fgets returned with string: %s", s); return s; } int fputs(const char *buf, FILE *fp) { static int (*func)(); int n; if(!func) { func = (int (*)()) dlsym(RTLD_NEXT, "fputs"); } printf("fputs is called with string: \"%s\"\n", buf); n = func(buf, fp); return n; }