]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Merge in Nick's final implementation of VG_(strncpy), from ERASER branch.
authorJulian Seward <jseward@acm.org>
Sat, 24 Aug 2002 09:29:03 +0000 (09:29 +0000)
committerJulian Seward <jseward@acm.org>
Sat, 24 Aug 2002 09:29:03 +0000 (09:29 +0000)
MERGE TO (head, if it isn't ERASER)

git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_1_0_BRANCH@630

vg_include.h
vg_mylibc.c

index f97fd4bbaa46f71c7f357dd76322b03e9b7c66fb..ca1b0b0aa128f63906b9380b895c3d2bbb912ee6 100644 (file)
@@ -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 );
 
index 38f5a3dd4261b8fb0a52c6e1f49e601cf47b1dfb..8769cf1710e409c856ecd297388a6a3f2a14c0c0 100644 (file)
@@ -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;
+      }
    }
 }