X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstring%2Fstrncpy.c;h=e89332cfadd633de3444dbb68e4867970bd08d4e;hp=2d865d782b7f0601798aa0b84ba600a6d65fe1ff;hb=1d9d92ba957a0b8307c9a65c35867fde68e6533b;hpb=34893ecc2200dc7017c36a54cb6c5f4c2378b5ec diff --git a/functions/string/strncpy.c b/functions/string/strncpy.c index 2d865d7..e89332c 100644 --- a/functions/string/strncpy.c +++ b/functions/string/strncpy.c @@ -1,8 +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> + +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; +}