summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2023-11-15 22:31:02 +0100
committerAlejandro Colomar <alx@kernel.org>2023-11-16 15:26:45 +0100
commitfb3cf24b56f3d6c14a566161dc40a29e5406b41c (patch)
tree51751c1c75262b7495c25d014b42250db4cef57d
parent8711bc63fef4c6e186039bfb1ed543485ae478db (diff)
lib/strncpy.h: Add STRNCPY() wrapper for strncpy(3)
This wrapper calculates the destination buffer's size, to avoid errors in the size calculation. Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r--lib/Makefile.am1
-rw-r--r--lib/strncpy.h21
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 96dfefe2..bfe13c33 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -141,6 +141,7 @@ libshadow_la_SOURCES = \
stpecpy.h \
stpeprintf.c \
stpeprintf.h \
+ strncpy.h \
strtcpy.c \
strtcpy.h \
strtoday.c \
diff --git a/lib/strncpy.h b/lib/strncpy.h
new file mode 100644
index 00000000..90e76f0f
--- /dev/null
+++ b/lib/strncpy.h
@@ -0,0 +1,21 @@
+/*
+ * SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+
+#ifndef SHADOW_INCLUDE_LIB_STRNCPY_H_
+#define SHADOW_INCLUDE_LIB_STRNCPY_H_
+
+
+#include <config.h>
+
+#include <string.h>
+
+#include "sizeof.h"
+
+
+#define STRNCPY(dst, src) strncpy(dst, src, SIZEOF_ARRAY(dst))
+
+
+#endif // include guard