Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / string / stpcpy.c
blob4e2ae9fe0da67dda204a2948d218dd8822860ca8
1 /*
2 FUNCTION
3 <<stpcpy>>---copy string returning a pointer to its end
5 INDEX
6 stpcpy
8 SYNOPSIS
9 #include <string.h>
10 char *stpcpy(char *restrict <[dst]>, const char *restrict <[src]>);
12 DESCRIPTION
13 <<stpcpy>> copies the string pointed to by <[src]>
14 (including the terminating null character) to the array
15 pointed to by <[dst]>.
17 RETURNS
18 This function returns a pointer to the end of the destination string,
19 thus pointing to the trailing '\0'.
21 PORTABILITY
22 <<stpcpy>> is a GNU extension, candidate for inclusion into POSIX/SUSv4.
24 <<stpcpy>> requires no supporting OS subroutines.
26 QUICKREF
27 stpcpy gnu
30 #include <string.h>
31 #include <limits.h>
33 /*SUPPRESS 560*/
34 /*SUPPRESS 530*/
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)
42 #else
43 #if LONG_MAX == 9223372036854775807L
44 /* Nonzero if X (a long int) contains a NULL byte. */
45 #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
46 #else
47 #error long int is not a 32bit or 64bit type.
48 #endif
49 #endif
51 #ifndef DETECTNULL
52 #error long int is not a 32bit or 64bit byte
53 #endif
55 char*
56 stpcpy (char *__restrict dst,
57 const char *__restrict src)
59 #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
60 long *aligned_dst;
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"
70 sized copies. */
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++))
83 return --dst;