summaryrefslogtreecommitdiff
path: root/wcsmbs/wcsncat.c
diff options
context:
space:
mode:
Diffstat (limited to 'wcsmbs/wcsncat.c')
-rw-r--r--wcsmbs/wcsncat.c57
1 files changed, 9 insertions, 48 deletions
diff --git a/wcsmbs/wcsncat.c b/wcsmbs/wcsncat.c
index 8d4013b53d..94d7347175 100644
--- a/wcsmbs/wcsncat.c
+++ b/wcsmbs/wcsncat.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995-2018 Free Software Foundation, Inc.
+/* Copyright (C) 1995-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
@@ -14,7 +14,7 @@
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
+ <https://www.gnu.org/licenses/>. */
#include <wchar.h>
@@ -26,54 +26,15 @@
wchar_t *
WCSNCAT (wchar_t *dest, const wchar_t *src, size_t n)
{
- wchar_t c;
- wchar_t * const s = dest;
+ wchar_t *ret = dest;
- /* Find the end of DEST. */
- do
- c = *dest++;
- while (c != L'\0');
+ /* Find the end of dest. */
+ dest += __wcslen (dest);
- /* Make DEST point before next character, so we can increment
- it while memory is read (wins on pipelined cpus). */
- dest -= 2;
+ size_t ds = __wcsnlen (src, n);
- if (n >= 4)
- {
- size_t n4 = n >> 2;
- do
- {
- c = *src++;
- *++dest = c;
- if (c == L'\0')
- return s;
- c = *src++;
- *++dest = c;
- if (c == L'\0')
- return s;
- c = *src++;
- *++dest = c;
- if (c == L'\0')
- return s;
- c = *src++;
- *++dest = c;
- if (c == L'\0')
- return s;
- } while (--n4 > 0);
- n &= 3;
- }
+ dest[ds] = L'\0';
+ __wmemcpy (dest, src, ds);
- while (n > 0)
- {
- c = *src++;
- *++dest = c;
- if (c == L'\0')
- return s;
- n--;
- }
-
- if (c != L'\0')
- *++dest = L'\0';
-
- return s;
+ return ret;
}