From: Julian Seward Date: Sat, 24 Aug 2002 09:29:03 +0000 (+0000) Subject: Merge in Nick's final implementation of VG_(strncpy), from ERASER branch. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83618f7bffad500c54fab8c0f378e1a05b5437d7;p=thirdparty%2Fvalgrind.git Merge in Nick's final implementation of VG_(strncpy), from ERASER branch. MERGE TO (head, if it isn't ERASER) git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_1_0_BRANCH@630 --- diff --git a/vg_include.h b/vg_include.h index f97fd4bbaa..ca1b0b0aa1 100644 --- a/vg_include.h +++ b/vg_include.h @@ -929,7 +929,7 @@ extern Char VG_(toupper) ( Char c ); extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest ); -extern void VG_(strncpy) ( Char* dest, const Char* src, Int ndest ); +extern Char* VG_(strncpy) ( Char* dest, const Char* src, Int ndest ); extern Bool VG_(stringMatch) ( Char* pat, Char* str ); diff --git a/vg_mylibc.c b/vg_mylibc.c index 38f5a3dd42..8769cf1710 100644 --- a/vg_mylibc.c +++ b/vg_mylibc.c @@ -763,14 +763,17 @@ void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest ) } -void VG_(strncpy) ( Char* dest, const Char* src, Int ndest ) +Char* VG_(strncpy) ( Char* dest, const Char* src, Int ndest ) { Int i = 0; while (True) { - if (src[i] == 0) return; - if (i >= ndest) return; + if (i >= ndest) return dest; /* reached limit */ dest[i] = src[i]; - i++; + if (src[i++] == 0) { + /* reached NUL; pad rest with zeroes as required */ + while (i < ndest) dest[i++] = 0; + return dest; + } } }