annotate src/strcat.c @ 388:aabb7f5b1c81 r21-2-9

Import from CVS: tag r21-2-9
author cvs
date Mon, 13 Aug 2007 11:09:42 +0200
parents 850242ba4a81
children 74fd4e045ea6
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
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
30 Here is a correct version from glibc 1.09.
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. */
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 2
diff changeset
36 /* CONST IS LOSING, but const is part of the interface of strcat */
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
37 char *
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
38 strcat (char *dest, const char *src)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
39 {
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 2
diff changeset
40 REGISTER char *s1 = dest;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 2
diff changeset
41 REGISTER CONST char *s2 = src;
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
42 char c;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
43
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
44 /* Find the end of the string. */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
45 do
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
46 c = *s1++;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
47 while (c != '\0');
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
48
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
49 /* Make S1 point before the next character, so we can increment
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
50 it while memory is read (wins on pipelined cpus). */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
51 s1 -= 2;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
52
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
53 do
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
54 {
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
55 c = *s2++;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
56 *++s1 = c;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
57 }
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
58 while (c != '\0');
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
59
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
60 return dest;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
61 }