diff options
| author | Roy Marples <roy@marples.name> | 2007-04-05 16:56:58 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2007-04-05 16:56:58 +0000 |
| commit | 235ce0896deb6ce04326f8a1514f0b600b7c8dc1 (patch) | |
| tree | 4fca90eb94025062c7b2285b73852aaf0d337eae /common.c | |
| parent | 505951cbf0e61e07f4452addf17680c3db6a0409 (diff) | |
| download | dhcpcd-235ce0896deb6ce04326f8a1514f0b600b7c8dc1.tar.xz | |
Add safe_strncpy function to ensure everything is NULL terminated
Diffstat (limited to 'common.c')
| -rw-r--r-- | common.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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> |
