]> pd.if.org Git - pdclib/blobdiff - functions/string/strncpy.c
Re-import from Subversion.
[pdclib] / functions / string / strncpy.c
index fd6e5d26b14fac318eacaf63ea17cca845755ca3..e89332cfadd633de3444dbb68e4867970bd08d4e 100644 (file)
@@ -1,29 +1,22 @@
-// ----------------------------------------------------------------------------
-// $Id$
-// ----------------------------------------------------------------------------
-// Public Domain C Library - http://pdclib.sourceforge.net
-// This code is Public Domain. Use, modify, and redistribute at will.
-// ----------------------------------------------------------------------------
+/* ----------------------------------------------------------------------------
+ * $Id$
+ * ----------------------------------------------------------------------------
+ * Public Domain C Library - http://pdclib.sourceforge.net
+ * This code is Public Domain. Use, modify, and redistribute at will.
+ * --------------------------------------------------------------------------*/
 
-char * strncpy( char * restrict s1, const char * restrict s2, size_t n ) { /* TODO */ };
+#include <__size_t.h>
 
-/* PDPC code - unreviewed
-char *strncpy(char *s1, const char *s2, size_t n)
+char * strncpy( char * restrict dest, const char * restrict src, size_t n )
 {
-    char *p = s1;
-    size_t x;
-    
-    for (x=0; x < n; x++)
+    char * tmp = dest;
+    while ( ( n-- != 0 ) && ( ( *dest++ = *src++ ) != '\0' ) )
     {
-        *p = *s2;
-        if (*s2 == '\0') break;
-        p++;
-        s2++;
+        /* EMPTY */
     }
-    for (; x < n; x++)
+    while ( n-- != 0 )
     {
-        *p++ = '\0';
+        *dest++ = '\0';
     }
-    return (s1);
+    return tmp;
 }
-*/
\ No newline at end of file