summaryrefslogtreecommitdiffstats
path: root/common.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-04-05 16:56:58 +0000
committerRoy Marples <roy@marples.name>2007-04-05 16:56:58 +0000
commit235ce0896deb6ce04326f8a1514f0b600b7c8dc1 (patch)
tree4fca90eb94025062c7b2285b73852aaf0d337eae /common.c
parent505951cbf0e61e07f4452addf17680c3db6a0409 (diff)
downloaddhcpcd-235ce0896deb6ce04326f8a1514f0b600b7c8dc1.tar.xz
Add safe_strncpy function to ensure everything is NULL terminated
Diffstat (limited to 'common.c')
-rw-r--r--common.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/common.c b/common.c
index c7a50e02..8246b8e1 100644
--- a/common.c
+++ b/common.c
@@ -27,6 +27,16 @@
#include "common.h"
#include "logger.h"
+/* A way of safely handling strncpy */
+char *safe_strncpy (char *dst, const char *src, size_t size)
+{
+ if (! size)
+ return dst;
+
+ dst[--size] = '\0';
+ return strncpy (dst, src, size);
+}
+
/* This requires us to link to rt on glibc, so we use sysinfo instead */
#ifdef __linux__
#include <sys/sysinfo.h>