diff options
author | Alejandro Colomar <alx@kernel.org> | 2023-11-21 19:15:29 +0100 |
---|---|---|
committer | Alejandro Colomar <alx@kernel.org> | 2023-11-22 12:34:10 +0100 |
commit | 249999de88ad72a300ddb192bfab1850f9a7e203 (patch) | |
tree | 9c8cc01062f7735b29866bedc43f716c98518829 | |
parent | e2b2392e1d062afa7a8c6b56072d371163984ffe (diff) |
stpncpy.3: EXAMPLES: Use fwrite(3) instead of printf(3)
fwrite(3) is more appropriate for printing a character sequence with
known lenght. printf(3) has a limitation of INT_MAX, and also requires
more complex (less readable) code.
Suggested-by: Paul Eggert <eggert@cs.ucla.edu>
Cowritten-by: Paul Eggert <eggert@cs.ucla.edu>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r-- | man3/stpncpy.3 | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/man3/stpncpy.3 b/man3/stpncpy.3 index 058db482d..2f8cab250 100644 --- a/man3/stpncpy.3 +++ b/man3/stpncpy.3 @@ -156,7 +156,8 @@ main(void) len = strnlen(buf2, sizeof(buf2)); \& printf("[len = %zu]: ", len); - printf("%.*s\en", (int) len, buf2); // "Hello world!" + fwrite(buf2, 1, len, stdout); + putchar(\[aq]\en\[aq]); \& if (sizeof(buf1) < strlen("Hello world!")) warnx("stpncpy: truncating character sequence"); @@ -164,7 +165,8 @@ main(void) len = p \- buf1; \& printf("[len = %zu]: ", len); - printf("%.*s\en", (int) len, buf1); // "Hello world!" + fwrite(buf1, 1, len, stdout); + putchar(\[aq]\en\[aq]); \& exit(EXIT_SUCCESS); } |