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

#define HIGHS(x) ((x) - ((x)*0-1) / 255 * 128)
#define LOWS(x) (((x)*0-1) / 255)
#define has_char(x, c) ((x) - LOWS(x) & ~(x) & HIGHS(x) ^ LOWS(x) * (c))

void *memccpy(void *restrict d, const void *restrict s, int c, size_t n)
{
	unsigned char *cd = (unsigned char *)d;
	const unsigned char *cs = (const unsigned char *)s;
	size_t *wd;
	const size_t *ws;

	c = (unsigned char)c;

	if ((uintptr_t)s % sizeof(size_t) != (uintptr_t)d % sizeof(size_t)
	    || n < sizeof(size_t))
		goto bytewise;

	for (; (uintptr_t)s % sizeof(size_t); *cd = *cs, cd++, cs++)
		if (*cs == c) return cd + 1;

	for (wd = (size_t *)d, ws = (const size_t *)s
	     ; !has_char(*ws, c) && n >= sizeof(size_t)
	     ; ws++, wd++, *wd = *ws);

	cd = (unsigned char *)wd;
	cs = (const unsigned char *)ws;

bytewise:
	for (; *cs != c; *cd = *cs, cs++, cd++, n--)
		if (!n) return NULL;

	return cd + 1;
}
debug log:

solving f032030 ...
found f032030 in https://inbox.vuxu.org/musl/1365280696-16525-2-git-send-email-nwmcsween@gmail.com/
found b85009c in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 b85009c8706e9bb050dd3340a3ff385fb215165d	src/string/memccpy.c

applying [1/1] https://inbox.vuxu.org/musl/1365280696-16525-2-git-send-email-nwmcsween@gmail.com/
diff --git a/src/string/memccpy.c b/src/string/memccpy.c
index b85009c..f032030 100644

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

index at:
100644 f03203044acb0466b5478d9dcced51c5cf72e60f	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).