]>
Commit | Line | Data |
---|---|---|
c84142e8 UD |
1 | /* Copyright (C) 1991, 1997 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. | |
28f540f4 | 3 | |
c84142e8 | 4 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
5 | modify it under the terms of the GNU Lesser General Public |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
28f540f4 | 8 | |
c84142e8 UD |
9 | The GNU C Library 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 GNU | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
28f540f4 | 13 | |
41bdb6e2 AJ |
14 | You should have received a copy of the GNU Lesser General Public |
15 | License along with the GNU C Library; if not, write to the Free | |
16 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
17 | 02111-1307 USA. */ | |
28f540f4 | 18 | |
28f540f4 | 19 | #include <string.h> |
c84142e8 UD |
20 | |
21 | #ifdef _LIBC | |
22 | # include <memcopy.h> | |
23 | #else | |
24 | typedef char reg_char; | |
25 | #endif | |
28f540f4 | 26 | |
9a0a462c UD |
27 | #undef strncat |
28 | ||
28f540f4 | 29 | char * |
c84142e8 UD |
30 | strncat (s1, s2, n) |
31 | char *s1; | |
32 | const char *s2; | |
33 | size_t n; | |
28f540f4 RM |
34 | { |
35 | reg_char c; | |
36 | char *s = s1; | |
37 | ||
38 | /* Find the end of S1. */ | |
39 | do | |
40 | c = *s1++; | |
41 | while (c != '\0'); | |
42 | ||
43 | /* Make S1 point before next character, so we can increment | |
44 | it while memory is read (wins on pipelined cpus). */ | |
45 | s1 -= 2; | |
46 | ||
47 | if (n >= 4) | |
48 | { | |
49 | size_t n4 = n >> 2; | |
50 | do | |
51 | { | |
52 | c = *s2++; | |
53 | *++s1 = c; | |
54 | if (c == '\0') | |
55 | return s; | |
56 | c = *s2++; | |
57 | *++s1 = c; | |
58 | if (c == '\0') | |
59 | return s; | |
60 | c = *s2++; | |
61 | *++s1 = c; | |
62 | if (c == '\0') | |
63 | return s; | |
64 | c = *s2++; | |
65 | *++s1 = c; | |
66 | if (c == '\0') | |
67 | return s; | |
68 | } while (--n4 > 0); | |
69 | n &= 3; | |
70 | } | |
71 | ||
72 | while (n > 0) | |
73 | { | |
74 | c = *s2++; | |
75 | *++s1 = c; | |
76 | if (c == '\0') | |
77 | return s; | |
78 | n--; | |
79 | } | |
80 | ||
81 | if (c != '\0') | |
82 | *++s1 = '\0'; | |
83 | ||
84 | return s; | |
85 | } |