mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-02 17:28:30 +00:00
Update Musl Libc code
We now have implement all of Musl's localization code, the same way that Musl implements localization. You may need setlocale(LC_ALL, "C.UTF-8"), just in case anything stops working as expected.
This commit is contained in:
parent
d0360bf4bd
commit
bb815eafaf
116 changed files with 6525 additions and 5523 deletions
|
@ -104,6 +104,8 @@ static bool IsMyDebugBinary(const char *path) {
|
|||
|
||||
static void FindDebugBinaryInit(void) {
|
||||
const char *comdbg;
|
||||
if (issetugid())
|
||||
return;
|
||||
if ((comdbg = getenv("COMDBG")) && IsMyDebugBinary(comdbg)) {
|
||||
g_comdbg.res = comdbg;
|
||||
return;
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#ifndef _LANGINFO_H
|
||||
#define _LANGINFO_H
|
||||
#include "libc/str/langinfo.h"
|
||||
#include "libc/str/locale.h"
|
||||
#include "libc/str/nltypes.h"
|
||||
#endif /* _LANGINFO_H */
|
||||
|
|
|
@ -40,7 +40,7 @@ void GetAddr2linePathInit(void) {
|
|||
char *res;
|
||||
int e = errno;
|
||||
const char *env, *cmd, *path;
|
||||
if ((env = getenv("ADDR2LINE"))) {
|
||||
if ((env = secure_getenv("ADDR2LINE"))) {
|
||||
cmd = env;
|
||||
path = env;
|
||||
} else {
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "libc/runtime/syslib.internal.h"
|
||||
#include "libc/stdalign.internal.h"
|
||||
#include "libc/str/locale.h"
|
||||
#include "libc/str/locale.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
|
@ -213,7 +214,6 @@ textstartup void __enable_tls(void) {
|
|||
tib->tib_errno = __errno;
|
||||
tib->tib_strace = __strace;
|
||||
tib->tib_ftrace = __ftrace;
|
||||
tib->tib_locale = (intptr_t)&__c_dot_utf8_locale;
|
||||
tib->tib_pthread = (pthread_t)&_pthread_static;
|
||||
if (IsWindows()) {
|
||||
intptr_t hThread;
|
||||
|
@ -246,6 +246,7 @@ textstartup void __enable_tls(void) {
|
|||
// initialize posix threads
|
||||
_pthread_static.tib = tib;
|
||||
_pthread_static.pt_flags = PT_STATIC;
|
||||
_pthread_static.pt_locale = &__global_locale;
|
||||
dll_init(&_pthread_static.list);
|
||||
_pthread_list = &_pthread_static.list;
|
||||
atomic_store_explicit(&_pthread_static.ptid, tid, memory_order_release);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/getenv.h"
|
||||
#include "libc/intrin/safemacros.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
|
@ -27,8 +28,9 @@
|
|||
*/
|
||||
textstartup int __strace_init(int argc, char **argv, char **envp, long *auxv) {
|
||||
/* asan isn't initialized yet at runlevel 300 */
|
||||
if (__intercept_flag(&argc, argv, "--strace") ||
|
||||
__atoul(nulltoempty(__getenv(envp, "STRACE").s))) {
|
||||
if ((__intercept_flag(&argc, argv, "--strace") ||
|
||||
__atoul(nulltoempty(__getenv(envp, "STRACE").s))) &&
|
||||
!issetugid()) {
|
||||
strace_enabled(+1);
|
||||
}
|
||||
return (__argc = argc);
|
||||
|
|
|
@ -112,7 +112,7 @@ static void __zipos_init(void) {
|
|||
const char *progpath;
|
||||
if (!(s = getenv("COSMOPOLITAN_DISABLE_ZIPOS"))) {
|
||||
// this environment variable may be a filename or file descriptor
|
||||
if ((progpath = getenv("COSMOPOLITAN_INIT_ZIPOS")) &&
|
||||
if ((progpath = secure_getenv("COSMOPOLITAN_INIT_ZIPOS")) &&
|
||||
(x = strtol(progpath, &endptr, 10)) >= 0 && !*endptr) {
|
||||
fd = x;
|
||||
} else {
|
||||
|
|
|
@ -32,7 +32,6 @@ LIBC_SOCK_A_DIRECTDEPS = \
|
|||
LIBC_NEXGEN32E \
|
||||
LIBC_NT_ADVAPI32 \
|
||||
LIBC_NT_IPHLPAPI \
|
||||
LIBC_NT_IPHLPAPI \
|
||||
LIBC_NT_KERNEL32 \
|
||||
LIBC_NT_NTDLL \
|
||||
LIBC_NT_WS2_32 \
|
||||
|
|
|
@ -1,727 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/iconv.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/locale.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/thread/tls.h"
|
||||
// clang-format off
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
|
||||
#define UTF_32BE 0300
|
||||
#define UTF_16LE 0301
|
||||
#define UTF_16BE 0302
|
||||
#define UTF_32LE 0303
|
||||
#define UCS2BE 0304
|
||||
#define UCS2LE 0305
|
||||
#define WCHAR_T 0306
|
||||
#define US_ASCII 0307
|
||||
#define UTF_8 0310
|
||||
#define UTF_16 0312
|
||||
#define UTF_32 0313
|
||||
#define UCS2 0314
|
||||
#define EUC_JP 0320
|
||||
#define SHIFT_JIS 0321
|
||||
#define ISO2022_JP 0322
|
||||
#define GB18030 0330
|
||||
#define GBK 0331
|
||||
#define GB2312 0332
|
||||
#define BIG5 0340
|
||||
#define EUC_KR 0350
|
||||
|
||||
/* Definitions of charmaps. Each charmap consists of:
|
||||
* 1. Empty-string-terminated list of null-terminated aliases.
|
||||
* 2. Special type code or number of elided quads of entries.
|
||||
* 3. Character table (size determined by field 2), consisting
|
||||
* of 5 bytes for every 4 characters, interpreted as 10-bit
|
||||
* indices into the legacy_chars table. */
|
||||
|
||||
static const unsigned char charmaps[] =
|
||||
"utf8\0char\0\0\310"
|
||||
"wchart\0\0\306"
|
||||
"ucs2be\0\0\304"
|
||||
"ucs2le\0\0\305"
|
||||
"utf16be\0\0\302"
|
||||
"utf16le\0\0\301"
|
||||
"ucs4be\0utf32be\0\0\300"
|
||||
"ucs4le\0utf32le\0\0\303"
|
||||
"ascii\0usascii\0iso646\0iso646us\0\0\307"
|
||||
"utf16\0\0\312"
|
||||
"ucs4\0utf32\0\0\313"
|
||||
"ucs2\0\0\314"
|
||||
"eucjp\0\0\320"
|
||||
"shiftjis\0sjis\0\0\321"
|
||||
"iso2022jp\0\0\322"
|
||||
"gb18030\0\0\330"
|
||||
"gbk\0\0\331"
|
||||
"gb2312\0\0\332"
|
||||
"big5\0bigfive\0cp950\0big5hkscs\0\0\340"
|
||||
"euckr\0ksc5601\0ksx1001\0cp949\0\0\350"
|
||||
#include "libc/stdio/codepages.inc"
|
||||
;
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wmissing-braces"
|
||||
|
||||
/* Table of characters that appear in legacy 8-bit codepages,
|
||||
* limited to 1024 slots (10 bit indices). The first 256 entries
|
||||
* are elided since those characters are obviously all included. */
|
||||
static const unsigned short legacy_chars[] = {
|
||||
#include "libc/stdio/legacychars.inc"
|
||||
};
|
||||
|
||||
static const unsigned short jis0208[84][94] = {
|
||||
#include "libc/stdio/jis0208.inc"
|
||||
};
|
||||
|
||||
static const unsigned short gb18030[126][190] = {
|
||||
#include "libc/stdio/gb18030.inc"
|
||||
};
|
||||
|
||||
static const unsigned short big5[89][157] = {
|
||||
#include "libc/stdio/big5.inc"
|
||||
};
|
||||
|
||||
static const unsigned short hkscs[] = {
|
||||
#include "libc/stdio/hkscs.inc"
|
||||
};
|
||||
|
||||
static const unsigned short ksc[93][94] = {
|
||||
#include "libc/stdio/ksc.inc"
|
||||
};
|
||||
|
||||
static const unsigned short rev_jis[] = {
|
||||
#include "libc/stdio/revjis.inc"
|
||||
};
|
||||
|
||||
static int fuzzycmp(const unsigned char *a, const unsigned char *b)
|
||||
{
|
||||
for (; *a && *b; a++, b++) {
|
||||
while (*a && (*a|32U)-'a'>26 && *a-'0'>10U) a++;
|
||||
if ((*a|32U) != *b) return 1;
|
||||
}
|
||||
return *a != *b;
|
||||
}
|
||||
|
||||
static size_t find_charmap(const void *name)
|
||||
{
|
||||
const unsigned char *s;
|
||||
if (!*(char *)name) name=charmaps; /* "utf8" */
|
||||
for (s=charmaps; *s; ) {
|
||||
if (!fuzzycmp(name, s)) {
|
||||
for (; *s; s+=strlen((void *)s)+1);
|
||||
return s+1-charmaps;
|
||||
}
|
||||
s += strlen((void *)s)+1;
|
||||
if (!*s) {
|
||||
if (s[1] > 0200) s+=2;
|
||||
else s+=2+(64U-s[1])*5;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct stateful_cd {
|
||||
iconv_t base_cd;
|
||||
unsigned state;
|
||||
};
|
||||
|
||||
static iconv_t combine_to_from(size_t t, size_t f)
|
||||
{
|
||||
return (void *)(f<<16 | t<<1 | 1);
|
||||
}
|
||||
|
||||
static size_t extract_from(iconv_t cd)
|
||||
{
|
||||
return (size_t)cd >> 16;
|
||||
}
|
||||
|
||||
static size_t extract_to(iconv_t cd)
|
||||
{
|
||||
return (size_t)cd >> 1 & 0x7fff;
|
||||
}
|
||||
|
||||
iconv_t iconv_open(const char *to, const char *from)
|
||||
{
|
||||
size_t f, t;
|
||||
struct stateful_cd *scd;
|
||||
|
||||
if ((t = find_charmap(to))==-1
|
||||
|| (f = find_charmap(from))==-1
|
||||
|| (charmaps[t] >= 0330)) {
|
||||
errno = EINVAL;
|
||||
return (iconv_t)-1;
|
||||
}
|
||||
iconv_t cd = combine_to_from(t, f);
|
||||
|
||||
switch (charmaps[f]) {
|
||||
case UTF_16:
|
||||
case UTF_32:
|
||||
case UCS2:
|
||||
case ISO2022_JP:
|
||||
scd = malloc(sizeof *scd);
|
||||
if (!scd) return (iconv_t)-1;
|
||||
scd->base_cd = cd;
|
||||
scd->state = 0;
|
||||
cd = (iconv_t)scd;
|
||||
}
|
||||
|
||||
return cd;
|
||||
}
|
||||
|
||||
int iconv_close(iconv_t cd)
|
||||
{
|
||||
if (!((size_t)cd & 1)) free((void *)cd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned get_16(const unsigned char *s, int e)
|
||||
{
|
||||
e &= 1;
|
||||
return s[e]<<8 | s[1-e];
|
||||
}
|
||||
|
||||
static void put_16(unsigned char *s, unsigned c, int e)
|
||||
{
|
||||
e &= 1;
|
||||
s[e] = c>>8;
|
||||
s[1-e] = c;
|
||||
}
|
||||
|
||||
static unsigned get_32(const unsigned char *s, int e)
|
||||
{
|
||||
e &= 3;
|
||||
return (s[e]+0U)<<24 | s[e^1]<<16 | s[e^2]<<8 | s[e^3];
|
||||
}
|
||||
|
||||
static void put_32(unsigned char *s, unsigned c, int e)
|
||||
{
|
||||
e &= 3;
|
||||
s[e^0] = c>>24;
|
||||
s[e^1] = c>>16;
|
||||
s[e^2] = c>>8;
|
||||
s[e^3] = c;
|
||||
}
|
||||
|
||||
/* Adapt as needed */
|
||||
#define mbrtowc_utf8 mbrtowc
|
||||
#define wctomb_utf8 wctomb
|
||||
|
||||
static unsigned legacy_map(const unsigned char *map, unsigned c)
|
||||
{
|
||||
if (c < 4*map[-1]) return c;
|
||||
unsigned x = c - 4*map[-1];
|
||||
x = (map[x*5/4]>>(2*x%8)) | ((map[x*5/4+1]<<(8-(2*x%8))) & 1023);
|
||||
return x < 256 ? x : legacy_chars[x-256];
|
||||
}
|
||||
|
||||
static unsigned uni_to_jis(unsigned c)
|
||||
{
|
||||
unsigned nel = sizeof rev_jis / sizeof *rev_jis;
|
||||
unsigned d, j, i, b = 0;
|
||||
for (;;) {
|
||||
i = nel/2;
|
||||
j = rev_jis[b+i];
|
||||
d = jis0208[j/256][j%256];
|
||||
if (d==c) return j + 0x2121;
|
||||
else if (nel == 1) return 0;
|
||||
else if (c < d)
|
||||
nel /= 2;
|
||||
else {
|
||||
b += i;
|
||||
nel -= nel/2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restrict out, size_t *restrict outb)
|
||||
{
|
||||
size_t x=0;
|
||||
struct stateful_cd *scd=0;
|
||||
if (!((size_t)cd & 1)) {
|
||||
scd = (void *)cd;
|
||||
cd = scd->base_cd;
|
||||
}
|
||||
unsigned to = extract_to(cd);
|
||||
unsigned from = extract_from(cd);
|
||||
const unsigned char *map = charmaps+from+1;
|
||||
const unsigned char *tomap = charmaps+to+1;
|
||||
mbstate_t st = {0};
|
||||
wchar_t wc;
|
||||
unsigned c, d;
|
||||
size_t k, l;
|
||||
int err;
|
||||
unsigned char type = map[-1];
|
||||
unsigned char totype = tomap[-1];
|
||||
locale_t *ploc = (locale_t *)&__get_tls()->tib_locale;
|
||||
locale_t loc = *ploc;
|
||||
|
||||
if (!in || !*in || !*inb) return 0;
|
||||
|
||||
*ploc = 0; // TODO(jart): UTF8_LOCALE?
|
||||
|
||||
for (; *inb; *in+=l, *inb-=l) {
|
||||
c = *(unsigned char *)*in;
|
||||
l = 1;
|
||||
|
||||
switch (type) {
|
||||
case UTF_8:
|
||||
if (c < 128) break;
|
||||
l = mbrtowc_utf8(&wc, *in, *inb, &st);
|
||||
if (l == (size_t)-1) goto ilseq;
|
||||
if (l == (size_t)-2) goto starved;
|
||||
c = wc;
|
||||
break;
|
||||
case US_ASCII:
|
||||
if (c >= 128) goto ilseq;
|
||||
break;
|
||||
case WCHAR_T:
|
||||
l = sizeof(wchar_t);
|
||||
if (*inb < l) goto starved;
|
||||
c = *(wchar_t *)*in;
|
||||
if (0) {
|
||||
case UTF_32BE:
|
||||
case UTF_32LE:
|
||||
l = 4;
|
||||
if (*inb < 4) goto starved;
|
||||
c = get_32((void *)*in, type);
|
||||
}
|
||||
if (c-0xd800u < 0x800u || c >= 0x110000u) goto ilseq;
|
||||
break;
|
||||
case UCS2BE:
|
||||
case UCS2LE:
|
||||
case UTF_16BE:
|
||||
case UTF_16LE:
|
||||
l = 2;
|
||||
if (*inb < 2) goto starved;
|
||||
c = get_16((void *)*in, type);
|
||||
if ((unsigned)(c-0xdc00) < 0x400) goto ilseq;
|
||||
if ((unsigned)(c-0xd800) < 0x400) {
|
||||
if (type-UCS2BE < 2U) goto ilseq;
|
||||
l = 4;
|
||||
if (*inb < 4) goto starved;
|
||||
d = get_16((void *)(*in + 2), type);
|
||||
if ((unsigned)(d-0xdc00) >= 0x400) goto ilseq;
|
||||
c = ((c-0xd7c0)<<10) + (d-0xdc00);
|
||||
}
|
||||
break;
|
||||
case UCS2:
|
||||
case UTF_16:
|
||||
l = 0;
|
||||
if (!scd)
|
||||
goto starved;
|
||||
if (!scd->state) {
|
||||
if (*inb < 2) goto starved;
|
||||
c = get_16((void *)*in, 0);
|
||||
scd->state = type==UCS2
|
||||
? c==0xfffe ? UCS2LE : UCS2BE
|
||||
: c==0xfffe ? UTF_16LE : UTF_16BE;
|
||||
if (c == 0xfffe || c == 0xfeff)
|
||||
l = 2;
|
||||
}
|
||||
type = scd->state;
|
||||
continue;
|
||||
case UTF_32:
|
||||
l = 0;
|
||||
if (!scd)
|
||||
goto starved;
|
||||
if (!scd->state) {
|
||||
if (*inb < 4) goto starved;
|
||||
c = get_32((void *)*in, 0);
|
||||
scd->state = c==0xfffe0000 ? UTF_32LE : UTF_32BE;
|
||||
if (c == 0xfffe0000 || c == 0xfeff)
|
||||
l = 4;
|
||||
}
|
||||
type = scd->state;
|
||||
continue;
|
||||
case SHIFT_JIS:
|
||||
if (c < 128) break;
|
||||
if (c-0xa1 <= 0xdf-0xa1) {
|
||||
c += 0xff61-0xa1;
|
||||
break;
|
||||
}
|
||||
l = 2;
|
||||
if (*inb < 2) goto starved;
|
||||
d = *((unsigned char *)*in + 1);
|
||||
if (c-129 <= 159-129) c -= 129;
|
||||
else if (c-224 <= 239-224) c -= 193;
|
||||
else goto ilseq;
|
||||
c *= 2;
|
||||
if (d-64 <= 158-64) {
|
||||
if (d==127) goto ilseq;
|
||||
if (d>127) d--;
|
||||
d -= 64;
|
||||
} else if (d-159 <= 252-159) {
|
||||
c++;
|
||||
d -= 159;
|
||||
}
|
||||
c = jis0208[c][d];
|
||||
if (!c) goto ilseq;
|
||||
break;
|
||||
case EUC_JP:
|
||||
if (c < 128) break;
|
||||
l = 2;
|
||||
if (*inb < 2) goto starved;
|
||||
d = *((unsigned char *)*in + 1);
|
||||
if (c==0x8e) {
|
||||
c = d;
|
||||
if (c-0xa1 > 0xdf-0xa1) goto ilseq;
|
||||
c += 0xff61 - 0xa1;
|
||||
break;
|
||||
}
|
||||
c -= 0xa1;
|
||||
d -= 0xa1;
|
||||
if (c >= 84 || d >= 94) goto ilseq;
|
||||
c = jis0208[c][d];
|
||||
if (!c) goto ilseq;
|
||||
break;
|
||||
case ISO2022_JP:
|
||||
if (!scd) goto starved;
|
||||
if (c >= 128) goto ilseq;
|
||||
if (c == '\033') {
|
||||
l = 3;
|
||||
if (*inb < 3) goto starved;
|
||||
c = *((unsigned char *)*in + 1);
|
||||
d = *((unsigned char *)*in + 2);
|
||||
if (c != '(' && c != '$') goto ilseq;
|
||||
switch (128*(c=='$') + d) {
|
||||
case 'B': scd->state=0; continue;
|
||||
case 'J': scd->state=1; continue;
|
||||
case 'I': scd->state=4; continue;
|
||||
case 128+'@': scd->state=2; continue;
|
||||
case 128+'B': scd->state=3; continue;
|
||||
}
|
||||
goto ilseq;
|
||||
}
|
||||
switch (scd->state) {
|
||||
case 1:
|
||||
if (c=='\\') c = 0xa5;
|
||||
if (c=='~') c = 0x203e;
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
l = 2;
|
||||
if (*inb < 2) goto starved;
|
||||
d = *((unsigned char *)*in + 1);
|
||||
c -= 0x21;
|
||||
d -= 0x21;
|
||||
if (c >= 84 || d >= 94) goto ilseq;
|
||||
c = jis0208[c][d];
|
||||
if (!c) goto ilseq;
|
||||
break;
|
||||
case 4:
|
||||
if (c-0x60 < 0x1f) goto ilseq;
|
||||
if (c-0x21 < 0x5e) c += 0xff61-0x21;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case GB2312:
|
||||
if (c < 128) break;
|
||||
if (c < 0xa1) goto ilseq;
|
||||
case GBK:
|
||||
case GB18030:
|
||||
if (c < 128) break;
|
||||
c -= 0x81;
|
||||
if (c >= 126) goto ilseq;
|
||||
l = 2;
|
||||
if (*inb < 2) goto starved;
|
||||
d = *((unsigned char *)*in + 1);
|
||||
if (d < 0xa1 && type == GB2312) goto ilseq;
|
||||
if (d-0x40>=191 || d==127) {
|
||||
if (d-'0'>9 || type != GB18030)
|
||||
goto ilseq;
|
||||
l = 4;
|
||||
if (*inb < 4) goto starved;
|
||||
c = (10*c + d-'0') * 1260;
|
||||
d = *((unsigned char *)*in + 2);
|
||||
if (d-0x81>126) goto ilseq;
|
||||
c += 10*(d-0x81);
|
||||
d = *((unsigned char *)*in + 3);
|
||||
if (d-'0'>9) goto ilseq;
|
||||
c += d-'0';
|
||||
c += 128;
|
||||
for (d=0; d<=c; ) {
|
||||
k = 0;
|
||||
for (int i=0; i<126; i++)
|
||||
for (int j=0; j<190; j++)
|
||||
if (gb18030[i][j]-d <= c-d)
|
||||
k++;
|
||||
d = c+1;
|
||||
c += k;
|
||||
}
|
||||
break;
|
||||
}
|
||||
d -= 0x40;
|
||||
if (d>63) d--;
|
||||
c = gb18030[c][d];
|
||||
break;
|
||||
case BIG5:
|
||||
if (c < 128) break;
|
||||
l = 2;
|
||||
if (*inb < 2) goto starved;
|
||||
d = *((unsigned char *)*in + 1);
|
||||
if (d-0x40>=0xff-0x40 || d-0x7f<0xa1-0x7f) goto ilseq;
|
||||
d -= 0x40;
|
||||
if (d > 0x3e) d -= 0x22;
|
||||
if (c-0xa1>=0xfa-0xa1) {
|
||||
if (c-0x87>=0xff-0x87) goto ilseq;
|
||||
if (c < 0xa1) c -= 0x87;
|
||||
else c -= 0x87 + (0xfa-0xa1);
|
||||
c = (hkscs[4867+(c*157+d)/16]>>(c*157+d)%16)%2<<17
|
||||
| hkscs[c*157+d];
|
||||
/* A few HKSCS characters map to pairs of UCS
|
||||
* characters. These are mapped to surrogate
|
||||
* range in the hkscs table then hard-coded
|
||||
* here. Ugly, yes. */
|
||||
if (c/256 == 0xdc) {
|
||||
union {
|
||||
char c[8];
|
||||
wchar_t wc[2];
|
||||
} tmp;
|
||||
char *ptmp = tmp.c;
|
||||
size_t tmpx = iconv(combine_to_from(to, find_charmap("utf8")),
|
||||
&(char *){"\303\212\314\204"
|
||||
"\303\212\314\214"
|
||||
"\303\252\314\204"
|
||||
"\303\252\314\214"
|
||||
+c%256}, &(size_t){4},
|
||||
&ptmp, &(size_t){sizeof tmp});
|
||||
size_t tmplen = ptmp - tmp.c;
|
||||
if (tmplen > *outb) goto toobig;
|
||||
if (tmpx) x++;
|
||||
memcpy(*out, &tmp, tmplen);
|
||||
*out += tmplen;
|
||||
*outb -= tmplen;
|
||||
continue;
|
||||
}
|
||||
if (!c) goto ilseq;
|
||||
break;
|
||||
}
|
||||
c -= 0xa1;
|
||||
c = big5[c][d]|(c==0x27&&(d==0x3a||d==0x3c||d==0x42))<<17;
|
||||
if (!c) goto ilseq;
|
||||
break;
|
||||
case EUC_KR:
|
||||
if (c < 128) break;
|
||||
l = 2;
|
||||
if (*inb < 2) goto starved;
|
||||
d = *((unsigned char *)*in + 1);
|
||||
c -= 0xa1;
|
||||
d -= 0xa1;
|
||||
if (c >= 93 || d >= 94) {
|
||||
c += (0xa1-0x81);
|
||||
d += 0xa1;
|
||||
if (c >= 93 || ((c>=0xc6-0x81) && d>0x52))
|
||||
goto ilseq;
|
||||
if (d-'A'<26) d = d-'A';
|
||||
else if (d-'a'<26) d = d-'a'+26;
|
||||
else if (d-0x81<0xff-0x81) d = d-0x81+52;
|
||||
else goto ilseq;
|
||||
if (c < 0x20) c = 178*c + d;
|
||||
else c = 178*0x20 + 84*(c-0x20) + d;
|
||||
c += 0xac00;
|
||||
for (d=0xac00; d<=c; ) {
|
||||
k = 0;
|
||||
for (int i=0; i<93; i++)
|
||||
for (int j=0; j<94; j++)
|
||||
if (ksc[i][j]-d <= c-d)
|
||||
k++;
|
||||
d = c+1;
|
||||
c += k;
|
||||
}
|
||||
break;
|
||||
}
|
||||
c = ksc[c][d];
|
||||
if (!c) goto ilseq;
|
||||
break;
|
||||
default:
|
||||
if (!c) break;
|
||||
c = legacy_map(map, c);
|
||||
if (!c) goto ilseq;
|
||||
}
|
||||
|
||||
switch (totype) {
|
||||
case WCHAR_T:
|
||||
if (*outb < sizeof(wchar_t)) goto toobig;
|
||||
*(wchar_t *)*out = c;
|
||||
*out += sizeof(wchar_t);
|
||||
*outb -= sizeof(wchar_t);
|
||||
break;
|
||||
case UTF_8:
|
||||
if (*outb < 4) {
|
||||
char tmp[4];
|
||||
k = wctomb_utf8(tmp, c);
|
||||
if (*outb < k) goto toobig;
|
||||
memcpy(*out, tmp, k);
|
||||
} else k = wctomb_utf8(*out, c);
|
||||
*out += k;
|
||||
*outb -= k;
|
||||
break;
|
||||
case US_ASCII:
|
||||
if (c > 0x7f) subst: x++, c='*';
|
||||
default:
|
||||
if (*outb < 1) goto toobig;
|
||||
if (c<256 && c==legacy_map(tomap, c)) {
|
||||
revout:
|
||||
if (*outb < 1) goto toobig;
|
||||
*(*out)++ = c;
|
||||
*outb -= 1;
|
||||
break;
|
||||
}
|
||||
d = c;
|
||||
for (c=4*totype; c<256; c++) {
|
||||
if (d == legacy_map(tomap, c)) {
|
||||
goto revout;
|
||||
}
|
||||
}
|
||||
goto subst;
|
||||
case SHIFT_JIS:
|
||||
if (c < 128) goto revout;
|
||||
if (c == 0xa5) {
|
||||
x++;
|
||||
c = '\\';
|
||||
goto revout;
|
||||
}
|
||||
if (c == 0x203e) {
|
||||
x++;
|
||||
c = '~';
|
||||
goto revout;
|
||||
}
|
||||
if (c-0xff61 <= 0xdf-0xa1) {
|
||||
c += 0xa1 - 0xff61;
|
||||
goto revout;
|
||||
}
|
||||
c = uni_to_jis(c);
|
||||
if (!c) goto subst;
|
||||
if (*outb < 2) goto toobig;
|
||||
d = c%256;
|
||||
c = c/256;
|
||||
*(*out)++ = (c+1)/2 + (c<95 ? 112 : 176);
|
||||
*(*out)++ = c%2 ? d + 31 + d/96 : d + 126;
|
||||
*outb -= 2;
|
||||
break;
|
||||
case EUC_JP:
|
||||
if (c < 128) goto revout;
|
||||
if (c-0xff61 <= 0xdf-0xa1) {
|
||||
c += 0x0e00 + 0x21 - 0xff61;
|
||||
} else {
|
||||
c = uni_to_jis(c);
|
||||
}
|
||||
if (!c) goto subst;
|
||||
if (*outb < 2) goto toobig;
|
||||
*(*out)++ = c/256 + 0x80;
|
||||
*(*out)++ = c%256 + 0x80;
|
||||
*outb -= 2;
|
||||
break;
|
||||
case ISO2022_JP:
|
||||
if (c < 128) goto revout;
|
||||
if (c-0xff61 <= 0xdf-0xa1 || c==0xa5 || c==0x203e) {
|
||||
if (*outb < 7) goto toobig;
|
||||
*(*out)++ = '\033';
|
||||
*(*out)++ = '(';
|
||||
if (c==0xa5) {
|
||||
*(*out)++ = 'J';
|
||||
*(*out)++ = '\\';
|
||||
} else if (c==0x203e) {
|
||||
*(*out)++ = 'J';
|
||||
*(*out)++ = '~';
|
||||
} else {
|
||||
*(*out)++ = 'I';
|
||||
*(*out)++ = c-0xff61+0x21;
|
||||
}
|
||||
*(*out)++ = '\033';
|
||||
*(*out)++ = '(';
|
||||
*(*out)++ = 'B';
|
||||
*outb -= 7;
|
||||
break;
|
||||
}
|
||||
c = uni_to_jis(c);
|
||||
if (!c) goto subst;
|
||||
if (*outb < 8) goto toobig;
|
||||
*(*out)++ = '\033';
|
||||
*(*out)++ = '$';
|
||||
*(*out)++ = 'B';
|
||||
*(*out)++ = c/256;
|
||||
*(*out)++ = c%256;
|
||||
*(*out)++ = '\033';
|
||||
*(*out)++ = '(';
|
||||
*(*out)++ = 'B';
|
||||
*outb -= 8;
|
||||
break;
|
||||
case UCS2:
|
||||
totype = UCS2BE;
|
||||
case UCS2BE:
|
||||
case UCS2LE:
|
||||
case UTF_16:
|
||||
case UTF_16BE:
|
||||
case UTF_16LE:
|
||||
if (c < 0x10000 || totype-UCS2BE < 2U) {
|
||||
if (c >= 0x10000) c = 0xFFFD;
|
||||
if (*outb < 2) goto toobig;
|
||||
put_16((void *)*out, c, totype);
|
||||
*out += 2;
|
||||
*outb -= 2;
|
||||
break;
|
||||
}
|
||||
if (*outb < 4) goto toobig;
|
||||
c -= 0x10000;
|
||||
put_16((void *)*out, (c>>10)|0xd800, totype);
|
||||
put_16((void *)(*out + 2), (c&0x3ff)|0xdc00, totype);
|
||||
*out += 4;
|
||||
*outb -= 4;
|
||||
break;
|
||||
case UTF_32:
|
||||
totype = UTF_32BE;
|
||||
case UTF_32BE:
|
||||
case UTF_32LE:
|
||||
if (*outb < 4) goto toobig;
|
||||
put_32((void *)*out, c, totype);
|
||||
*out += 4;
|
||||
*outb -= 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*ploc = loc;
|
||||
return x;
|
||||
ilseq:
|
||||
err = EILSEQ;
|
||||
x = -1;
|
||||
goto end;
|
||||
toobig:
|
||||
err = E2BIG;
|
||||
x = -1;
|
||||
goto end;
|
||||
starved:
|
||||
err = EINVAL;
|
||||
x = -1;
|
||||
end:
|
||||
errno = err;
|
||||
*ploc = loc;
|
||||
return x;
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/limits.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/mb.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
wint_t btowc(int c) {
|
||||
int b = (unsigned char)c;
|
||||
return b < 128U ? b : (MB_CUR_MAX == 1 && c != EOF) ? CODEUNIT(c) : WEOF;
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/str/mb.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
size_t c16rtomb(char *restrict s, char16_t c16, mbstate_t *restrict ps) {
|
||||
static unsigned internal_state;
|
||||
if (!ps)
|
||||
ps = (void *)&internal_state;
|
||||
unsigned *x = (unsigned *)ps;
|
||||
wchar_t wc;
|
||||
if (!s) {
|
||||
if (*x)
|
||||
goto ilseq;
|
||||
return 1;
|
||||
}
|
||||
if (!*x && c16 - 0xd800u < 0x400) {
|
||||
*x = (c16 - 0xd7c0) << 10;
|
||||
return 0;
|
||||
}
|
||||
if (*x) {
|
||||
if (c16 - 0xdc00u >= 0x400)
|
||||
goto ilseq;
|
||||
else
|
||||
wc = *x + c16 - 0xdc00;
|
||||
*x = 0;
|
||||
} else {
|
||||
wc = c16;
|
||||
}
|
||||
return wcrtomb(s, wc, 0);
|
||||
ilseq:
|
||||
*x = 0;
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
|
||||
size_t c32rtomb(char *s, char32_t c, mbstate_t *t) {
|
||||
return wcrtomb(s, c, t);
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/locale.h"
|
||||
|
||||
void freelocale(locale_t l) {
|
||||
// TODO: implement me
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/langinfo.h"
|
||||
#include "libc/str/locale.h"
|
||||
#include "libc/str/nltypes.h"
|
||||
#include "libc/thread/tls.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
// clang-format off
|
||||
|
||||
static const char c_time[] =
|
||||
"Sun\0" "Mon\0" "Tue\0" "Wed\0" "Thu\0" "Fri\0" "Sat\0"
|
||||
"Sunday\0" "Monday\0" "Tuesday\0" "Wednesday\0"
|
||||
"Thursday\0" "Friday\0" "Saturday\0"
|
||||
"Jan\0" "Feb\0" "Mar\0" "Apr\0" "May\0" "Jun\0"
|
||||
"Jul\0" "Aug\0" "Sep\0" "Oct\0" "Nov\0" "Dec\0"
|
||||
"January\0" "February\0" "March\0" "April\0"
|
||||
"May\0" "June\0" "July\0" "August\0"
|
||||
"September\0" "October\0" "November\0" "December\0"
|
||||
"AM\0" "PM\0"
|
||||
"%a %b %e %T %Y\0"
|
||||
"%m/%d/%y\0"
|
||||
"%H:%M:%S\0"
|
||||
"%I:%M:%S %p\0"
|
||||
"\0"
|
||||
"\0"
|
||||
"%m/%d/%y\0"
|
||||
"0123456789\0"
|
||||
"%a %b %e %T %Y\0"
|
||||
"%H:%M:%S";
|
||||
|
||||
static const char c_messages[] = "^[yY]\0" "^[nN]\0" "yes\0" "no";
|
||||
static const char c_numeric[] = ".\0" "";
|
||||
|
||||
char *nl_langinfo_l(nl_item item, locale_t loc)
|
||||
{
|
||||
int cat = item >> 16;
|
||||
int idx = item & 65535;
|
||||
const char *str;
|
||||
|
||||
if (!loc)
|
||||
return "";
|
||||
|
||||
if (item == CODESET) return loc->cat[LC_CTYPE] ? "UTF-8" : "ASCII";
|
||||
|
||||
/* _NL_LOCALE_NAME extension */
|
||||
if (idx == 65535 && cat < LC_ALL)
|
||||
return loc->cat[cat] ? (char *)loc->cat[cat]->name : "C";
|
||||
|
||||
switch (cat) {
|
||||
case LC_NUMERIC:
|
||||
if (idx > 1) return "";
|
||||
str = c_numeric;
|
||||
break;
|
||||
case LC_TIME:
|
||||
if (idx > 0x31) return "";
|
||||
str = c_time;
|
||||
break;
|
||||
case LC_MONETARY:
|
||||
if (idx > 0) return "";
|
||||
str = "";
|
||||
break;
|
||||
case LC_MESSAGES:
|
||||
if (idx > 3) return "";
|
||||
str = c_messages;
|
||||
break;
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
|
||||
for (; idx; idx--, str++) for (; *str; str++);
|
||||
// if (cat != LC_NUMERIC && *str) str = LCTRANS(str, cat, loc);
|
||||
return (char *)str;
|
||||
}
|
||||
|
||||
char *nl_langinfo(nl_item item)
|
||||
{
|
||||
return nl_langinfo_l(item, (locale_t)__get_tls()->tib_locale);
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_STR_LANGINFO_H_
|
||||
#define COSMOPOLITAN_LIBC_STR_LANGINFO_H_
|
||||
#include "libc/str/locale.h"
|
||||
#include "libc/str/nltypes.h"
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define ABDAY_1 0x20000
|
||||
|
@ -78,7 +80,8 @@ COSMOPOLITAN_C_START_
|
|||
#define NOSTR 0x50003
|
||||
#endif
|
||||
|
||||
char *nl_langinfo(int);
|
||||
char *nl_langinfo(nl_item);
|
||||
char *nl_langinfo_l(nl_item, locale_t);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_STR_LANGINFO_H_ */
|
||||
|
|
|
@ -16,10 +16,12 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/locale.h"
|
||||
#include "libc/str/locale.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
static const uint32_t empty_mo[] = {0x950412de, 0, -1, -1, -1};
|
||||
static const uint32_t empty_mo[] = {
|
||||
0x950412de, 0, -1, -1, -1,
|
||||
};
|
||||
|
||||
const struct __locale_map __c_dot_utf8 = {
|
||||
.map = empty_mo,
|
||||
|
@ -27,8 +29,11 @@ const struct __locale_map __c_dot_utf8 = {
|
|||
.name = "C.UTF-8",
|
||||
};
|
||||
|
||||
const struct __locale_struct __c_locale;
|
||||
|
||||
const struct __locale_struct __c_locale = {0};
|
||||
const struct __locale_struct __c_dot_utf8_locale = {
|
||||
.cat[LC_CTYPE] = &__c_dot_utf8,
|
||||
};
|
||||
|
||||
struct __locale_struct __global_locale;
|
||||
|
||||
pthread_mutex_t __locale_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
|
|
@ -17,29 +17,13 @@
|
|||
#define LC_MONETARY_MASK 16
|
||||
#define LC_MESSAGES_MASK 32
|
||||
#define LC_ALL_MASK 0x1fbf
|
||||
#define LOCALE_NAME_MAX 23
|
||||
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define LC_GLOBAL_LOCALE ((locale_t) - 1)
|
||||
|
||||
struct __locale_map {
|
||||
const void *map;
|
||||
size_t map_size;
|
||||
char name[LOCALE_NAME_MAX + 1];
|
||||
const struct __locale_map *next;
|
||||
};
|
||||
|
||||
struct __locale_struct {
|
||||
const struct __locale_map *cat[6];
|
||||
};
|
||||
|
||||
typedef struct __locale_struct *locale_t;
|
||||
|
||||
extern const struct __locale_map __c_dot_utf8;
|
||||
extern const struct __locale_struct __c_locale;
|
||||
extern const struct __locale_struct __c_dot_utf8_locale;
|
||||
|
||||
char *nl_langinfo_l(int, locale_t) libcesque;
|
||||
char *setlocale(int, const char *) libcesque;
|
||||
double strtod_l(const char *, char **, locale_t) libcesque;
|
||||
|
|
52
libc/str/locale.internal.h
Normal file
52
libc/str/locale.internal.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_STR_LOCALE_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_STR_LOCALE_INTERNAL_H_
|
||||
#include "libc/limits.h"
|
||||
#include "libc/str/locale.h"
|
||||
#include "libc/thread/posixthread.internal.h"
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define LOCALE_NAME_MAX 23
|
||||
|
||||
struct __locale_map {
|
||||
const void *map;
|
||||
size_t map_size;
|
||||
char name[LOCALE_NAME_MAX + 1];
|
||||
const struct __locale_map *next;
|
||||
};
|
||||
|
||||
struct __locale_struct {
|
||||
const struct __locale_map *cat[6];
|
||||
};
|
||||
|
||||
extern pthread_mutex_t __locale_lock;
|
||||
|
||||
extern struct __locale_struct __global_locale;
|
||||
extern const struct __locale_map __c_dot_utf8;
|
||||
extern const struct __locale_struct __c_locale;
|
||||
extern const struct __locale_struct __c_dot_utf8_locale;
|
||||
|
||||
const struct __locale_map *__get_locale(int, const char *);
|
||||
const char *__mo_lookup(const void *, size_t, const char *);
|
||||
const char *__lctrans(const char *, const struct __locale_map *);
|
||||
const char *__lctrans_cur(const char *);
|
||||
const char *__lctrans_impl(const char *, const struct __locale_map *);
|
||||
int __loc_is_allocated(locale_t);
|
||||
char *__gettextdomain(void);
|
||||
|
||||
#define LOC_MAP_FAILED ((const struct __locale_map *)-1)
|
||||
|
||||
#define LCTRANS(msg, lc, loc) __lctrans(msg, (loc)->cat[(lc)])
|
||||
#define LCTRANS_CUR(msg) __lctrans_cur(msg)
|
||||
|
||||
#define C_LOCALE ((locale_t) & __c_locale)
|
||||
#define UTF8_LOCALE ((locale_t) & __c_dot_utf8_locale)
|
||||
|
||||
#define CURRENT_LOCALE _pthread_self()->pt_locale
|
||||
|
||||
#define CURRENT_UTF8 (!!_pthread_self()->pt_locale->cat[LC_CTYPE])
|
||||
|
||||
#undef MB_CUR_MAX
|
||||
#define MB_CUR_MAX (CURRENT_UTF8 ? 4 : 1)
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_STR_LOCALE_INTERNAL_H_ */
|
|
@ -1,52 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/mb.internal.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
#define C(x) (x < 2 ? -1 : (R(0x80, 0xc0) | x))
|
||||
#define D(x) C((x + 16))
|
||||
#define E(x) \
|
||||
((x == 0 ? R(0xa0, 0xc0) \
|
||||
: x == 0xd ? R(0x80, 0xa0) \
|
||||
: R(0x80, 0xc0)) | \
|
||||
(R(0x80, 0xc0) >> 6) | x)
|
||||
#define F(x) \
|
||||
((x >= 5 ? 0 \
|
||||
: x == 0 ? R(0x90, 0xc0) \
|
||||
: x == 4 ? R(0x80, 0x90) \
|
||||
: R(0x80, 0xc0)) | \
|
||||
(R(0x80, 0xc0) >> 6) | (R(0x80, 0xc0) >> 12) | x)
|
||||
|
||||
const uint32_t kMbBittab[51 /* ?! */] = {
|
||||
C(0x2), C(0x3), C(0x4), C(0x5), C(0x6), C(0x7), C(0x8), C(0x9), C(0xa),
|
||||
C(0xb), C(0xc), C(0xd), C(0xe), C(0xf), D(0x0), D(0x1), D(0x2), D(0x3),
|
||||
D(0x4), D(0x5), D(0x6), D(0x7), D(0x8), D(0x9), D(0xa), D(0xb), D(0xc),
|
||||
D(0xd), D(0xe), D(0xf), E(0x0), E(0x1), E(0x2), E(0x3), E(0x4), E(0x5),
|
||||
E(0x6), E(0x7), E(0x8), E(0x9), E(0xa), E(0xb), E(0xc), E(0xd), E(0xe),
|
||||
E(0xf), F(0x0), F(0x1), F(0x2), F(0x3), F(0x4),
|
||||
};
|
|
@ -1,17 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_STR_MB_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_STR_MB_INTERNAL_H_
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define SA 0xc2u
|
||||
#define SB 0xf4u
|
||||
#define CODEUNIT(c) (0xdfff & (signed char)(c))
|
||||
#define IS_CODEUNIT(c) ((unsigned)(c) - 0xdf80 < 0x80)
|
||||
#define R(a, b) ((uint32_t)((a == 0x80 ? 0x40u - b : 0u - a) << 23))
|
||||
#define FAILSTATE R(0x80, 0x80)
|
||||
#define OOB(c, b) \
|
||||
(((((b) >> 3) - 0x10) | (((b) >> 3) + ((int32_t)(c) >> 26))) & ~7)
|
||||
|
||||
extern const uint32_t kMbBittab[51];
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_STR_MB_INTERNAL_H_ */
|
|
@ -1,23 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
|
||||
int mblen(const char *s, size_t n) {
|
||||
return mbtowc(0, s, n);
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
|
||||
size_t mbrlen(const char *s, size_t n, mbstate_t *t) {
|
||||
static mbstate_t ss;
|
||||
if (!t)
|
||||
t = &ss;
|
||||
return mbrtowc(0, s, n, t);
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/str/mb.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
size_t mbrtoc16(char16_t *pc16, const char *s, size_t n, mbstate_t *ps) {
|
||||
static unsigned internal_state;
|
||||
if (!ps)
|
||||
ps = (void *)&internal_state;
|
||||
unsigned *pending = (unsigned *)ps;
|
||||
if (!s)
|
||||
return mbrtoc16(0, "", 1, ps);
|
||||
/* mbrtowc states for partial UTF-8 characters have the high bit set;
|
||||
* we use nonzero states without high bit for pending surrogates. */
|
||||
if ((int)*pending > 0) {
|
||||
if (pc16)
|
||||
*pc16 = *pending;
|
||||
*pending = 0;
|
||||
return -3;
|
||||
}
|
||||
wchar_t wc;
|
||||
size_t ret = mbrtowc(&wc, s, n, ps);
|
||||
if (ret <= 4) {
|
||||
if (wc >= 0x10000) {
|
||||
*pending = (wc & 0x3ff) + 0xdc00;
|
||||
wc = 0xd7c0 + (wc >> 10);
|
||||
}
|
||||
if (pc16)
|
||||
*pc16 = wc;
|
||||
}
|
||||
return ret;
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
size_t mbrtoc32(char32_t *pc32, const char *s, size_t n, mbstate_t *ps) {
|
||||
static unsigned internal_state;
|
||||
if (!ps)
|
||||
ps = (void *)&internal_state;
|
||||
if (!s)
|
||||
return mbrtoc32(0, "", 1, ps);
|
||||
wchar_t wc;
|
||||
size_t ret = mbrtowc(&wc, s, n, ps);
|
||||
if (ret <= 4 && pc32)
|
||||
*pc32 = wc;
|
||||
return ret;
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/str/mb.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
size_t mbrtowc(wchar_t *wc, const char *src, size_t n, mbstate_t *st) {
|
||||
static unsigned internal_state;
|
||||
long wut;
|
||||
unsigned c;
|
||||
const unsigned char *s = (const void *)src;
|
||||
const unsigned N = n;
|
||||
wchar_t dummy;
|
||||
if (!st)
|
||||
st = (void *)&internal_state;
|
||||
c = *(unsigned *)st;
|
||||
if (!s) {
|
||||
if (c)
|
||||
goto ilseq;
|
||||
return 0;
|
||||
} else if (!wc) {
|
||||
wc = &dummy;
|
||||
}
|
||||
if (!n)
|
||||
return -2;
|
||||
if (!c) {
|
||||
if (*s < 0x80)
|
||||
return !!(*wc = *s);
|
||||
if (MB_CUR_MAX == 1)
|
||||
return (*wc = CODEUNIT(*s)), 1;
|
||||
if (*s - SA > SB - SA)
|
||||
goto ilseq;
|
||||
wut = *s++ - SA;
|
||||
wut = MAX(0, MIN(ARRAYLEN(kMbBittab) - 1, wut));
|
||||
c = kMbBittab[wut];
|
||||
n--;
|
||||
}
|
||||
if (n) {
|
||||
if (OOB(c, *s))
|
||||
goto ilseq;
|
||||
loop:
|
||||
c = c << 6 | (*s++ - 0x80);
|
||||
n--;
|
||||
if (!(c & (1U << 31))) {
|
||||
*(unsigned *)st = 0;
|
||||
*wc = c;
|
||||
return N - n;
|
||||
}
|
||||
if (n) {
|
||||
if (*s - 0x80u >= 0x40)
|
||||
goto ilseq;
|
||||
goto loop;
|
||||
}
|
||||
}
|
||||
*(unsigned *)st = c;
|
||||
return -2;
|
||||
ilseq:
|
||||
*(unsigned *)st = 0;
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
|
||||
int mbsinit(const mbstate_t *t) {
|
||||
return !t || !*t;
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/str/mb.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
size_t mbsnrtowcs(wchar_t *wcs, const char **src, size_t n, size_t wn,
|
||||
mbstate_t *st) {
|
||||
size_t l, cnt = 0, n2;
|
||||
wchar_t *ws, wbuf[256];
|
||||
const char *s = *src;
|
||||
const char *tmp_s;
|
||||
if (!wcs) {
|
||||
ws = wbuf, wn = sizeof(wbuf) / sizeof(*wbuf);
|
||||
} else {
|
||||
ws = wcs;
|
||||
}
|
||||
/* making sure output buffer size is at most n/4 will ensure
|
||||
* that mbsrtowcs never reads more than n input bytes. thus
|
||||
* we can use mbsrtowcs as long as it's practical.. */
|
||||
while (s && wn && ((n2 = n / 4) >= wn || n2 > 32)) {
|
||||
if (n2 >= wn)
|
||||
n2 = wn;
|
||||
tmp_s = s;
|
||||
l = mbsrtowcs(ws, &s, n2, st);
|
||||
if (!(l + 1)) {
|
||||
cnt = l;
|
||||
wn = 0;
|
||||
break;
|
||||
}
|
||||
if (ws != wbuf) {
|
||||
ws += l;
|
||||
wn -= l;
|
||||
}
|
||||
n = s ? n - (s - tmp_s) : 0;
|
||||
cnt += l;
|
||||
}
|
||||
if (s)
|
||||
while (wn && n) {
|
||||
l = mbrtowc(ws, s, n, st);
|
||||
if (l + 2 <= 2) {
|
||||
if (!(l + 1)) {
|
||||
cnt = l;
|
||||
break;
|
||||
}
|
||||
if (!l) {
|
||||
s = 0;
|
||||
break;
|
||||
}
|
||||
/* have to roll back partial character */
|
||||
*(unsigned *)st = 0;
|
||||
break;
|
||||
}
|
||||
s += l;
|
||||
n -= l;
|
||||
/* safe - this loop runs fewer than sizeof(wbuf)/8 times */
|
||||
ws++;
|
||||
wn--;
|
||||
cnt++;
|
||||
}
|
||||
if (wcs)
|
||||
*src = s;
|
||||
return cnt;
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/str/mb.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
size_t mbsrtowcs(wchar_t *ws, const char **src, size_t wn, mbstate_t *st) {
|
||||
const unsigned char *s = (const void *)*src;
|
||||
size_t wn0 = wn;
|
||||
unsigned c = 0;
|
||||
if (st && (c = *(unsigned *)st)) {
|
||||
if (ws) {
|
||||
*(unsigned *)st = 0;
|
||||
goto resume;
|
||||
} else {
|
||||
goto resume0;
|
||||
}
|
||||
}
|
||||
if (MB_CUR_MAX == 1) {
|
||||
if (!ws)
|
||||
return strlen((const char *)s);
|
||||
for (;;) {
|
||||
if (!wn) {
|
||||
*src = (const void *)s;
|
||||
return wn0;
|
||||
}
|
||||
if (!*s)
|
||||
break;
|
||||
c = *s++;
|
||||
*ws++ = CODEUNIT(c);
|
||||
wn--;
|
||||
}
|
||||
*ws = 0;
|
||||
*src = 0;
|
||||
return wn0 - wn;
|
||||
}
|
||||
if (!ws)
|
||||
for (;;) {
|
||||
if (*s - 1u < 0x7f) {
|
||||
s++;
|
||||
wn--;
|
||||
continue;
|
||||
}
|
||||
if (*s - SA > SB - SA)
|
||||
break;
|
||||
c = kMbBittab[*s++ - SA];
|
||||
resume0:
|
||||
if (OOB(c, *s)) {
|
||||
s--;
|
||||
break;
|
||||
}
|
||||
s++;
|
||||
if (c & (1U << 25)) {
|
||||
if (*s - 0x80u >= 0x40) {
|
||||
s -= 2;
|
||||
break;
|
||||
}
|
||||
s++;
|
||||
if (c & (1U << 19)) {
|
||||
if (*s - 0x80u >= 0x40) {
|
||||
s -= 3;
|
||||
break;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
}
|
||||
wn--;
|
||||
c = 0;
|
||||
}
|
||||
else
|
||||
for (;;) {
|
||||
if (!wn) {
|
||||
*src = (const void *)s;
|
||||
return wn0;
|
||||
}
|
||||
if (*s - 1u < 0x7f) {
|
||||
*ws++ = *s++;
|
||||
wn--;
|
||||
continue;
|
||||
}
|
||||
if (*s - SA > SB - SA)
|
||||
break;
|
||||
c = kMbBittab[*s++ - SA];
|
||||
resume:
|
||||
if (OOB(c, *s)) {
|
||||
s--;
|
||||
break;
|
||||
}
|
||||
c = (c << 6) | (*s++ - 0x80);
|
||||
if (c & (1U << 31)) {
|
||||
if (*s - 0x80u >= 0x40) {
|
||||
s -= 2;
|
||||
break;
|
||||
}
|
||||
c = (c << 6) | (*s++ - 0x80);
|
||||
if (c & (1U << 31)) {
|
||||
if (*s - 0x80u >= 0x40) {
|
||||
s -= 3;
|
||||
break;
|
||||
}
|
||||
c = (c << 6) | (*s++ - 0x80);
|
||||
}
|
||||
}
|
||||
*ws++ = c;
|
||||
wn--;
|
||||
c = 0;
|
||||
}
|
||||
if (!c && !*s) {
|
||||
if (ws) {
|
||||
*ws = 0;
|
||||
*src = 0;
|
||||
}
|
||||
return wn0 - wn;
|
||||
}
|
||||
errno = EILSEQ;
|
||||
if (ws)
|
||||
*src = (const void *)s;
|
||||
return -1;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
|
||||
size_t mbstowcs(wchar_t *pwc, const char *s, size_t wn) {
|
||||
return mbsrtowcs(pwc, (void *)&s, wn, 0);
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/str/mb.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
int mbtowc(wchar_t *restrict wc, const char *restrict src, size_t n) {
|
||||
unsigned c;
|
||||
const unsigned char *s = (const void *)src;
|
||||
wchar_t dummy;
|
||||
if (!s)
|
||||
return 0;
|
||||
if (!n)
|
||||
goto ilseq;
|
||||
if (!wc)
|
||||
wc = &dummy;
|
||||
if (*s < 0x80)
|
||||
return !!(*wc = *s);
|
||||
if (MB_CUR_MAX == 1)
|
||||
return (*wc = CODEUNIT(*s)), 1;
|
||||
if (*s - SA > SB - SA)
|
||||
goto ilseq;
|
||||
c = kMbBittab[*s++ - SA];
|
||||
/* Avoid excessive checks against n: If shifting the state n-1
|
||||
* times does not clear the high bit, then the value of n is
|
||||
* insufficient to read a character */
|
||||
if (n < 4 && ((c << (6 * n - 6)) & (1U << 31)))
|
||||
goto ilseq;
|
||||
if (OOB(c, *s))
|
||||
goto ilseq;
|
||||
c = c << 6 | (*s++ - 0x80);
|
||||
if (!(c & (1U << 31))) {
|
||||
*wc = c;
|
||||
return 2;
|
||||
}
|
||||
if (*s - 0x80u >= 0x40)
|
||||
goto ilseq;
|
||||
c = c << 6 | (*s++ - 0x80);
|
||||
if (!(c & (1U << 31))) {
|
||||
*wc = c;
|
||||
return 3;
|
||||
}
|
||||
if (*s - 0x80u >= 0x40)
|
||||
goto ilseq;
|
||||
*wc = c << 6 | (*s++ - 0x80);
|
||||
return 4;
|
||||
ilseq:
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/locale.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
locale_t newlocale(int catmask, const char *locale, locale_t base) {
|
||||
// TODO: implement me
|
||||
return 0;
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/safemacros.h"
|
||||
#include "libc/intrin/strace.h"
|
||||
#include "libc/str/locale.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* Sets program locale.
|
||||
*
|
||||
* Cosmopolitan only supports the C or POSIX locale with UTF-8.
|
||||
*/
|
||||
char *setlocale(int category, const char *locale) {
|
||||
char *res;
|
||||
if (!locale || (*locale == '\0')) {
|
||||
res = "C";
|
||||
} else if (!strcmp(locale, "C") || //
|
||||
!strcmp(locale, "POSIX") || //
|
||||
!strcmp(locale, "C.UTF-8") || //
|
||||
!strcmp(locale, "en_US.UTF-8")) {
|
||||
res = (char *)locale;
|
||||
} else {
|
||||
res = NULL;
|
||||
}
|
||||
STRACE("setlocale(%d, %#s) → %s", category, locale, res);
|
||||
return res;
|
||||
}
|
|
@ -27,10 +27,7 @@ COSMOPOLITAN_C_START_
|
|||
void *memset(void *, int, size_t) memcpyesque;
|
||||
void *memmove(void *, const void *, size_t) memcpyesque;
|
||||
void *memcpy(void *, const void *, size_t) memcpyesque;
|
||||
void *mempcpy(void *, const void *, size_t) memcpyesque;
|
||||
char *hexpcpy(char *, const void *, size_t) memcpyesque;
|
||||
void *memccpy(void *, const void *, int, size_t) memcpyesque;
|
||||
void explicit_bzero(void *, size_t);
|
||||
|
||||
int memcmp(const void *, const void *, size_t) strlenesque;
|
||||
int timingsafe_bcmp(const void *, const void *, size_t) libcesque;
|
||||
|
@ -41,7 +38,6 @@ size_t strnlen(const char *, size_t) strlenesque;
|
|||
size_t strnlen_s(const char *, size_t) libcesque;
|
||||
char *strchr(const char *, int) strlenesque;
|
||||
void *memchr(const void *, int, size_t) strlenesque;
|
||||
char *strchrnul(const char *, int) strlenesque returnsnonnull;
|
||||
void *rawmemchr(const void *, int) strlenesque returnsnonnull;
|
||||
size_t wcslen(const wchar_t *) strlenesque;
|
||||
size_t wcsnlen(const wchar_t *, size_t) strlenesque;
|
||||
|
@ -51,7 +47,6 @@ wchar_t *wmemchr(const wchar_t *, wchar_t, size_t) strlenesque;
|
|||
wchar_t *wcschrnul(const wchar_t *, wchar_t)
|
||||
strlenesque returnsnonnull;
|
||||
char *strstr(const char *, const char *) strlenesque;
|
||||
char *strcasestr(const char *, const char *) strlenesque;
|
||||
wchar_t *wcsstr(const wchar_t *, const wchar_t *) strlenesque;
|
||||
int strcmp(const char *, const char *) strlenesque;
|
||||
int strncmp(const char *, const char *, size_t) strlenesque;
|
||||
|
@ -59,14 +54,11 @@ int wcscmp(const wchar_t *, const wchar_t *) strlenesque;
|
|||
int wcsncmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
|
||||
int wmemcmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
|
||||
int strcasecmp(const char *, const char *) strlenesque;
|
||||
int memcasecmp(const void *, const void *, size_t) strlenesque;
|
||||
int wcscasecmp(const wchar_t *, const wchar_t *) strlenesque;
|
||||
int strncasecmp(const char *, const char *, size_t) strlenesque;
|
||||
int wcsncasecmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
|
||||
char *strrchr(const char *, int) strlenesque;
|
||||
void *memrchr(const void *, int, size_t) strlenesque;
|
||||
wchar_t *wcsrchr(const wchar_t *, wchar_t) strlenesque;
|
||||
void *wmemrchr(const wchar_t *, wchar_t, size_t) strlenesque;
|
||||
char *strpbrk(const char *, const char *) strlenesque;
|
||||
wchar_t *wcspbrk(const wchar_t *, const wchar_t *) strlenesque;
|
||||
size_t strspn(const char *, const char *) strlenesque;
|
||||
|
@ -75,13 +67,10 @@ size_t strcspn(const char *, const char *) strlenesque;
|
|||
size_t wcscspn(const wchar_t *, const wchar_t *) strlenesque;
|
||||
void *memfrob(void *, size_t) memcpyesque;
|
||||
int strcoll(const char *, const char *) strlenesque;
|
||||
char *strsep(char **, const char *) libcesque paramsnonnull();
|
||||
char *stpcpy(char *, const char *) memcpyesque;
|
||||
char *stpncpy(char *, const char *, size_t) memcpyesque;
|
||||
char *strcat(char *, const char *) memcpyesque;
|
||||
wchar_t *wcscat(wchar_t *, const wchar_t *) memcpyesque;
|
||||
size_t strlcpy(char *, const char *, size_t) libcesque;
|
||||
size_t strlcat(char *, const char *, size_t) libcesque;
|
||||
size_t strxfrm(char *, const char *, size_t) libcesque;
|
||||
char *strcpy(char *, const char *) memcpyesque;
|
||||
wchar_t *wcscpy(wchar_t *, const wchar_t *) memcpyesque;
|
||||
|
@ -91,13 +80,9 @@ char *strncpy(char *, const char *, size_t) memcpyesque;
|
|||
char *strtok(char *, const char *) paramsnonnull((2)) libcesque;
|
||||
char *strtok_r(char *, const char *, char **) paramsnonnull((2, 3));
|
||||
wchar_t *wcstok(wchar_t *, const wchar_t *, wchar_t **) paramsnonnull((2, 3));
|
||||
int strverscmp(const char *, const char *) libcesque;
|
||||
wchar_t *wmemset(wchar_t *, wchar_t, size_t) memcpyesque;
|
||||
wchar_t *wmemcpy(wchar_t *, const wchar_t *, size_t) memcpyesque;
|
||||
wchar_t *wmempcpy(wchar_t *, const wchar_t *, size_t) memcpyesque;
|
||||
wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t) memcpyesque;
|
||||
void *memmem(const void *, size_t, const void *, size_t)
|
||||
libcesque nosideeffect;
|
||||
ssize_t strfmon(char *, size_t, const char *, ...) libcesque;
|
||||
long a64l(const char *) libcesque;
|
||||
char *l64a(long) libcesque;
|
||||
|
@ -131,6 +116,33 @@ char *strerror(int) returnsnonnull dontthrow dontcallback;
|
|||
errno_t strerror_r(int, char *, size_t) libcesque;
|
||||
char *__xpg_strerror_r(int, char *, size_t) libcesque;
|
||||
|
||||
int bcmp(const void *, const void *, size_t) strlenesque;
|
||||
void bcopy(const void *, void *, size_t) memcpyesque;
|
||||
void bzero(void *, size_t) memcpyesque;
|
||||
char *index(const char *, int) strlenesque;
|
||||
char *rindex(const char *, int) strlenesque;
|
||||
|
||||
#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
|
||||
defined(_XOPEN_SOURCE)
|
||||
void *memccpy(void *, const void *, int, size_t) memcpyesque;
|
||||
#endif
|
||||
|
||||
#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
char *strsep(char **, const char *) libcesque paramsnonnull();
|
||||
void explicit_bzero(void *, size_t);
|
||||
size_t strlcpy(char *, const char *, size_t) libcesque;
|
||||
size_t strlcat(char *, const char *, size_t) libcesque;
|
||||
#endif
|
||||
|
||||
#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE)
|
||||
int strverscmp(const char *, const char *) libcesque;
|
||||
char *strchrnul(const char *, int) strlenesque returnsnonnull;
|
||||
char *strcasestr(const char *, const char *) strlenesque;
|
||||
void *memmem(const void *, size_t, const void *, size_t) libcesque;
|
||||
void *memrchr(const void *, int, size_t) strlenesque;
|
||||
void *mempcpy(void *, const void *, size_t) memcpyesque;
|
||||
#endif
|
||||
|
||||
#ifdef _COSMO_SOURCE
|
||||
pureconst uint64_t tpenc(uint32_t) libcesque;
|
||||
char *chomp(char *) libcesque;
|
||||
|
@ -141,6 +153,7 @@ bool32 startswithi(const char *, const char *) strlenesque;
|
|||
bool32 endswith(const char *, const char *) strlenesque;
|
||||
bool32 istext(const void *, size_t) libcesque;
|
||||
bool32 isutf8(const void *, size_t) libcesque;
|
||||
void *wmemrchr(const wchar_t *, wchar_t, size_t) strlenesque;
|
||||
const char *strsignal_r(int, char[21]) returnsnonnull libcesque __wur;
|
||||
char16_t *chomp16(char16_t *) libcesque;
|
||||
size_t strlen16(const char16_t *) strlenesque;
|
||||
|
@ -150,6 +163,7 @@ void *memchr16(const void *, int, size_t) strlenesque;
|
|||
char16_t *strchrnul16(const char16_t *, int) strlenesque returnsnonnull;
|
||||
void *rawmemchr16(const void *, int) strlenesque returnsnonnull;
|
||||
char16_t *strstr16(const char16_t *, const char16_t *) strlenesque;
|
||||
int memcasecmp(const void *, const void *, size_t) strlenesque;
|
||||
int strcmp16(const char16_t *, const char16_t *) strlenesque;
|
||||
int strncmp16(const char16_t *, const char16_t *, size_t) strlenesque;
|
||||
int strcasecmp16(const char16_t *, const char16_t *) strlenesque;
|
||||
|
@ -171,14 +185,9 @@ bool32 wcsstartswith(const wchar_t *, const wchar_t *) strlenesque;
|
|||
bool32 wcsendswith(const wchar_t *, const wchar_t *) strlenesque;
|
||||
char *__join_paths(char *, size_t, const char *, const char *) libcesque __wur;
|
||||
int __mkntpathat(int, const char *, int, char16_t[hasatleast 1024]);
|
||||
wchar_t *wmempcpy(wchar_t *, const wchar_t *, size_t) memcpyesque;
|
||||
#endif /* _COSMO_SOURCE */
|
||||
|
||||
int bcmp(const void *, const void *, size_t) strlenesque;
|
||||
void bcopy(const void *, void *, size_t) memcpyesque;
|
||||
void bzero(void *, size_t) memcpyesque;
|
||||
char *index(const char *, int) strlenesque;
|
||||
char *rindex(const char *, int) strlenesque;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_STR_STR_H_ */
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/str/mb.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
size_t wcrtomb(char *s, wchar_t wc, mbstate_t *st) {
|
||||
if (!s)
|
||||
return 1;
|
||||
if ((unsigned)wc < 0x80) {
|
||||
*s = wc;
|
||||
return 1;
|
||||
} else if (MB_CUR_MAX == 1) {
|
||||
if (!IS_CODEUNIT(wc)) {
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
}
|
||||
*s = wc;
|
||||
return 1;
|
||||
} else if ((unsigned)wc < 0x800) {
|
||||
*s++ = 0xc0 | (wc >> 6);
|
||||
*s = 0x80 | (wc & 0x3f);
|
||||
return 2;
|
||||
} else if ((unsigned)wc < 0xd800 || (unsigned)wc - 0xe000 < 0x2000) {
|
||||
*s++ = 0xe0 | (wc >> 12);
|
||||
*s++ = 0x80 | ((wc >> 6) & 0x3f);
|
||||
*s = 0x80 | (wc & 0x3f);
|
||||
return 3;
|
||||
} else if ((unsigned)wc - 0x10000 < 0x100000) {
|
||||
*s++ = 0xf0 | (wc >> 18);
|
||||
*s++ = 0x80 | ((wc >> 12) & 0x3f);
|
||||
*s++ = 0x80 | ((wc >> 6) & 0x3f);
|
||||
*s = 0x80 | (wc & 0x3f);
|
||||
return 4;
|
||||
}
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/str/mb.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
size_t wcsnrtombs(char *dst, const wchar_t **wcs, size_t wn, size_t n,
|
||||
mbstate_t *st) {
|
||||
const wchar_t *ws = *wcs;
|
||||
size_t cnt = 0;
|
||||
if (!dst)
|
||||
n = 0;
|
||||
while (ws && wn) {
|
||||
char tmp[MB_LEN_MAX] = {0};
|
||||
size_t l = wcrtomb(n < MB_LEN_MAX ? tmp : dst, *ws, 0);
|
||||
if (l == -1) {
|
||||
cnt = -1;
|
||||
break;
|
||||
}
|
||||
if (dst) {
|
||||
if (n < MB_LEN_MAX) {
|
||||
if (l > n)
|
||||
break;
|
||||
memcpy(dst, tmp, l);
|
||||
}
|
||||
dst += l;
|
||||
n -= l;
|
||||
}
|
||||
if (!*ws) {
|
||||
ws = 0;
|
||||
break;
|
||||
}
|
||||
ws++;
|
||||
wn--;
|
||||
cnt += l;
|
||||
}
|
||||
if (dst)
|
||||
*wcs = ws;
|
||||
return cnt;
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/str/mb.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
size_t wcsrtombs(char *s, const wchar_t **ws, size_t n, mbstate_t *st) {
|
||||
const wchar_t *ws2;
|
||||
char buf[4];
|
||||
size_t N = n, l;
|
||||
if (!s) {
|
||||
for (n = 0, ws2 = *ws; *ws2; ws2++) {
|
||||
if (*ws2 >= 0x80u) {
|
||||
l = wcrtomb(buf, *ws2, 0);
|
||||
if (!(l + 1))
|
||||
return -1;
|
||||
n += l;
|
||||
} else
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
while (n >= 4) {
|
||||
if (**ws - 1u >= 0x7fu) {
|
||||
if (!**ws) {
|
||||
*s = 0;
|
||||
*ws = 0;
|
||||
return N - n;
|
||||
}
|
||||
l = wcrtomb(s, **ws, 0);
|
||||
if (!(l + 1))
|
||||
return -1;
|
||||
s += l;
|
||||
n -= l;
|
||||
} else {
|
||||
*s++ = **ws;
|
||||
n--;
|
||||
}
|
||||
(*ws)++;
|
||||
}
|
||||
while (n) {
|
||||
if (**ws - 1u >= 0x7fu) {
|
||||
if (!**ws) {
|
||||
*s = 0;
|
||||
*ws = 0;
|
||||
return N - n;
|
||||
}
|
||||
l = wcrtomb(buf, **ws, 0);
|
||||
if (!(l + 1))
|
||||
return -1;
|
||||
if (l > n)
|
||||
return N - n;
|
||||
wcrtomb(s, **ws, 0);
|
||||
s += l;
|
||||
n -= l;
|
||||
} else {
|
||||
*s++ = **ws;
|
||||
n--;
|
||||
}
|
||||
(*ws)++;
|
||||
}
|
||||
return N;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
|
||||
size_t wcstombs(char *s, const wchar_t *ws, size_t n) {
|
||||
return wcsrtombs(s, &(const wchar_t *){ws}, n, 0);
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/limits.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/mb.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
int wctob(wint_t c) {
|
||||
if (c < 128U)
|
||||
return c;
|
||||
if (MB_CUR_MAX == 1 && IS_CODEUNIT(c))
|
||||
return (unsigned char)c;
|
||||
return EOF;
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/limits.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
int wctomb(char *s, wchar_t wc) {
|
||||
if (!s)
|
||||
return 0;
|
||||
return wcrtomb(s, wc, 0);
|
||||
}
|
|
@ -40,7 +40,6 @@ static char *_mktls_finish(struct CosmoTib **out_tib, char *mem,
|
|||
tib->tib_ftrace = old->tib_ftrace;
|
||||
tib->tib_strace = old->tib_strace;
|
||||
tib->tib_sigmask = old->tib_sigmask;
|
||||
tib->tib_locale = (intptr_t)&__c_dot_utf8_locale;
|
||||
atomic_store_explicit(&tib->tib_tid, -1, memory_order_relaxed);
|
||||
if (out_tib) {
|
||||
*out_tib = tib;
|
||||
|
|
|
@ -69,6 +69,8 @@ enum PosixThreadStatus {
|
|||
|
||||
#define POSIXTHREAD_CONTAINER(e) DLL_CONTAINER(struct PosixThread, list, e)
|
||||
|
||||
typedef struct __locale_struct *locale_t;
|
||||
|
||||
struct PosixThread {
|
||||
int pt_flags; // 0x00: see PT_* constants
|
||||
atomic_int pt_canceled; // 0x04: thread has bad beliefs
|
||||
|
@ -86,6 +88,7 @@ struct PosixThread {
|
|||
uint64_t pt_blkmask;
|
||||
int64_t pt_semaphore;
|
||||
intptr_t pt_iohandle;
|
||||
locale_t pt_locale;
|
||||
void *pt_ioverlap;
|
||||
jmp_buf pt_exiter;
|
||||
pthread_attr_t pt_attr;
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/stack.h"
|
||||
#include "libc/runtime/syslib.internal.h"
|
||||
#include "libc/str/locale.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/auxv.h"
|
||||
#include "libc/sysv/consts/clone.h"
|
||||
|
@ -235,6 +236,7 @@ static errno_t pthread_create_impl(pthread_t *thread,
|
|||
return EAGAIN;
|
||||
}
|
||||
dll_init(&pt->list);
|
||||
pt->pt_locale = &__global_locale;
|
||||
pt->pt_start = start_routine;
|
||||
pt->pt_arg = arg;
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ struct CosmoTib {
|
|||
struct CosmoTib *tib_self; /* 0x00 */
|
||||
struct CosmoFtrace tib_ftracer; /* 0x08 */
|
||||
void *tib_garbages; /* 0x18 */
|
||||
intptr_t tib_locale; /* 0x20 */
|
||||
intptr_t __unused; /* 0x20 */
|
||||
intptr_t tib_pthread; /* 0x28 */
|
||||
struct CosmoTib *tib_self2; /* 0x30 */
|
||||
_Atomic(int32_t) tib_tid; /* 0x38 transitions -1 → tid → 0 */
|
||||
|
|
|
@ -33,11 +33,14 @@ LIBC_X_A_DIRECTDEPS = \
|
|||
LIBC_PROC \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_NT_KERNEL32 \
|
||||
LIBC_NT_ADVAPI32 \
|
||||
LIBC_STDIO \
|
||||
LIBC_SOCK \
|
||||
LIBC_STR \
|
||||
LIBC_SYSV \
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_MUSL
|
||||
THIRD_PARTY_MUSL \
|
||||
THIRD_PARTY_TZ \
|
||||
|
||||
LIBC_X_A_DEPS := \
|
||||
$(call uniq,$(foreach x,$(LIBC_X_A_DIRECTDEPS),$($(x))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue