FMTCHECK(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’– NAME πŸ’–

okay so fmtcheck(3) β€” straight out of the Library Functions Manual β€” is the little icon that sanitizes a user-supplied printf(3)-style format string. no cap, that's the whole vibe.

🧚 LIBRARY 🧚

Standard C Library (libc, -lc) πŸ’…

✨ SYNOPSIS ✨

#include <stdio.h>

const char *
fmtcheck(const char *fmt_suspect, const char *fmt_default);

πŸ¦‹ DESCRIPTION πŸ¦‹

fmtcheck() scans fmt_suspect and fmt_default to figure out if fmt_suspect will consume the same argument types as fmt_default β€” and to make sure fmt_suspect is a valid format string. lowkey a vibe check for format strings πŸ’–

The printf(3) family of functions cannot verify the types of arguments that they are passed at run-time. sometimes, like with catgets(3), it's useful or necessary to use a user-supplied format string with no guarantee that the format string matches the specified arguments. 😭

fmtcheck() was designed to be used in these cases, as in:

printf(fmtcheck(user_format, standard_format), arg1, arg2);

In the check, field widths, fillers, precisions, etc. are ignored (unless the field width or precision is an asterisk * instead of a digit string). also, any text other than the format specifiers is completely ignored. periodt. πŸ’…

πŸŽ€ RETURN VALUES πŸŽ€

  • if fmt_suspect is a valid format and consumes the same argument types as fmt_default, then fmtcheck() returns fmt_suspect βœ…
  • otherwise, it returns fmt_default πŸ”

🌈 SEE ALSO 🌈

printf(3) πŸ‘‘ that's the whole crew.

πŸ’€ BUGS πŸ’€

The fmtcheck() function does not recognize positional parameters. not me finding out the hard way πŸ™ˆ

πŸ”₯ SECURITY CONSIDERATIONS πŸ”₯

note that the formats may be quite different as long as they accept the same arguments. for example:

"%p %o %30s %#llx %-10.*e %n"

is compatible with:

"This number %lu %d%% and string %s has %qd numbers and %.*g floats (%n)"

However, "%o" is not equivalent to "%lx" because the first requires an integer and the second requires a long. fr fr, don't mix those up πŸ’…


kisses bestie, this page is from Debian, dated October 16, 2002 🫢✨

πŸ“¦ where this page comes from