Merge remote-tracking branch 'origin/master' into for-steve
[sxemacs] / src / strcat.c
1 /* Copyright (C) 1991 Free Software Foundation, Inc.
2 This file is part of SXEmacs
3
4 SXEmacs is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 SXEmacs is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17
18 /* Synched up with: Not in FSF. */
19
20 # include <config.h>
21 # ifndef REGISTER               /* Strictly enforced in 20.3 */
22 # define REGISTER
23 # endif
24
25 /* In HPUX 10 the strcat function references memory past the last byte of
26    the string!  This will core dump if the memory following the last byte is
27    not mapped.
28
29    Here is a correct version from, glibc 1.09.
30 */
31
32 char *strcat(char *dest, const char *src);
33
34 /* Append SRC on the end of DEST.  */
35 char *strcat(char *dest, const char *src)
36 {
37         REGISTER char *s1 = dest;
38         REGISTER const char *s2 = src;
39         char c;
40
41         /* Find the end of the string.  */
42         do
43                 c = *s1++;
44         while (c != '\0');
45
46         /* Make S1 point before the next character, so we can increment
47            it while memory is read (wins on pipelined cpus).  */
48         s1 -= 2;
49
50         do {
51                 c = *s2++;
52                 *++s1 = c;
53         }
54         while (c != '\0');
55
56         return dest;
57 }