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: How to override printf/scanf calls


On Wed, Oct 7, 2009 at 11:15 PM, Bharath Ramesh <bramesh@vt.edu> wrote:
> I know that I can override most system calls in libc writing the function
> with the right signature and then creating a shard library out of it and use
> the LD_PRELOAD mechanism when I run any application. This method doesn't not
> work for libc calls like printf/scanf. Writing a shared library with any of
> this calls has issues as ld cant preload this shared library. The only other
> option I have at the moment is to download glibc source and rebuild glibc
> with appropriate changes. This makes the solution not portable, I was
> wondering if there was any other way by which I could override libc calls
> like printf/scanf?
>
> Regards,
>
> Bharath
>

For printf (in version 2.10) there is an override mechanism in place.
Please reference how I used it in libdfp:

http://www.eglibc.org/cgi-bin/viewcvs.cgi/libdfp/trunk/printf_dfp.c?rev=8808&view=markup

Look for the __dfp_ais function and __d32_va, __d64_va, __d128_va functions.

Also look at __register_printf_dfp for how to register your hooks.

There is no similar mechanism for scanf.  It is recommended that uses
simply use <type>to functions instead of scanf directly.

Ryan S. Arnold


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