This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Override fscanf memory allocation function?
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Ian Pilcher <arequipeno at gmail dot com>
- Cc: libc-help at sourceware dot org
- Date: Tue, 14 Jan 2014 17:28:40 +0100
- Subject: Re: Override fscanf memory allocation function?
- Authentication-results: sourceware.org; auth=none
- References: <lb3nau$amp$1 at ger dot gmane dot org>
On Tue, Jan 14, 2014 at 10:06:54AM -0600, Ian Pilcher wrote:
> Is it possible to override the memory allocation function used by scanf
> and friends when the 'm' flag is used with a string conversion?
>
> I am writing a library, and I would like to allow the application to
> specify the memory management functions used by the library.
>
> My library uses fscanf to read files line-by-line:
>
> fscanf(in, "%m[^\n]", &line)
>
> Thanks!
>
Not directly, there is a solution that is overkill, override a
malloc by a LD_PRELOADED library then use backtrace to check if
a malloc was called from fscanf and call appropriate function if so.