Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / string / strcpy.c
blob94e16b512b9eea1e0eef5c40fed46841c063bfde
1 /*
2 FUNCTION
3 <<strcpy>>---copy string
5 INDEX
6 strcpy
8 SYNOPSIS
9 #include <string.h>
10 char *strcpy(char *<[dst]>, const char *<[src]>);
12 DESCRIPTION
13 <<strcpy>> 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 the initial value of <[dst]>.
20 PORTABILITY
21 <<strcpy>> is ANSI C.
23 <<strcpy>> requires no supporting OS subroutines.
25 QUICKREF
26 strcpy ansi pure
29 #include <string.h>
30 #include <limits.h>
32 /*SUPPRESS 560*/
33 /*SUPPRESS 530*/
35 /* Nonzero if either X or Y is not aligned on a "long" boundary. */
36 #define UNALIGNED(X, Y) \
37 (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
39 #if LONG_MAX == 2147483647L
40 #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
41 #else
42 #if LONG_MAX == 9223372036854775807L
43 /* Nonzero if X (a long int) contains a NULL byte. */
44 #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
45 #else
46 #error long int is not a 32bit or 64bit type.
47 #endif
48 #endif
50 #ifndef DETECTNULL
51 #error long int is not a 32bit or 64bit byte
52 #endif
54 char*
55 strcpy (char *dst0,
56 const char *src0)
58 #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
59 char *s = dst0;
61 while (*dst0++ = *src0++)
64 return s;
65 #else
66 char *dst = dst0;
67 const char *src = src0;
68 long *aligned_dst;
69 const long *aligned_src;
71 /* If SRC or DEST is unaligned, then copy bytes. */
72 if (!UNALIGNED (src, dst))
74 aligned_dst = (long*)dst;
75 aligned_src = (long*)src;
77 /* SRC and DEST are both "long int" aligned, try to do "long int"
78 sized copies. */
79 while (!DETECTNULL(*aligned_src))
81 *aligned_dst++ = *aligned_src++;
84 dst = (char*)aligned_dst;
85 src = (char*)aligned_src;
88 while ((*dst++ = *src++))
90 return dst0;
91 #endif /* not PREFER_SIZE_OVER_SPEED */