annotate src/strcpy.c @ 203:850242ba4a81 r20-3b28

Import from CVS: tag r20-3b28
author cvs
date Mon, 13 Aug 2007 10:02:21 +0200
parents 376386a54a3c
children 74fd4e045ea6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 /* In SunOS 4.1.1 the strcpy function references memory past the last byte of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 the string! This will core dump if the memory following the last byte is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 not mapped.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 Here are correct versions by hbs@lucid.com.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 0
diff changeset
27 # include <config.h>
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 0
diff changeset
28 # ifndef REGISTER /* Strictly enforced in 20.3 */
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 0
diff changeset
29 # define REGISTER
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 0
diff changeset
30 # endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #define ALIGNED(x) (!(((unsigned long) (x)) & (sizeof (unsigned long) - 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #define MAGIC 0x7efefeff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #define HIGH_BIT_P(c) ((c) & hi_bit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #define HAS_ZERO(c) (((((c) + magic) ^ (c)) & not_magic) != not_magic)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 0
diff changeset
38 /* CONST IS LOSING, but const is part of the interface of strcpy */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 strcpy (char *to, const char *from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 char *return_value = to;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 if (to == from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 return to;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 else if (ALIGNED (to) && ALIGNED (from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 unsigned long *to1 = (unsigned long *) to;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 const unsigned long *from1 = (const unsigned long *) from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 unsigned long c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 unsigned long magic = MAGIC;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 unsigned long not_magic = ~magic;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 /* unsigned long hi_bit = 0x80000000; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 while ((c = *from1) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 if (HAS_ZERO(c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 to = (char *) to1;
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 0
diff changeset
59 from = (CONST char *) from1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 goto slow_loop;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 *to1 = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 to1++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 from1++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 to = (char *) to1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 *to = (char) 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 return return_value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 char c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 slow_loop:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 while ((c = *from) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 *to = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 to++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 *to = (char) 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 return return_value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 }