This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: overriding fclose(2)


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")


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]