X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstring%2Fstrncat.c;h=4a819919e1b969e3aa3283abba399ab28f4404f4;hp=1bc202398636595fb72da31940acc6c4d47bdd88;hb=1d9d92ba957a0b8307c9a65c35867fde68e6533b;hpb=0a5395faab237ba9008352b0f4bee9659bbd3d5f diff --git a/functions/string/strncat.c b/functions/string/strncat.c index 1bc2023..4a81991 100644 --- a/functions/string/strncat.c +++ b/functions/string/strncat.c @@ -1,26 +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 * strncat( char * restrict s1, const char * restrict s2, size_t n ) { /* TODO */ }; +#include <__size_t.h> -/* PDPC code - unreviewed +char * strncat( char * restrict dest, const char * restrict src, size_t n ) { - char *p = s1; - size_t x = 0; - - while (*p != '\0') p++; - while ((*s2 != '\0') && (x < n)) + char * tmp = dest; + while ( *dest != '\0' ) { - *p = *s2; - p++; - s2++; - x++; + ++dest; } - *p = '\0'; - return (s1); + while ( ( n-- > 0 ) && ( *src != '\0' ) ) + { + *dest++ = *src++; + } + return tmp; } -*/