b0236c7cf7
The strncpy function has long been deemed unsafe for use, in favor of strlcpy or snprintf. While snprintf is standard and strlcpy is still largely available, they both have issues regarding error checking and performance. Both will force reading the source buffer past the requested size if the input is not a proper c-string, and will return the expected number of bytes copied, meaning that error checking needs to verify that the number of bytes copied is not superior to the destination size. This contributes to awkward code flow, unclear error checking and potential issues with malformed input. The function strscpy has been discussed for some time already and has been made available in the linux kernel[1]. Propose this new function as a safe alternative. [1]: http://git.kernel.org/linus/30c44659f4a3 Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com> Acked-by: Juhamatti Kuusisaari <juhamatti.kuusisaari@coriant.com> Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>