3 ms·
I think we can agree that strncpy is not perfect. Perhaps we can rank by levels of sanity? my_string_cpy() < strcpy < strncpy < strncat < snprintf < strlcat I
by angry_octet 11y ago
I think we can agree that strncpy is not perfect. Perhaps we can rank by levels of sanity?
my_string_cpy() < strcpy < strncpy < strncat < snprintf < strlcat
I dislike the strncat approach because if the prior null termination gets lost then problems ensue, whereas with snprintf that won't happen. The BSD man page mentions that snprintf may not be safe for use in signal handlers on some systems; obviously snprintf is a much bigger piece of code.
Personally I dislike using extensive macros, but I'll leave that for the flame war.