From bd9104762599054a720f693071729923747f669c Mon Sep 17 00:00:00 2001 From: Nelson Ferreira Date: Fri, 2 Mar 2012 17:29:57 -0500 Subject: [PATCH] xstrncpy saga * src/sysdep.h (xstrncpy): New inline function. * src/sysdep.h (xstpncpy): Use xstrncpy instead of strncpy Signed-off-by: Nelson Ferreira --- src/sysdep.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/sysdep.h b/src/sysdep.h index c506d26..7b8fd87 100644 --- a/src/sysdep.h +++ b/src/sysdep.h @@ -189,8 +189,15 @@ extern_inline char *xdirname(const char *file); #define xstrcmp strcmp #define xstrcat strcat #define xstrncmp strncmp -#define xstrncpy strncpy #define xstrncat strncat + +extern_inline char* +xstrncpy(char* target, const char*source, size_t len) +{ + *target ='\0'; + strncat(target,source,len-1); +} + #if defined HAVE_STPCPY # define xstpcpy stpcpy #else @@ -218,7 +225,7 @@ extern_inline char* xstpncpy(char *target, const char *source, size_t len) { char *p = target; - strncpy(target, source, len); + xstrncpy(target, source, len); p += len; return p; } -- 2.34.1