annotate src/strcat.c @ 8:4b173ad71786 r19-15b5

Import from CVS: tag r19-15b5
author cvs
date Mon, 13 Aug 2007 08:47:35 +0200
parents ac2d302a0011
children 850242ba4a81
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
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
21 /* In HPUX 10 the strcat function references memory past the last byte of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
22 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
23 not mapped.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
24
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
25 Here is a correct version from glibc 1.09.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
26 */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
27
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
28 char *strcat (char *dest, const char *src);
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
29
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
30 /* Append SRC on the end of DEST. */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
31 char *
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
32 strcat (char *dest, const char *src)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
33 {
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
34 register char *s1 = dest;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
35 register const char *s2 = src;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
36 char c;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
37
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
38 /* Find the end of the string. */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
39 do
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
40 c = *s1++;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
41 while (c != '\0');
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
42
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
43 /* Make S1 point before the next character, so we can increment
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
44 it while memory is read (wins on pipelined cpus). */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
45 s1 -= 2;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
46
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
47 do
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
48 {
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
49 c = *s2++;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
50 *++s1 = c;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
51 }
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
52 while (c != '\0');
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
53
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
54 return dest;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
55 }