mailing list of musl libc
 help / color / mirror / code / Atom feed
0b37da5dfeabf5ac465a68be760262ecfee7bb39 blob 910 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
 
#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))
#define weak_alias(o, n) extern __typeof__(o) n __attribute__((weak, alias(#o)))

char *__stpncpy(char *restrict d, const char *restrict s, size_t n)
{
	size_t *wd;
	const size_t *ws;

	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) && (*d = *s); d++, s++, n--);
	if (!*s) return memset(d, 0, n);

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

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

	return memset(d, 0, n);
}

weak_alias(__stpncpy, stpncpy);
debug log:

solving 0b37da5d ...
found 0b37da5d in https://inbox.vuxu.org/musl/20170715195541.3136-3-nwmcsween@gmail.com/
found 1f57a4dd in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 1f57a4ddbd0a818168e56c0b15178e93304c42cf	src/string/stpncpy.c

applying [1/1] https://inbox.vuxu.org/musl/20170715195541.3136-3-nwmcsween@gmail.com/
diff --git a/src/string/stpncpy.c b/src/string/stpncpy.c
index 1f57a4dd..0b37da5d 100644

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

index at:
100644 0b37da5dfeabf5ac465a68be760262ecfee7bb39	src/string/stpncpy.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).