MERGE TO (head, if it isn't ERASER)
git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_1_0_BRANCH@630
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 );
}
-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;
+ }
}
}