3 ms·
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
by eqvinox 7y ago
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/stdio/vfprintf.c 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 https://github.com/FRRouting/frr/tree/master/lib/printf
http://docs.frrouting.org/projects/dev-guide/en/latest/logging.html 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.)