mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-07 11:48:30 +00:00
Make minor improvements
- Work towards simplifying ape.S startup process - Rewrote ar because it took minutes to build cosmopolitan.a
This commit is contained in:
parent
95bc650be8
commit
aea89fe832
70 changed files with 1037 additions and 456 deletions
|
@ -256,97 +256,6 @@ bool luhn(const char *);
|
|||
|
||||
char *strsignal(int) returnsnonnull libcesque;
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § strings » hooks ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
extern int (*const hook$strcmp16)(const char16_t *, const char16_t *);
|
||||
extern int (*const hook$strncmp16)(const char16_t *, const char16_t *, size_t);
|
||||
extern int (*const hook$wcscmp)(const wchar_t *, const wchar_t *);
|
||||
extern int (*const hook$wcsncmp)(const wchar_t *, const wchar_t *, size_t);
|
||||
#define __STR_HOOK(SYMBOL) hook$##SYMBOL
|
||||
#else
|
||||
#define __STR_HOOK(SYMBOL) SYMBOL
|
||||
#endif /* GNUC && !ANSI */
|
||||
|
||||
/* TODO(jart): Use @gotpcrel. */
|
||||
#undef __STR_HOOK
|
||||
#define __STR_HOOK(SYMBOL) SYMBOL
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § strings » generic typing ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
#if __STDC_VERSION__ + 0 >= 201112
|
||||
|
||||
#define strnlen(s, n) \
|
||||
_Generic(*(s), wchar_t \
|
||||
: wcsnlen, char16_t \
|
||||
: strnlen16, default \
|
||||
: strnlen)(s, n)
|
||||
|
||||
#define strnlen_s(s, n) \
|
||||
_Generic(*(s), wchar_t \
|
||||
: wcsnlen_s, char16_t \
|
||||
: strnlen16_s, default \
|
||||
: strnlen_s)(s, n)
|
||||
|
||||
#define strpbrk(s, c) \
|
||||
_Generic(*(s), wchar_t \
|
||||
: wcspbrk, char16_t \
|
||||
: strpbrk16, default \
|
||||
: strpbrk)(s, c)
|
||||
|
||||
#define strspn(s, c) \
|
||||
_Generic(*(s), wchar_t : wcsspn, char16_t : strspn16, default : strspn)(s, c)
|
||||
|
||||
#define strcspn(s, c) \
|
||||
_Generic(*(s), wchar_t \
|
||||
: wcscspn, char16_t \
|
||||
: strcspn16, default \
|
||||
: strcspn)(s, c)
|
||||
|
||||
/* clang-format off */
|
||||
#define strcmp(s1, s2) \
|
||||
_Generic((s1)[0], \
|
||||
wchar_t: __STR_HOOK(wcscmp), \
|
||||
char16_t: _Generic(*(s2), \
|
||||
char: strcmp16to8, \
|
||||
default: __STR_HOOK(strcmp16)), \
|
||||
default: _Generic(*(s2), \
|
||||
char16_t: strcmp8to16, \
|
||||
default: strcmp))(s1, s2)
|
||||
/* clang-format on */
|
||||
|
||||
#define strncmp(s1, s2, n) \
|
||||
_Generic(*(s1), wchar_t \
|
||||
: __STR_HOOK(wcsncmp), char16_t \
|
||||
: _Generic(*(s2), char \
|
||||
: strncmp16to8, default \
|
||||
: __STR_HOOK(strncmp16)), \
|
||||
default \
|
||||
: _Generic(*(s2), char16_t \
|
||||
: strncmp8to16, default \
|
||||
: strncmp))(s1, s2, n)
|
||||
|
||||
#define strcasecmp(s1, s2) \
|
||||
_Generic(*(s1), wchar_t \
|
||||
: wcscasecmp, char16_t \
|
||||
: strcasecmp16, default \
|
||||
: strcasecmp)(s1, s2)
|
||||
|
||||
#define strncasecmp(s1, s2, n) \
|
||||
_Generic(*(s1), wchar_t \
|
||||
: wcsncasecmp, char16_t \
|
||||
: strncasecmp16, default \
|
||||
: strncasecmp)(s1, s2, n)
|
||||
|
||||
#define chomp(s) \
|
||||
_Generic(*(s), wchar_t : wchomp, char16_t : chomp16, default : chomp)(s)
|
||||
|
||||
#endif /* C11 */
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § strings » optimizations ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
* @see strspn(), strtok_r()
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
size_t(strcspn)(const char *s, const char *reject) {
|
||||
size_t strcspn(const char *s, const char *reject) {
|
||||
size_t i;
|
||||
for (i = 0; s[i]; ++i) {
|
||||
if (HasCharacter(s[i], reject)) {
|
||||
|
|
|
@ -20,9 +20,20 @@
|
|||
#include "libc/nexgen32e/hascharacter.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
#undef strcspn
|
||||
#define char char16_t
|
||||
#define HasCharacter HasCharacter16
|
||||
#define strcspn strcspn16
|
||||
|
||||
#include "libc/str/strcspn.c"
|
||||
/**
|
||||
* Returns prefix length, consisting of chars not in reject.
|
||||
* a.k.a. Return index of first byte that's in charset.
|
||||
*
|
||||
* @param reject is nul-terminated character set
|
||||
* @see strspn(), strtok_r()
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
size_t strcspn16(const char16_t *s, const char16_t *reject) {
|
||||
size_t i;
|
||||
for (i = 0; s[i]; ++i) {
|
||||
if (HasCharacter16(s[i], reject)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -20,9 +20,20 @@
|
|||
#include "libc/nexgen32e/hascharacter.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
#undef strcspn
|
||||
#define char wchar_t
|
||||
#define HasCharacter HasCharacterWide
|
||||
#define strcspn wcscspn
|
||||
|
||||
#include "libc/str/strcspn.c"
|
||||
/**
|
||||
* Returns prefix length, consisting of chars not in reject.
|
||||
* a.k.a. Return index of first byte that's in charset.
|
||||
*
|
||||
* @param reject is nul-terminated character set
|
||||
* @see strspn(), strtok_r()
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
size_t wcscspn(const wchar_t *s, const wchar_t *reject) {
|
||||
size_t i;
|
||||
for (i = 0; s[i]; ++i) {
|
||||
if (HasCharacterWide(s[i], reject)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue