Search code examples
c++printfimplementationglibc

Where can I find an existing implementation of sprintf?


I need to customize c++ sprintf function, after step into sprintf, i got _cfltcvt_l, but there isn't _cfltcvt_l source code in visual studio.

I did the same thing in g++, it lead me to __mingw_vsprintf function, but i don't know where __mingw_vsprintf is.

I know that glibc is one of the implements, after downloaded, i can't find any file related to sprintf, So could anyone tell me where can I find an existing implementation of sprintf?


Solution

  • There's quite a train of functions to follow in glibc:

    First, there's sprintf which calls vsprintf which calls vfprintf which does all the work. I believe the io and _IO_ prefixes might be irrelevant. They might not be, in which case my answer is wrong.


    On the MinGW-w64 side of things the train follows a different path:

    First, you have mingw_sprintf, which calls __pformat or mingw_pformat which looks like it does all the work.


    I never got to figuring out how BSD libc is structured, so I can't show you their implementation.