FMTCHECK(3)
π 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_suspectis a valid format and consumes the same argument types asfmt_default, thenfmtcheck()returnsfmt_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
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2000 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms