Home > Software engineering >  How can I find source code of printf in macOS?
How can I find source code of printf in macOS?

Time:03-23

Sorry for my bad english.

I'm using macOS 12.3 in M1 Pro MacBook Pro

I want to know about source code of printf in C standard library.

I can find stdio.h file in usr/include directory.

But I can't find printf.c or stdio.c file in same directory.

And I think Apple Open Source's printf.c is too complicate, dosen't looks like a real code in macOS and dosen't helpful for me. Is that Apple Open Source printf.c code is really used in macOS?

https://opensource.apple.com/source/xnu/xnu-201/osfmk/kern/printf.c.auto.html

CodePudding user response:

The newest Apple Open Source libc implementation of vfprintf (which is the generic underlying function that plain printf calls) can be found here on opensource.apple.com.

It's about 1400 lines, and yes, it is complex.

Some other alternate implementations (which are complex too) are:

  • Related