blob: 2da61771c61e4a5516026735237a200994f55018 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*
2 * Copyright (C) 2002 Manuel Novoa III
3 * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
4 *
5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6 */
7
8#include "_string.h"
9
10#ifdef WANT_WIDE
11# define Wstrncmp wcsncmp
12#else
13# define Wstrncmp strncmp
14#endif
15
16int Wstrncmp(register const Wchar *s1, register const Wchar *s2, size_t n)
17{
18#ifdef WANT_WIDE
19 while (n && (*((Wuchar *)s1) == *((Wuchar *)s2))) {
20 if (!*s1++) {
21 return 0;
22 }
23 ++s2;
24 --n;
25 }
26
27 return (n == 0) ? 0 : (*((Wuchar *)s1) - *((Wuchar *)s2));
28#else
29 int r = 0;
30
31 while (n--
32 && ((r = ((int)(*((unsigned char *)s1))) - *((unsigned char *)s2++))
33 == 0)
34 && *s1++);
35
36 return r;
37#endif
38}
39#ifndef WANT_WIDE
40libc_hidden_weak(strncmp)
41#endif