Dan Cross reported that Plan9 has equivalent functions, called [v]seprint(3). Let's honor Plan9, and reuse their choice of a name, which is more concise (except that we keep the trailing 'f', for consistency with the ISO C printf(3) family of functions).
That might also give some visibility to this API, which is superior to snprintf(3) in some use cases (chaining several calls; catenating formatted strings).
Replace our source code documentation by a reference (and link) to Plan9's [v]seprint(3) manual page.
Dan Cross reported that Plan9 has equivalent functions, called [v]seprint(3). Let's honor Plan9, and reuse their choice of a name, which is more concise (except that we keep the trailing 'f', for consistency with the ISO C printf(3) family of functions).
That might also give some visibility to this API, which is superior to snprintf(3) in some use cases (chaining several calls; catenating formatted strings).
Replace our source code documentation by a reference (and link) to Plan9's [v]seprint(3) manual page.
Link: https://9fans.github.io/plan9port/man/man3/print.html Reported-by: @dancrossnyc
Revisions:
v2
- Keep in a separate file: lib/string/seprintf.[ch] ``` $ git range-diff shadow/master gh/seprintf seprintf 1: 0b5d7360 ! 1: d046d7db lib/string/sprintf.*, lib/, src/: Rename [v]stpeprintf() to > @@ Metadata Author: Alejandro Colomarv3
- Remove unnecessary include - Re-organize lib/string/ into subdirectories ``` $ git range-diff master gh/seprintf seprintf 1: d046d7db ! 1: 4cfbb930 lib/string/seprintf.[ch], lib/, src/: Rename [v]stpeprintf() to [v]seprintf() @@ lib/string/seprintf.h (new) +#includev3b
- @dancrossnyc reviewed the first patch ``` $ git range-diff master gh/seprintf seprintf 1: 4cfbb930 ! 1: abdf883b lib/string/seprintf.[ch], lib/, src/: Rename [v]stpeprintf() to [v]seprintf() @@ Commit message Link:v3c
- Fix file name ``` $ git range-diff master gh/seprintf seprintf 1: abdf883b = 1: abdf883b lib/string/seprintf.[ch], lib/, src/: Rename [v]stpeprintf() to [v]seprintf() 2: 4db1536e ! 2: 66b96d18 lib/string/sprintf/, lib/, src/, tests/: Move all sprintf(3)-like APIs to a subdirectory @@ tests/unit/Makefile.am: test_strtcpy_LDADD = \ $(NULL) test_xasprintf_CFLAGS = \ - ## tests/unit/test_sprintf.c ## + ## tests/unit/test_sprintf.c => tests/unit/test_snprintf.c ## @@ #includev3d
- Rebase ``` $ git range-diff gh/master..gh/seprintf master..seprintf 1: abdf883b = 1: c13092b6 lib/string/seprintf.[ch], lib/, src/: Rename [v]stpeprintf() to [v]seprintf() 2: 66b96d18 = 2: dc6da914 lib/string/sprintf/, lib/, src/, tests/: Move all sprintf(3)-like APIs to a subdirectory 3: 90565c02 = 3: 0bbfc60f lib/string/strcpy/, lib/, src/, tests/: Move all copying APIs to a subdirectory ```v4
- Do not rename the API. Just move the files around for a better organization. The Plan9 API cannot detect truncation. If Plan9 improves their API, we'll rename ours in the future. (Cc: @hallyn ) ``` $ git range-diff gh/master gh/seprintf seprintf 1: c13092b6 < -: -------- lib/string/seprintf.[ch], lib/, src/: Rename [v]stpeprintf() to [v]seprintf() 2: dc6da914 ! 1: a77a6a59 lib/string/sprintf/, lib/, src/, tests/: Move all sprintf(3)-like APIs to a subdirectory @@ lib/Makefile.am: libshadow_la_SOURCES = \ spawn.c \ sssd.c \ sssd.h \ -- string/seprintf.c \ -- string/seprintf.h \ - string/sprintf.c \ - string/sprintf.h \ -+ string/sprintf/seprintf.c \ -+ string/sprintf/seprintf.h \ + string/sprintf/snprintf.c \ + string/sprintf/snprintf.h \ ++ string/sprintf/stpeprintf.c \ ++ string/sprintf/stpeprintf.h \ + string/sprintf/xasprintf.c \ + string/sprintf/xasprintf.h \ string/stpecpy.c \ string/stpecpy.h \ +- string/stpeprintf.c \ +- string/stpeprintf.h \ string/strftime.c \ + string/strftime.h \ + string/strncpy.h \ ## lib/commonio.c ## @@ @@ lib/idmapping.c #include "alloc.h" #include "atoi/str2i.h" #include "prototypes.h" --#include "string/seprintf.h" -+#include "string/sprintf/seprintf.h" +-#include "string/stpeprintf.h" ++#include "string/sprintf/stpeprintf.h" #include "idmapping.h" #if HAVE_SYS_CAPABILITY_H #includev4b
- Rebase ``` $ git range-diff gh/master..gh/seprintf shadow/master..seprintf 1: a77a6a59 ! 1: 9c7d1b78 lib/string/sprintf/, lib/, src/, tests/: Move all sprintf(3)-like APIs to a subdirectory @@ lib/env.c ## lib/get_pid.c ## @@ - #include