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

#define hidden __attribute__((visibility("hidden")))
#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))

hidden
size_t __strscpy(char *restrict d, const char *restrict s, size_t n)
{
	const char *const d0 = d;
	size_t aliases *wd;
	const size_t aliases *ws;

	if (!n--) return 0;

	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 ((uintptr_t)s & sizeof(size_t) - 1) return d - d0;

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

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

	*d = 0;

	return d - d0;
}
debug log:

solving c2e25b7c ...
found c2e25b7c in https://inbox.vuxu.org/musl/20170715195541.3136-4-nwmcsween@gmail.com/

applying [1/1] https://inbox.vuxu.org/musl/20170715195541.3136-4-nwmcsween@gmail.com/
diff --git a/src/string/strscpy.c b/src/string/strscpy.c
new file mode 100644
index 00000000..c2e25b7c

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

index at:
100644 c2e25b7ca85ecfa93c551d93072403b67565c143	src/string/strscpy.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).