* hurd/hurdsig.c (write_corefile): Fix typo.
[glibc/history.git] / wcsmbs / wcsncpy.c
blobffa791a89901a613070683b76ed9c38265e929d7
1 /* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
20 #include <wchar.h>
23 /* Copy no more than N wide-characters of SRC to DEST. */
24 wchar_t *
25 wcsncpy (dest, src, n)
26 wchar_t *dest;
27 const wchar_t *src;
28 size_t n;
30 wint_t c;
31 wchar_t *const s = dest;
33 --dest;
35 if (n >= 4)
37 size_t n4 = n >> 2;
39 for (;;)
41 c = *src++;
42 *++dest = c;
43 if (c == L'\0')
44 break;
45 c = *src++;
46 *++dest = c;
47 if (c == L'\0')
48 break;
49 c = *src++;
50 *++dest = c;
51 if (c == L'\0')
52 break;
53 c = *src++;
54 *++dest = c;
55 if (c == L'\0')
56 break;
57 if (--n4 == 0)
58 goto last_chars;
60 n = n - (dest - s) - 1;
61 if (n == 0)
62 return s;
63 goto zero_fill;
66 last_chars:
67 n &= 3;
68 if (n == 0)
69 return s;
73 c = *src++;
74 *++dest = c;
75 if (--n == 0)
76 return s;
78 while (c != L'\0');
80 zero_fill:
82 *++dest = L'\0';
83 while (--n > 0);
85 return s;