3 <<strncat>>---concatenate strings
10 char *strncat(char *restrict <[dst]>, const char *restrict <[src]>,
14 <<strncat>> appends not more than <[length]> characters from
15 the string pointed to by <[src]> (including the terminating
16 null character) to the end of the string pointed to by
17 <[dst]>. The initial character of <[src]> overwrites the null
18 character at the end of <[dst]>. A terminating null character
19 is always appended to the result
22 Note that a null is always appended, so that if the copy is
23 limited by the <[length]> argument, the number of characters
24 appended to <[dst]> is <<n + 1>>.
27 This function returns the initial value of <[dst]>
30 <<strncat>> is ANSI C.
32 <<strncat>> requires no supporting OS subroutines.
41 /* Nonzero if X is aligned on a "long" boundary. */
43 (((long)X & (sizeof (long) - 1)) == 0)
45 #if LONG_MAX == 2147483647L
46 #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
48 #if LONG_MAX == 9223372036854775807L
49 /* Nonzero if X (a long int) contains a NULL byte. */
50 #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
52 #error long int is not a 32bit or 64bit type.
57 #error long int is not a 32bit or 64bit byte
61 strncat (char *__restrict s1
,
62 const char *__restrict s2
,
65 #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
70 while (n
-- != 0 && (*s1
++ = *s2
++))
80 /* Skip over the data in s1 as quickly as possible. */
83 unsigned long *aligned_s1
= (unsigned long *)s1
;
84 while (!DETECTNULL (*aligned_s1
))
87 s1
= (char *)aligned_s1
;
93 /* s1 now points to the its trailing null character, now copy
94 up to N bytes from S2 into S1 stopping if a NULL is encountered
97 It is not safe to use strncpy here since it copies EXACTLY N
98 characters, NULL padding if necessary. */
99 while (n
-- != 0 && (*s1
++ = *s2
++))
106 #endif /* not PREFER_SIZE_OVER_SPEED */