3 <<stpcpy>>---copy string returning a pointer to its end
10 char *stpcpy(char *restrict <[dst]>, const char *restrict <[src]>);
13 <<stpcpy>> copies the string pointed to by <[src]>
14 (including the terminating null character) to the array
15 pointed to by <[dst]>.
18 This function returns a pointer to the end of the destination string,
19 thus pointing to the trailing '\0'.
22 <<stpcpy>> is a GNU extension, candidate for inclusion into POSIX/SUSv4.
24 <<stpcpy>> requires no supporting OS subroutines.
36 /* Nonzero if either X or Y is not aligned on a "long" boundary. */
37 #define UNALIGNED(X, Y) \
38 (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
40 #if LONG_MAX == 2147483647L
41 #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
43 #if LONG_MAX == 9223372036854775807L
44 /* Nonzero if X (a long int) contains a NULL byte. */
45 #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
47 #error long int is not a 32bit or 64bit type.
52 #error long int is not a 32bit or 64bit byte
56 stpcpy (char *__restrict dst
,
57 const char *__restrict src
)
59 #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
61 const long *aligned_src
;
63 /* If SRC or DEST is unaligned, then copy bytes. */
64 if (!UNALIGNED (src
, dst
))
66 aligned_dst
= (long*)dst
;
67 aligned_src
= (long*)src
;
69 /* SRC and DEST are both "long int" aligned, try to do "long int"
71 while (!DETECTNULL(*aligned_src
))
73 *aligned_dst
++ = *aligned_src
++;
76 dst
= (char*)aligned_dst
;
77 src
= (char*)aligned_src
;
79 #endif /* not PREFER_SIZE_OVER_SPEED */
81 while ((*dst
++ = *src
++))