mailing list of musl libc
 help / color / mirror / code / Atom feed
0c73fa10655309b6fc7cd7f4954b744ccf34a5f3 blob 1646 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 
#include <stdlib.h>
#include <wchar.h>
#include <uchar.h>
#include <errno.h>
#include "internal.h"

__attribute__((__noinline__))
static size_t mbrtoc8_slow(unsigned char *__restrict pc8, const char *__restrict src, size_t n, mbstate_t *__restrict st)
{
	static unsigned internal_state;
	wchar_t wc;
	unsigned* pending = st ? (void*)st : &internal_state;

	// The high bit is set if there is still missing input. If it
	// is not set and the value is not zero, a previous call has
	// stacked the missing output bytes withing the state.
	if ((-*pending) > INT_MIN) {
		if (pc8) *pc8 = *pending;
		(*pending) >>= 8;
		return -3;
	}

	// mbrtowc has return values -2, -1, 0, 1, ..., 4.
	size_t res = mbrtowc(&wc, src, n, (void*)pending);
	if (res <= 4) {
		_Alignas(unsigned) unsigned char s[8] = { 0 };
		// Write the result bytes to s over the word boundary
		// as we need it. Our wcrtomb implementation ignores
		// the state variable, there will be no errors and the
		// return value can be ignored.
		wcrtomb((void*)(s+3), wc, 0);
		// Depending on the endianess this maybe a single load
		// instruction. We want to be sure that the bytes are
		// in this order, and that the high-order byte is 0.
		*pending = (0u|s[4])<<000 | (0u|s[5])<<010 | (0u|s[6])<<020 | (0u|s[7])<<030;
		if (pc8) *pc8 = s[3];
	}
	return res;
}

static size_t __mbrtoc8(unsigned char *__restrict pc8, const char *__restrict src, size_t n, mbstate_t *__restrict st)
{
	unsigned char *s = (void*)src;
	if (st && !*(unsigned*)st && (s[0] < 0x80u)) {
		if (pc8) *pc8 = s[0];
		return s[0]>0;
	}
	return mbrtoc8_slow(pc8, src, n, st);
}

weak_alias(__mbrtoc8, mbrtoc8);
debug log:

solving 0c73fa10 ...
found 0c73fa10 in https://inbox.vuxu.org/musl/976b592b08c82bd6b1f8834904071db6602f3885.1685534402.git.Jens.Gustedt@inria.fr/ ||
	https://inbox.vuxu.org/musl/a4faa3c9cef8b48d685f059ab8425ec3fd5087db.1684932960.git.Jens.Gustedt@inria.fr/

applying [1/2] https://inbox.vuxu.org/musl/976b592b08c82bd6b1f8834904071db6602f3885.1685534402.git.Jens.Gustedt@inria.fr/
diff --git a/src/multibyte/mbrtoc8.c b/src/multibyte/mbrtoc8.c
new file mode 100644
index 00000000..0c73fa10

Checking patch src/multibyte/mbrtoc8.c...
Applied patch src/multibyte/mbrtoc8.c cleanly.

skipping https://inbox.vuxu.org/musl/a4faa3c9cef8b48d685f059ab8425ec3fd5087db.1684932960.git.Jens.Gustedt@inria.fr/ for 0c73fa10
index at:
100644 0c73fa10655309b6fc7cd7f4954b744ccf34a5f3	src/multibyte/mbrtoc8.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).