annotate src/strcat.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents 850242ba4a81
children 697ef44129c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1 /* Copyright (C) 1991 Free Software Foundation, Inc.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
2 This file is part of the GNU C Library.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
3
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
4 The GNU C Library is free software; you can redistribute it and/or
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
5 modify it under the terms of the GNU Library General Public License as
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
6 published by the Free Software Foundation; either version 2 of the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
7 License, or (at your option) any later version.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
8
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
9 The GNU C Library is distributed in the hope that it will be useful,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
12 Library General Public License for more details.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
13
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
14 You should have received a copy of the GNU Library General Public
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
15 License along with the GNU C Library; see the file COPYING.LIB. If
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
17 Cambridge, MA 02139, USA. */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
18
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
19 /* Synched up with: Not in FSF. */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
20
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 2
diff changeset
21 # include <config.h>
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 2
diff changeset
22 # ifndef REGISTER /* Strictly enforced in 20.3 */
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 2
diff changeset
23 # define REGISTER
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 2
diff changeset
24 # endif
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 2
diff changeset
25
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
26 /* In HPUX 10 the strcat function references memory past the last byte of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
27 the string! This will core dump if the memory following the last byte is
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
28 not mapped.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
29
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 203
diff changeset
30 Here is a correct version from, glibc 1.09.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
31 */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
32
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
33 char *strcat (char *dest, const char *src);
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
34
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
35 /* Append SRC on the end of DEST. */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
36 char *
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
37 strcat (char *dest, const char *src)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
38 {
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 2
diff changeset
39 REGISTER char *s1 = dest;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 203
diff changeset
40 REGISTER const char *s2 = src;
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
41 char c;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
42
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
43 /* Find the end of the string. */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
44 do
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
45 c = *s1++;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
46 while (c != '\0');
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
47
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
48 /* Make S1 point before the next character, so we can increment
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
49 it while memory is read (wins on pipelined cpus). */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
50 s1 -= 2;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
51
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
52 do
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
53 {
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
54 c = *s2++;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
55 *++s1 = c;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
56 }
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
57 while (c != '\0');
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
58
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
59 return dest;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
60 }