1 /*
2 FUNCTION
3 	<<strcpy>>---copy string
4 
5 INDEX
6 	strcpy
7 
8 ANSI_SYNOPSIS
9 	#include <string.h>
10 	char *strcpy(char *<[dst]>, const char *<[src]>);
11 
12 TRAD_SYNOPSIS
13 	#include <string.h>
14 	char *strcpy(<[dst]>, <[src]>)
15 	char *<[dst]>;
16 	char *<[src]>;
17 
18 DESCRIPTION
19 	<<strcpy>> copies the string pointed to by <[src]>
20 	(including the terminating null character) to the array
21 	pointed to by <[dst]>.
22 
23 RETURNS
24 	This function returns the initial value of <[dst]>.
25 
26 PORTABILITY
27 <<strcpy>> is ANSI C.
28 
29 <<strcpy>> requires no supporting OS subroutines.
30 
31 QUICKREF
32 	strcpy ansi pure
33 */
34 
35 #include <section_config.h>
36 #include <basic_types.h>
37 
38 #include <string.h>
39 #include <limits.h>
40 
41 /*SUPPRESS 560*/
42 /*SUPPRESS 530*/
43 
44 /* Nonzero if either X or Y is not aligned on a "long" boundary.  */
45 #define UNALIGNED(X, Y) \
46   (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
47 
48 #if LONG_MAX == 2147483647L
49 #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
50 #else
51 #if LONG_MAX == 9223372036854775807L
52 /* Nonzero if X (a long int) contains a NULL byte. */
53 #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
54 #else
55 #error long int is not a 32bit or 64bit type.
56 #endif
57 #endif
58 
59 #ifndef DETECTNULL
60 #error long int is not a 32bit or 64bit byte
61 #endif
62 
63 LIBC_ROM_TEXT_SECTION
64 _LONG_CALL_
_strcpy(char * dst0,const char * src0)65 char* _strcpy(char *dst0 , const char *src0)
66 {
67 #if defined(PREFER_SIZE_OVER_SPEED)
68   char *s = dst0;
69 
70   while (*dst0++ = *src0++)
71     ;
72 
73   return s;
74 #else
75   char *dst = dst0;
76   const char *src = src0;
77   long *aligned_dst;
78   const long *aligned_src;
79 
80   /* If SRC or DEST is unaligned, then copy bytes.  */
81   if (!UNALIGNED (src, dst))
82     {
83       aligned_dst = (long*)dst;
84       aligned_src = (long*)src;
85 
86       /* SRC and DEST are both "long int" aligned, try to do "long int"
87          sized copies.  */
88       while (!DETECTNULL(*aligned_src))
89         {
90           *aligned_dst++ = *aligned_src++;
91         }
92 
93       dst = (char*)aligned_dst;
94       src = (char*)aligned_src;
95     }
96 
97   while ((*dst++ = *src++))
98     ;
99   return dst0;
100 #endif /* not PREFER_SIZE_OVER_SPEED */
101 }
102