* signal/signal.h [__USE_BSD] (_sys_siglist, sys_siglist): Declare
[glibc.git] / sysdeps / generic / strncat.c
blob09463b36b845d1eb53650171219134810ae7b309
1 /* Copyright (C) 1991 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
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
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
19 #include <ansidecl.h>
20 #include <string.h>
21 #include <memcopy.h>
23 char *
24 DEFUN(strncat, (s1, s2, n), char *s1 AND CONST char *s2 AND size_t n)
26 reg_char c;
27 char *s = s1;
29 /* Find the end of S1. */
31 c = *s1++;
32 while (c != '\0');
34 /* Make S1 point before next character, so we can increment
35 it while memory is read (wins on pipelined cpus). */
36 s1 -= 2;
38 if (n >= 4)
40 size_t n4 = n >> 2;
43 c = *s2++;
44 *++s1 = c;
45 if (c == '\0')
46 return s;
47 c = *s2++;
48 *++s1 = c;
49 if (c == '\0')
50 return s;
51 c = *s2++;
52 *++s1 = c;
53 if (c == '\0')
54 return s;
55 c = *s2++;
56 *++s1 = c;
57 if (c == '\0')
58 return s;
59 } while (--n4 > 0);
60 n &= 3;
63 while (n > 0)
65 c = *s2++;
66 *++s1 = c;
67 if (c == '\0')
68 return s;
69 n--;
72 if (c != '\0')
73 *++s1 = '\0';
75 return s;