chiark / gitweb /
[PATCH] update klibc to version 0.181
[elogind.git] / klibc / klibc / strncpy.c
index a8fe45fcbb588bccb28c9fadaf821adef5e0df10..06964f31d687c3ef7acabf3c9ce6076e60de103c 100644 (file)
@@ -1,7 +1,5 @@
 /*
  * strncpy.c
- *
- * strncpy()
  */
 
 #include <string.h>
@@ -12,11 +10,15 @@ char *strncpy(char *dst, const char *src, size_t n)
   const char *p = src;
   char ch;
 
-  while ( n-- ) {
+  while (n) {
+    n--;
     *q++ = ch = *p++;
     if ( !ch )
       break;
   }
 
+  /* The specs say strncpy() fills the entire buffer with NUL.  Sigh. */
+  memset(q, 0, n);
+
   return dst;
 }