$ cat a.c #define _XOPEN_SOURCE 500 #include <stdio.h> int main() { char dest[255], src[] = "Hello"; snprintf(dest, sizeof(dest), "%s", src); } $ cc -Werror a.c a.c:7:3: error: implicitly declaring library function 'snprintf' with type 'int (char *, unsigned long, const char *, ...)' [-Werror,-Wimplicit-function-declaration] snprintf(dest, sizeof(dest), "%s", src); ^ a.c:7:3: note: include the header <stdio.h> or explicitly provide a declaration for 'snprintf' 1 error generated. According to https://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html Issue 5 Aligned with ISO/IEC 9899:1990/Amendment 1:1995 (E). Specifically, the l (ell) qualifier can now be used with c and s conversion specifiers. The snprintf() function is new in Issue 5. Example fix - https://github.com/dragonflybsd/dragonflybsd/commit/626be21490
Real world example from a library bundled with Firefox: $ git clone https://github.com/kinetiknz/cubeb $ cd cubeb $ CFLAGS="-isystem/usr/local/include" LDFLAGS="-L/usr/local/lib" cmake . $ make [...] src/cubeb_alsa.c:564:9: warning: implicitly declaring library function 'snprintf' with type 'int (char *, unsigned long, const char *, ...)' [-Wimplicit-function-declaration] r = snprintf(node_name, sizeof(node_name), "pcm.%s", string); ^ $ fgrep XOPEN src/cubeb_alsa.c #define _XOPEN_SOURCE 500 I cannot fix the warning upstream because neither Linux nor other BSDs are affected.
Created attachment 207271 [details] Make snprintf/vscanf visible under appropriate XSI visibility.
I agree with the snprintf/vsnprintf part of https://bugs.freebsd.org/bugzilla/attachment.cgi?id=207271&action=diff except that the test should be for __POSIX_VISIBLE >= 199506 instead of __XSI_VISIBLE >= 500 since this is not an XSI extension. The change to vfscanf/vscanf/vsscanf is redundant since __XSI_VISIBLE == 600 already implies C99.
Created attachment 207287 [details] Make snprintf/vscanf visible under appropriate POSIX visibility.
Attachment 207287 [details] looks good to me.