mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-21 01:50: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
|
@ -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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue