mailing list of musl libc
 help / color / mirror / code / Atom feed
f11c0573fb837d1d0a5060a7503ccd84f4f20e1b blob 699 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
 
#include <string.h>
#include <stdint.h>
#include <limits.h>

#define SS (sizeof(size_t))
#define ALIGN (sizeof(size_t)-1)
#define ONES ((size_t)-1/UCHAR_MAX)
#define HIGHS (ONES * (UCHAR_MAX/2+1))
#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)

void *(memchr)(const void *src, int c, size_t n)
{
	const unsigned char *s = src;
	c = (unsigned char)c;
#ifdef __GNUC__
	for (; ((uintptr_t)s & ALIGN) && n && *s != c; s++, n--);
	if (n && *s != c) {
		typedef size_t __attribute__((__may_alias__)) word;
		const word *w;
		size_t k = ONES * c;
		for (w = (const void *)s; n>=SS && !HASZERO(*w^k); w++, n-=SS);
		s = (const void *)w;
	}
#endif
	for (; n && *s != c; s++, n--);
	return n ? (void *)s : 0;
}
debug log:

solving f11c0573 ...
found f11c0573 in https://inbox.vuxu.org/musl/c166b0a43bfeb6f50b341d752ba0230d42eb08ab.1684932942.git.Jens.Gustedt@inria.fr/ ||
	https://inbox.vuxu.org/musl/a6fc4ae313c0362fadb2db179d781da850995c21.1685541439.git.Jens.Gustedt@inria.fr/
found 65f0d789 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 65f0d789b2c9a4e2bf8fbd89e9cbc704dd7a538f	src/string/memchr.c

applying [1/2] https://inbox.vuxu.org/musl/c166b0a43bfeb6f50b341d752ba0230d42eb08ab.1684932942.git.Jens.Gustedt@inria.fr/
diff --git a/src/string/memchr.c b/src/string/memchr.c
index 65f0d789..f11c0573 100644

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

skipping https://inbox.vuxu.org/musl/a6fc4ae313c0362fadb2db179d781da850995c21.1685541439.git.Jens.Gustedt@inria.fr/ for f11c0573
index at:
100644 f11c0573fb837d1d0a5060a7503ccd84f4f20e1b	src/string/memchr.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).