summaryrefslogtreecommitdiffstats
path: root/include/xstrncpy.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/xstrncpy.h')
-rw-r--r--include/xstrncpy.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/include/xstrncpy.h b/include/xstrncpy.h
new file mode 100644
index 000000000..7ed4109d6
--- /dev/null
+++ b/include/xstrncpy.h
@@ -0,0 +1,8 @@
+/* NUL-terminated version of strncpy() */
+#include <string.h>
+
+/* caller guarantees n > 0 */
+static inline void xstrncpy(char *dest, const char *src, size_t n) {
+ strncpy(dest, src, n-1);
+ dest[n-1] = 0;
+}