This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: overriding fclose(2)
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: vijay nag <vijunag at gmail dot com>
- Cc: "libc-help at sourceware dot org" <libc-help at sourceware dot org>
- Date: Mon, 12 May 2014 09:37:11 +0200
- Subject: Re: overriding fclose(2)
- Authentication-results: sourceware.org; auth=none
- References: <CAKhyrx-5s7jNsYnAu1pJAe==pZsQVkWGKcH-L8yhQw1+Z5bwMw at mail dot gmail dot com>
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")