strncpy will never be the right answer when your destination string ends in zero. strncpy is a function intended for use with unlimited fixed-width strings. More precisely, its purpose is to convert a zero-terminated string to a string with unlimited length (by copying). In other words, strncpy doesn't make sense here.
The real choice is between strlcpy and plain strcpy .
If you want to perform a “safe” (i.e. potentially truncated) copy to dst_arr , the correct function to use is strlcpy .
As for dst_ptr ... There is no such thing as "copy to dst_ptr ". You can copy to the memory indicated by dst_ptr , but first you need to make sure that it points somewhere and allocates that memory. There are many different ways to do this.
For example, you can just do dst_ptr to point to dst_arr , in which case the answer will be the same as in the previous case - strlcpy .
Or you can allocate memory using malloc . If the amount of allocated memory is guaranteed to be sufficient for the string (i.e., at least strlen(src_str) + 1 bytes is strlen(src_str) + 1 ), you can use plain strcpy or even memcpy to copy the string. There is no need and no reason to use strlcpy in this case, although some people may prefer to use it, as it somehow gives them a sense of added security.
If you intentionally allocate less memory (i.e. want your string to be truncated), then strlcpy becomes the right function.
source share