mailing list of musl libc
 help / color / mirror / code / Atom feed
068f6a2db77cfab0240a7ad717b87356d7fe4fad blob 946 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
 
#include <string.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))

void *memccpy(void *restrict _d, const void *restrict _s, int i, size_t n)
{
	i = (unsigned char)i;
	unsigned char *d = _d;
	const unsigned char *s = _s;
	size_t aliases *wd;
	const size_t aliases *ws, wi = byte_repeat(i);

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

	for (; (uintptr_t)s & sizeof(size_t) - 1 && *s != i
	     ; d++, s++, n--) *d = *s;
	if ((uintptr_t)s & sizeof(size_t) - 1) return d + 1;

	wd = (void *)d;
	ws = (const void *)s;
	for (;  n >= sizeof(size_t) && !word_has_zero(*ws ^ wi)
	     ; *wd++ = *ws++, n -= sizeof(size_t));
	d = (void *)wd;
	s = (const void *)ws;

bytewise:
	for (; n && *d != i; *d++ = *s++, n--);

	return n ? d + 1 : 0;
}
debug log:

solving 068f6a2d ...
found 068f6a2d in https://inbox.vuxu.org/musl/20170715195541.3136-3-nwmcsween@gmail.com/
found 7c233d5e in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 7c233d5e90571f20ed06819575343657495b8246	src/string/memccpy.c

applying [1/1] https://inbox.vuxu.org/musl/20170715195541.3136-3-nwmcsween@gmail.com/
diff --git a/src/string/memccpy.c b/src/string/memccpy.c
index 7c233d5e..068f6a2d 100644

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

index at:
100644 068f6a2db77cfab0240a7ad717b87356d7fe4fad	src/string/memccpy.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).