From 024f3f717238a1f764df7ad0ae310da6e10c3123 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 22 Dec 2023 11:41:02 +0100 Subject: [PATCH] string: add strncpy for fixed-size buffers Signed-off-by: Simon Rozman --- include/stdex/string.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/stdex/string.hpp b/include/stdex/string.hpp index 1b7e64e28..25ba752a2 100644 --- a/include/stdex/string.hpp +++ b/include/stdex/string.hpp @@ -1503,6 +1503,22 @@ namespace stdex } } + /// + /// Copy zero-terminated string + /// + /// \param[in] dst Destination string + /// \param[in] src Source string + /// + /// \return Number of code units excluding zero terminator in the dst string after the operation. + /// + template + inline size_t strncpy( + _Out_ _Post_maybez_ T1 (&dst)[N1], + _In_ const T2 (&src)[N2]) + { + return strncpy(dst, N1, src, N2); + } + /// /// Append zero-terminated string ///