annotate src/strcpy.c @ 3263:d674024a8674

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