customizing scanf ?

Basile STARYNKEVITCH basile@starynkevitch.net
Sun Oct 11 14:17:32 GMT 2026


On Sun, 2026-10-11 at 10:09 -0400, Carlos O'Donell wrote:
> On Fri, Oct 9, 2026 at 3:38 PM Basile STARYNKEVITCH
> <basile@starynkevitch.net> wrote:
> > With GNU libc, its printf and fprintf can be customized, see
> > https://sourceware.org/glibc/manual/latest/html_node/Customizing-Printf.html
> > 
> > Is there any analogue facilities to customize scanf?
> 
> No. There is no facility to customize scanf.
> 
> > (or do you know about any open source software adding customization
> > for
> > scanf)
> 
> There are many reasons why scanf is not implemented.
> 
> Firstly in order to implement a custom scanf handler we would have to
> rearchitect the vfscanf internals to expose quite a large API surface
> to allow forward scanning of the buffer, push back, and several other
> models for allowing the specifier to match input.

Thanks for the above explanation.

> 
> What would the be the case for adding this hook? Can you achieve the
> same thing with a wrapper that interposes the function?


I tend to believe that scanf can be indirectly customized by using
custom streams obtained by fopencookie.

I also believe that even customized printf is not often used in 2026
(few software components on github are today using fopencookie).

Otherwise the GCC compiler would offer more support about them, perhaps
implemented as standard compiler plugins shipped with recent GCC.

(most Linux programming don't do that).

Thanks for reading, and sorry for my English, I am French.

NB: see also github.com/RefPerSys
-- 

Basile STARYNKEVITCH                           
<basile@starynkevitch.net>
8 rue de la Faïencerie                      
http://starynkevitch.net/Basile/  
92340 Bourg-la-Reine                        
https://github.com/bstarynk
France                               
https://github.com/RefPerSys/RefPerSys
                  https://orcid.org/0000-0003-0908-5250


More information about the Libc-help mailing list