Updates for move of net apps to rosapps
[reactos.git] / reactos / apps / utils / net / ncftp / Strn / Strncat.c
1 #include <sys/types.h>
2 #include <string.h>
3 #include "Strn.h"
4
5 /*
6 * Concatenate src on the end of dst. The resulting string will have at most
7 * n-1 characters, not counting the NUL terminator which is always appended
8 * unlike strncat. The other big difference is that strncpy uses n as the
9 * max number of characters _appended_, while this routine uses n to limit
10 * the overall length of dst.
11 */
12 char *
13 Strncat(char *const dst, const char *const src, const size_t n)
14 {
15 register size_t i;
16 register char *d;
17 register const char *s;
18
19 if (n != 0 && ((i = strlen(dst)) < (n - 1))) {
20 d = dst + i;
21 s = src;
22 /* If they specified a maximum of n characters, use n - 1 chars to
23 * hold the copy, and the last character in the array as a NUL.
24 * This is the difference between the regular strncpy routine.
25 * strncpy doesn't guarantee that your new string will have a
26 * NUL terminator, but this routine does.
27 */
28 for (++i; i<n; i++) {
29 if ((*d++ = *s++) == 0) {
30 #if (STRN_ZERO_PAD == 1)
31 /* Pad with zeros. */
32 for (; i<n; i++)
33 *d++ = 0;
34 #endif /* STRN_ZERO_PAD */
35 return dst;
36 }
37 }
38 /* If we get here, then we have a full string, with n - 1 characters,
39 * so now we NUL terminate it and go home.
40 */
41 *d = 0;
42 }
43 return (dst);
44 } /* Strncat */