Re:Considering C99 for Curl
by masklinn on Tuesday November 22, 2022 @11:36AM
(#33707636)
But it's not an str* function, it's an strn* function. And most (though not all, that would be too easy) work on fixed-size (hence the n) nul-padded strings.
[ Parent
| on HN ]
No. It isn't. It has absolutely nothing to do with strings. There is no such thing as a fixed-sized string in C. "A string is a contiguous sequence of characters terminated by and including the first null character." § 7.1.1.
Calling your bespoke byte-sequence data structure a "string" is inaccurate and viewing strncpy() as a string function is erroneous and will lead to buffer overflows.
Have you considered giving reading comprehension a try?
Fixed-size strings are strings, just not nul-terminated strings. So are length-prefixed (“pascal”) strings.
Strncpy does not work with nul-terminated strings as I noted. If you’re working with fixed-size nul-padded strings however it’s the correct function to use.
> Have you considered giving reading comprehension a try?
Don't do this.