annotate src/strcpy.c @ 24:4103f0995bd7 r19-15b95

Import from CVS: tag r19-15b95
author cvs
date Mon, 13 Aug 2007 08:51:03 +0200
parents 376386a54a3c
children 850242ba4a81
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #define ALIGNED(x) (!(((unsigned long) (x)) & (sizeof (unsigned long) - 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #define MAGIC 0x7efefeff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #define HIGH_BIT_P(c) ((c) & hi_bit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #define HAS_ZERO(c) (((((c) + magic) ^ (c)) & not_magic) != not_magic)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 strcpy (char *to, const char *from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 char *return_value = to;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 if (to == from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 return to;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 else if (ALIGNED (to) && ALIGNED (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 unsigned long *to1 = (unsigned long *) to;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 const unsigned long *from1 = (const unsigned long *) from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 unsigned long c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 unsigned long magic = MAGIC;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 unsigned long not_magic = ~magic;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 /* unsigned long hi_bit = 0x80000000; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 while ((c = *from1) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 if (HAS_ZERO(c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 to = (char *) to1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 from = (const char *) from1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 goto slow_loop;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 *to1 = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 to1++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 from1++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 to = (char *) to1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 *to = (char) 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 return return_value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 char c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 slow_loop:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 while ((c = *from) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 *to = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 to++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 *to = (char) 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 return return_value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 }