Re: strncpy clarify result may not be null terminated

Jonny Grant
2023-11-11T21:15:17Z

Alejandro

I was reading again
https://man7.org/linux/man-pages/man7/string_copying.7.html

Sharing some comments, I realise not latest man page, if you have a new one online I could read that. I was reading man-pages 6.04, perhaps some already updated.

A) Could simplify and remove the "This function" and "These functions" that start each function description.

B) "RETURN VALUE" has the text before each function, rather than after as would be the convention from "DESCRIPTION", I suggest to move the return value text after each function name.

Could make it like https://man7.org/linux/man-pages/man3/string.3.html

C) In the examples, it's good stpecpy() checks for NULL pointers, the other's don't yet though.

D) strlcpy says
"These functions force a SIGSEGV if the src pointer is not a string."
How does it determine the pointer isn't a string?

E) Are these functions mentioned like ustpcpy() standardized by POSIX? or in use in a libc?

F)
char *stpncpy(char dst[restrict .sz], const char *restrict src,
size_t sz);
I know the 'restrict' keyword, but haven't seen this way it attempts to specify the size of the 'dst' array by using the parameter 'sz' is this in wide use in APIs? I remember C11 let us specify char ptr[static 1] to say the pointer must be at least 1 element in this example

Saw a few pages started to write out functions like
size_t strnlen(const char s[.maxlen], size_t maxlen);

Is this just for documentation? usually it would be: const char s[static maxlen]

G) "Because these functions ask for the length, and a string is by
nature composed of a character sequence of the same length plus a
terminating null byte, a string is also accepted as input."

I suggest to adjust the order so it doesn't start with a fragment:

"A string is also accepted as input, because these functions ask
for the length, and a string is by nature composed of a character
sequence of the same length plus a terminating null byte."

Could simplify and remove "by nature".

Unrelated man page strncpy, noticed this.

SEE ALSO
Could this refer to strcpy(3) and string(3) at the bottom?
https://man7.org/linux/man-pages/man3/strncpy.3.html

With kind regards
Jonny