|
|
Subscribe / Log in / New account

Ushering out strlcpy()

Ushering out strlcpy()

Posted Aug 30, 2022 7:10 UTC (Tue) by milesrout (subscriber, #126894)
In reply to: Ushering out strlcpy() by wtarreau
Parent article: Ushering out strlcpy()

>Agreed, I too would like to see strncpy() disappear, as it tends to lie to the reader. I've seen it be entirely responsible for major slowdowns a few times in different projects by the way, where users did not realize that it was padding the whole target buffer.

These people should not be programming in C.

"If the length of src is less than n, strncpy() writes additional null bytes to dest to ensure that a total of n bytes are written."

Right there in the man page. If you can't read the most basic documentation, don't use the language!


to post comments

Ushering out strlcpy()

Posted Aug 30, 2022 14:58 UTC (Tue) by NYKevin (subscriber, #129325) [Link] (1 responses)

IMHO it is not totally unreasonable to expect strncpy(src) to be equivalent to snprintf("%s", size, src), because strcpy(src) is actually equivalent to sprintf("%s", src).

(Incidentally, snprintf is just about the only portable function that DTRT in this context.)

Ushering out strlcpy()

Posted Aug 30, 2022 14:59 UTC (Tue) by NYKevin (subscriber, #129325) [Link]

(Oops, I put the arguments in the wrong order, but you know what I mean.)


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds