News for hackers. Stuff that matters.
Re:Tearing apart printf() (2018) by eqvinox on Wednesday November 13, 2019 @07:09AM (#21523181)
As far as the formatting part is concerned, if you just want to look at an implementation, FreeBSD's is extremely nice and readable:

https://github.com/lattera/freebsd/blob/master/lib/libc/stdi...

For FRRouting, we decided we want to use Linux kernel style extensions (like "%pI4"), so to get this in a portable way we imported FreeBSD's printf into our code. Since printf() isn't exactly "hot" code getting changed a lot, we considered the maintenance / duplication cost acceptable.

You can see the result here:

https://github.com/FRRouting/frr/tree/master/lib/printf

http://docs.frrouting.org/projects/dev-guide/en/latest/loggi...

stdio support is completely gone in our copy, WCHAR_SUPPORT is disabled at compile time, locale support is stubbed out/hardcoded to C locale. None of these matter to us. As a result, we can use this printf even in the SEGV handler. (That's only a bonus though, the main reason was extensibility on the format specifiers.)

There are no comments on this comment yet.