mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-04 19:52:28 +00:00
Make more libc improvements
- Make memmem() faster - Make readdir() thread safe - Remove 64kb limit from mkdeps.com - Add old crypt() function from Musl - Improve new fix-third-party.py tool - Improve libc/isystem/ headers and fix bugs
This commit is contained in:
parent
a8cf0f7e89
commit
6a5717a48f
50 changed files with 3783 additions and 280 deletions
|
@ -1,89 +1,105 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ 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. │
|
||||
│ 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. │
|
||||
│ │
|
||||
│ 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/nexgen32e/gettls.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/unicode/langinfo.h"
|
||||
#include "libc/unicode/locale.h"
|
||||
#include "libc/unicode/nltypes.h"
|
||||
|
||||
static const char c_time[] = "\
|
||||
Sun\0\n\
|
||||
Mon\0\n\
|
||||
Tue\0\n\
|
||||
Wed\0\n\
|
||||
Thu\0\n\
|
||||
Fri\0\n\
|
||||
Sat\0\n\
|
||||
Sunday\0\n\
|
||||
Monday\0\n\
|
||||
Tuesday\0\n\
|
||||
Wednesday\0\n\
|
||||
Thursday\0\n\
|
||||
Friday\0\n\
|
||||
Saturday\0\n\
|
||||
Jan\0\n\
|
||||
Feb\0\n\
|
||||
Mar\0\n\
|
||||
Apr\0\n\
|
||||
May\0\n\
|
||||
Jun\0\n\
|
||||
Jul\0\n\
|
||||
Aug\0\n\
|
||||
Sep\0\n\
|
||||
Oct\0\n\
|
||||
Nov\0\n\
|
||||
Dec\0\n\
|
||||
January\0\n\
|
||||
February\0\n\
|
||||
March\0\n\
|
||||
April\0\n\
|
||||
May\0\n\
|
||||
June\0\n\
|
||||
July\0\n\
|
||||
August\0\n\
|
||||
September\0\n\
|
||||
October\0\n\
|
||||
November\0\n\
|
||||
December\0\n\
|
||||
AM\0\n\
|
||||
PM\0\n\
|
||||
a %b %e %T %Y\0\n\
|
||||
m/%d/%y\0\n\
|
||||
H:%M:%S\0\n\
|
||||
I:%M:%S %p\0\n\
|
||||
0\n\
|
||||
0\n\
|
||||
m/%d/%y\0\n\
|
||||
0123456789\0\n\
|
||||
a %b %e %T %Y\0\n\
|
||||
H:%M:%S";
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
// clang-format off
|
||||
|
||||
static const char c_messages[] = "\
|
||||
^[yY]\0\
|
||||
^[nN]\0\
|
||||
yes\0\
|
||||
no";
|
||||
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_numeric[] = "\
|
||||
.\0\
|
||||
";
|
||||
static const char c_messages[] = "^[yY]\0" "^[nN]\0" "yes\0" "no";
|
||||
static const char c_numeric[] = ".\0" "";
|
||||
|
||||
char *nl_langinfo(int item) {
|
||||
if (item == CODESET) {
|
||||
return "UTF-8";
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
char *nl_langinfo_l(nl_item item, locale_t loc)
|
||||
{
|
||||
int cat = item >> 16;
|
||||
int idx = item & 65535;
|
||||
const char *str;
|
||||
|
||||
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, ((cthread_t)__get_tls())->locale);
|
||||
}
|
||||
|
|
|
@ -17,13 +17,27 @@
|
|||
#define LC_MONETARY_MASK 16
|
||||
#define LC_MESSAGES_MASK 32
|
||||
#define LC_ALL_MASK 0x1fbf
|
||||
#define LOCALE_NAME_MAX 23
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct __locale_struct;
|
||||
#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;
|
||||
|
||||
char *nl_langinfo_l(int, locale_t);
|
||||
char *setlocale(int, const char *);
|
||||
double strtod_l(const char *, char **, locale_t);
|
||||
double wcstod_l(const wchar_t *, wchar_t **, locale_t);
|
||||
|
|
19
libc/unicode/nltypes.h
Normal file
19
libc/unicode/nltypes.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_UNICODE_NLTYPES_H_
|
||||
#define COSMOPOLITAN_LIBC_UNICODE_NLTYPES_H_
|
||||
|
||||
#define NL_SETD 1
|
||||
#define NL_CAT_LOCALE 1
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
typedef int nl_item;
|
||||
typedef void *nl_catd;
|
||||
|
||||
nl_catd catopen(const char *, int);
|
||||
char *catgets(nl_catd, int, int, const char *);
|
||||
int catclose(nl_catd);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_UNICODE_NLTYPES_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue