mailing list of musl libc
 help / color / mirror / code / Atom feed
e1a9454aac93b4ce355006aa359d9b60e007b8ee blob 1534 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 
#include <strings.h>
#include <ctype.h>
#include <stdint.h>

#define aliases __attribute__((__may_alias__))
#define byte_repeat(x) ((size_t)~0 / 0xff * (x))
#define word_has_zero(x) (((x) - byte_repeat(0x01)) & ~(x) & byte_repeat(0x80))
#define word_tag_range(x, t, s, e) ((((x) | byte_repeat(t)) \
- byte_repeat(s) & ~((x) | byte_repeat(t)) - \
byte_repeat((e) + 1)) & (~(x) & byte_repeat(t)))
#define word_to_tolower(x) ((x) - (word_tag_range((x), 'a', 'z', 0x80)) >> 2)
#define weak_alias(o, n) extern __typeof__(o) n __attribute__((weak, alias(#o)))

int strncasecmp(const char *_l, const char *_r, size_t n)
{
	const unsigned char *l = (const void *)_l, *r = (const void *)_r;
	const size_t aliases *wl, aliases *wr;

	if (!n--) return 0;

	if (n < sizeof(size_t) * 3 || ((uintptr_t)l | (uintptr_t)r)
	    & sizeof(size_t) - 1) goto bytewise;

	for (;(uintptr_t)l & sizeof(size_t) - 1 && *l
	     && tolower(*l) == tolower(*r); l++, r++, n--);
	if ((uintptr_t)l & sizeof(size_t) - 1) return tolower(*l) - tolower(*r);

	wl = (const void *)l;
	wr = (const void *)r;
	for (; n >= sizeof(size_t) && !word_has_zero(*wl)
	       && word_to_tolower(*wl) == word_to_tolower(*wr)
	     ; wl++, wr++, n -= sizeof(size_t));
	l = (const void *)wl;
	r = (const void *)wr;

bytewise:
	for (; n && *l && tolower(*l) == tolower(*r); l++, r++, n--);

	return tolower(*l) - tolower(*r);
}

int __strncasecmp_l(const char *l, const char *r, size_t n, locale_t unused)
{
	return strncasecmp(l, r, n);
}

weak_alias(__strncasecmp_l, strncasecmp_l);
debug log:

solving e1a9454a ...
found e1a9454a in https://inbox.vuxu.org/musl/20170715195541.3136-2-nwmcsween@gmail.com/
found 3af53008 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 3af5300878a45c2ef78e1063736be9b4de18fd8f	src/string/strncasecmp.c

applying [1/1] https://inbox.vuxu.org/musl/20170715195541.3136-2-nwmcsween@gmail.com/
diff --git a/src/string/strncasecmp.c b/src/string/strncasecmp.c
index 3af53008..e1a9454a 100644

Checking patch src/string/strncasecmp.c...
Applied patch src/string/strncasecmp.c cleanly.

index at:
100644 e1a9454aac93b4ce355006aa359d9b60e007b8ee	src/string/strncasecmp.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).