]> pd.if.org Git - pdclib/blobdiff - functions/string/strncpy.c
Reviewed.
[pdclib] / functions / string / strncpy.c
index 2d865d782b7f0601798aa0b84ba600a6d65fe1ff..3784df4dcdf2c8fbc722adb5455230567bf21b12 100644 (file)
@@ -5,4 +5,18 @@
 // 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>
+
+char * strncpy( char * restrict dest, const char * restrict src, size_t n )
+{
+    char * tmp = dest;
+    while ( ( n-- != 0 ) && ( ( *dest++ = *src++ ) != '\0' ) )
+    {
+        // EMPTY
+    }
+    while ( n-- != 0 )
+    {
+        *dest++ = '\0';
+    }
+    return tmp;
+}