overriding fclose(2)

Ondřej Bílka neleai@seznam.cz
Mon May 12 07:42:00 GMT 2014


On Mon, May 12, 2014 at 11:50:35AM +0530, vijay nag wrote:
> Hello glibc,
> 
> I'm trying to override/wrap fclose(2) libc call the following way.
> 
> #include <stdio.h>
> 
> #undef fclose
> extern int _IO_new_fclose(_IO_FILE *fp);  /* defined in ./libio/iofclose.c */
> 
> int __attribute__((weak)) fclose(FILE *stream)
> {
>      /* extra actions before libc fclose */
> 
>      return _IO_new_fclose(stream);
> }
> 
> However, linker barfs out "Undefined reference" error for
> "_IO_new_fclose" symbol. Am I calling the appropriate libc fclose
> function ?

No, its not _IO_new_fclose is visibility is internal for libc.

You could get correct function from dynamic linker like by

dlsym(RTLD_NEXT, "fclose")



More information about the Libc-help mailing list