mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-06 22:43:34 +00:00
Clean up some code
- Use good ELF technique in cosmo_dlopen() - Make strerror() conform more to other libc impls - Introduce __clear_cache() and use it in cosmo_dlopen() - Remove libc/fmt/fmt.h header (trying to kill off LIBC_FMT)
This commit is contained in:
parent
7010a8081e
commit
68c7c9c1e0
244 changed files with 378 additions and 588 deletions
|
@ -17,7 +17,6 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/tty/tty.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/dlopen/dlfcn.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
|
@ -24,6 +23,7 @@
|
|||
* - x86-64 FreeBSD
|
||||
* - x86-64 Windows
|
||||
* - aarch64 Linux w/ Glibc
|
||||
* - aarch64 Linux w/ Musl Libc
|
||||
* - aarch64 MacOS
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#endif
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/hiredis/hiredis.h"
|
||||
|
|
|
@ -62,7 +62,6 @@ Contact: antirez@gmail.com\"\n\
|
|||
#include "libc/calls/termios.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/mem/arraylist2.internal.h"
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/inttypes.h"
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
*/
|
||||
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/magnumstrs.internal.h"
|
||||
#include "libc/mem/alloca.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/gc.h"
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/append.h"
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/calls/termios.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
|
|
@ -122,7 +122,6 @@
|
|||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/log.h"
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/termios.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/append.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include "libc/calls/syscall_support-nt.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/fmt/magnumstrs.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/atomic.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/sigset.internal.h"
|
||||
|
@ -34,8 +35,8 @@
|
|||
#include "libc/elf/struct/phdr.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/nt/dll.h"
|
||||
|
@ -69,11 +70,6 @@
|
|||
* @kudos jacereda for figuring out how to do this
|
||||
*/
|
||||
|
||||
#define XNU_RTLD_LAZY 1
|
||||
#define XNU_RTLD_NOW 2
|
||||
#define XNU_RTLD_LOCAL 4
|
||||
#define XNU_RTLD_GLOBAL 8
|
||||
|
||||
#define AMD_REXB 0x41
|
||||
#define AMD_REXW 0x48
|
||||
#define AMD_MOV_IMM 0xb8
|
||||
|
@ -83,11 +79,16 @@
|
|||
#define ARM_IDX_OFF 21
|
||||
#define ARM_MOV_NEX 0xf2800000u
|
||||
|
||||
#define XNU_RTLD_LAZY 1
|
||||
#define XNU_RTLD_NOW 2
|
||||
#define XNU_RTLD_LOCAL 4
|
||||
#define XNU_RTLD_GLOBAL 8
|
||||
|
||||
#define HELPER \
|
||||
"#include <dlfcn.h>\n\
|
||||
#include <stdio.h>\n\
|
||||
#include <stdlib.h>\n\
|
||||
int main(int argc, char *argv[]) {\n\
|
||||
int main(int argc, char **argv, char **envp) {\n\
|
||||
char *ep;\n\
|
||||
long addr;\n\
|
||||
if (argc != 2) {\n\
|
||||
|
@ -201,7 +202,7 @@ static char *elf_map(int fd, Elf64_Ehdr *ehdr, Elf64_Phdr *phdr, long pagesz,
|
|||
char *interp_path, size_t interp_size) {
|
||||
Elf64_Addr maxva = 0;
|
||||
Elf64_Addr minva = -1;
|
||||
for (Elf64_Phdr *p = phdr; p < &phdr[ehdr->e_phnum]; p++) {
|
||||
for (Elf64_Phdr *p = phdr; p < phdr + ehdr->e_phnum; p++) {
|
||||
if (p->p_type != PT_LOAD) {
|
||||
continue;
|
||||
}
|
||||
|
@ -227,18 +228,31 @@ static char *elf_map(int fd, Elf64_Ehdr *ehdr, Elf64_Phdr *phdr, long pagesz,
|
|||
}
|
||||
continue;
|
||||
}
|
||||
int prot = elf2prot(p->p_flags);
|
||||
Elf64_Addr skew = p->p_vaddr & (pagesz - 1);
|
||||
Elf64_Off off = p->p_offset - skew;
|
||||
if (__sys_mmap(base + p->p_vaddr - skew, skew + p->p_filesz, prot,
|
||||
Elf64_Addr a = p->p_vaddr + p->p_filesz;
|
||||
Elf64_Addr b = (a + (pagesz - 1)) & -pagesz;
|
||||
Elf64_Addr c = p->p_vaddr + p->p_memsz;
|
||||
int prot2 = elf2prot(p->p_flags);
|
||||
int prot1 = prot2;
|
||||
if (b > a) {
|
||||
prot1 |= PROT_WRITE;
|
||||
prot1 &= ~PROT_EXEC;
|
||||
}
|
||||
if (__sys_mmap(base + p->p_vaddr - skew, skew + p->p_filesz, prot1,
|
||||
MAP_FIXED | MAP_PRIVATE, fd, off, off) == MAP_FAILED) {
|
||||
return MAP_FAILED;
|
||||
}
|
||||
Elf64_Addr fend = (p->p_vaddr + p->p_filesz + (pagesz - 1)) & -pagesz;
|
||||
Elf64_Addr mend = p->p_vaddr + p->p_memsz;
|
||||
if (mend > fend && __sys_mmap(base + fend, mend - fend, prot,
|
||||
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1,
|
||||
0, 0) == MAP_FAILED) {
|
||||
if (b > a) {
|
||||
bzero(base + a, b - a);
|
||||
}
|
||||
if (c > b && __sys_mmap(base + b, c - b, prot2,
|
||||
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0,
|
||||
0) == MAP_FAILED) {
|
||||
return MAP_FAILED;
|
||||
}
|
||||
if (prot1 != prot2 &&
|
||||
sys_mprotect(base + p->p_vaddr - skew, skew + p->p_filesz, prot2)) {
|
||||
return MAP_FAILED;
|
||||
}
|
||||
}
|
||||
|
@ -302,14 +316,14 @@ static dontinline void elf_exec(const char *file, char **envp) {
|
|||
// get microprocessor page size
|
||||
long pagesz = getauxval(AT_PAGESZ);
|
||||
|
||||
// load executable
|
||||
// load helper executable into address space
|
||||
struct Loaded prog;
|
||||
char interp_path[256] = {0};
|
||||
if (!elf_load(&prog, file, pagesz, interp_path, sizeof(interp_path))) {
|
||||
return;
|
||||
}
|
||||
|
||||
// load platform libc
|
||||
// load platform c library into address space
|
||||
struct Loaded interp;
|
||||
if (!elf_load(&interp, interp_path, pagesz, 0, 0)) {
|
||||
return;
|
||||
|
@ -343,6 +357,7 @@ static dontinline void elf_exec(const char *file, char **envp) {
|
|||
FormatInt64(address_argument, (uintptr_t)foreign_helper);
|
||||
|
||||
// push auxiliary values
|
||||
// these tell the platform libc how to load the executable
|
||||
*--sp = 0;
|
||||
unsigned long key, val;
|
||||
for (av = (Elf64_auxv_t *)__auxv; (key = av->a_type); ++av) {
|
||||
|
@ -508,7 +523,8 @@ static void *foreign_thunk_sysv(void *func) {
|
|||
if (!(p = code = foreign_alloc(36))) return 0; // 16 + 16 + 4 = 36
|
||||
p = movimm(p, 5, (uintptr_t)func);
|
||||
p = movimm(p, 10, (uintptr_t)foreign_tramp);
|
||||
*(uint32_t *)p = 0xd63f0140; // blr x10
|
||||
*(uint32_t *)p = 0xd61f0140; // br x10
|
||||
__clear_cache(code, p + 4);
|
||||
#else
|
||||
#error "unsupported architecture"
|
||||
#endif
|
||||
|
|
|
@ -34,6 +34,7 @@ LIBC_DLOPEN_A_DIRECTDEPS = \
|
|||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
LIBC_STR \
|
||||
THIRD_PARTY_COMPILER_RT
|
||||
|
||||
LIBC_DLOPEN_A_DEPS := \
|
||||
$(call uniq,$(foreach x,$(LIBC_DLOPEN_A_DIRECTDEPS),$($(x))))
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "libc/dce.h"
|
||||
#include "libc/dns/hoststxt.h"
|
||||
#include "libc/dns/servicestxt.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/pushpop.internal.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include "libc/dns/resolvconf.h"
|
||||
#include "libc/dns/servicestxt.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "libc/cxxabi.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/dns/resolvconf.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/pushpop.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "libc/dns/consts.h"
|
||||
#include "libc/dns/dns.h"
|
||||
#include "libc/dns/hoststxt.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/sock/sock.h"
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
int __xpg_strerror_r(int a, char *b, size_t c) {
|
||||
return strerror_r(a, b, c);
|
||||
char *__xpg_strerror_r(int a, char *b, size_t c) {
|
||||
strerror_r(a, b, c);
|
||||
return b;
|
||||
}
|
||||
|
|
|
@ -41,9 +41,8 @@
|
|||
*/
|
||||
int atoi(const char *s) {
|
||||
int x, c, d;
|
||||
do {
|
||||
c = *s++;
|
||||
} while (c == ' ' || c == '\t');
|
||||
do c = *s++;
|
||||
while (c == ' ' || c == '\t');
|
||||
d = c == '-' ? -1 : 1;
|
||||
if (c == '-' || c == '+') c = *s++;
|
||||
for (x = 0; isdigit(c); c = *s++) {
|
||||
|
|
|
@ -31,9 +31,8 @@
|
|||
long atol(const char *s) {
|
||||
long x;
|
||||
int c, d;
|
||||
do {
|
||||
c = *s++;
|
||||
} while (c == ' ' || c == '\t');
|
||||
do c = *s++;
|
||||
while (c == ' ' || c == '\t');
|
||||
d = c == '-' ? -1 : 1;
|
||||
if (c == '-' || c == '+') c = *s++;
|
||||
for (x = 0; isdigit(c); c = *s++) {
|
||||
|
|
|
@ -72,17 +72,6 @@ imaxdiv_t imaxdiv(intmax_t, intmax_t) pureconst;
|
|||
#define lldiv(num, den) ((lldiv_t){(num) / (den), (num) % (den)})
|
||||
#endif
|
||||
|
||||
#if (__GNUC__ * 100 + __GNUC_MINOR__ >= 406 || defined(__llvm__)) && \
|
||||
!defined(__STRICT_ANSI__) && defined(_COSMO_SOURCE) && \
|
||||
!defined(__COSMOCC__)
|
||||
int128_t i128abs(int128_t)
|
||||
libcesque pureconst;
|
||||
int128_t strtoi128(const char *, char **, int) paramsnonnull((1));
|
||||
uint128_t strtou128(const char *, char **, int) paramsnonnull((1));
|
||||
int128_t wcstoi128(const wchar_t *, wchar_t **, int);
|
||||
uint128_t wcstou128(const wchar_t *, wchar_t **, int);
|
||||
#endif /* gcc 4.6+ */
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_FMT_CONV_H_ */
|
||||
|
|
|
@ -8,7 +8,7 @@ forceinline uint64_t __divmod10(uint64_t __x, unsigned *__r) {
|
|||
*__r = __x % 10;
|
||||
return __x / 10;
|
||||
#else
|
||||
uint128_t __dw;
|
||||
unsigned __int128 __dw;
|
||||
unsigned long long __hi, __rm;
|
||||
__dw = __x;
|
||||
__dw *= 0xcccccccccccccccdull;
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_FMT_FMT_H_
|
||||
#define COSMOPOLITAN_LIBC_FMT_FMT_H_
|
||||
|
||||
#if __SIZEOF_POINTER__ == 8
|
||||
#define POINTER_XDIGITS 12 /* math.log(2**48-1,16) */
|
||||
#else
|
||||
#define POINTER_XDIGITS 8
|
||||
#endif
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
char *fcvt(double, int, int *, int *);
|
||||
char *ecvt(double, int, int *, int *);
|
||||
char *gcvt(double, int, char *);
|
||||
|
||||
#ifdef _COSMO_SOURCE
|
||||
int __vcscanf(int (*)(void *), int (*)(int, void *), void *, const char *,
|
||||
va_list);
|
||||
int __fmt(void *, void *, const char *, va_list);
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_FMT_FMT_H_ */
|
|
@ -76,17 +76,6 @@ o/$(MODE)/libc/fmt/wcstoumax.o: private \
|
|||
CFLAGS += \
|
||||
-Os
|
||||
|
||||
# we can't use compiler magic because:
|
||||
# kprintf() depends on these functions
|
||||
o/$(MODE)/libc/fmt/strerrno.greg.o \
|
||||
o/$(MODE)/libc/fmt/strerrdoc.greg.o \
|
||||
o/$(MODE)/libc/fmt/strerror_wr.greg.o: private \
|
||||
COPTS += \
|
||||
-fpie \
|
||||
-fno-sanitize=all \
|
||||
-fno-stack-protector \
|
||||
-fpatchable-function-entry=0,0
|
||||
|
||||
LIBC_FMT_LIBS = $(foreach x,$(LIBC_FMT_ARTIFACTS),$($(x)))
|
||||
LIBC_FMT_SRCS = $(foreach x,$(LIBC_FMT_ARTIFACTS),$($(x)_SRCS))
|
||||
LIBC_FMT_HDRS = $(foreach x,$(LIBC_FMT_ARTIFACTS),$($(x)_HDRS))
|
||||
|
|
|
@ -41,4 +41,8 @@
|
|||
} \
|
||||
}
|
||||
|
||||
int __vcscanf(int (*)(void *), int (*)(int, void *), void *, const char *,
|
||||
va_list);
|
||||
int __fmt(void *, void *, const char *, va_list);
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_FMT_STRTOL_H_ */
|
|
@ -1,39 +0,0 @@
|
|||
/*-*- 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 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/fmt/conv.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/mem/reverse.internal.h"
|
||||
|
||||
/**
|
||||
* Converts unsigned 64-bit integer to octal string.
|
||||
* @param a needs at least 24 bytes
|
||||
* @return bytes written w/o nul
|
||||
*/
|
||||
dontinline size_t uint64toarray_radix8(uint64_t i, char a[hasatleast 24]) {
|
||||
size_t j;
|
||||
j = 0;
|
||||
do {
|
||||
a[j++] = i % 8 + '0';
|
||||
i /= 8;
|
||||
} while (i > 0);
|
||||
a[j] = '\0';
|
||||
reverse(a, j);
|
||||
return j;
|
||||
}
|
|
@ -17,7 +17,6 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/stdckdint.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/strtol.internal.h"
|
||||
#include "libc/fmt/internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/stdckdint.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/strtol.internal.h"
|
||||
#include "libc/fmt/internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/stdckdint.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/strtol.internal.h"
|
||||
#include "libc/fmt/internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/stdckdint.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/strtol.internal.h"
|
||||
#include "libc/fmt/internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/stdckdint.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*-*- 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 2020 Justine Alexandra Roberts Tunney │
|
||||
│ Copyright 2023 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 │
|
||||
|
@ -16,26 +16,22 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/mem/reverse.internal.h"
|
||||
|
||||
dontinline size_t uint64toarray(uint64_t i, char *a, int r) {
|
||||
size_t j;
|
||||
j = 0;
|
||||
do {
|
||||
a[j++] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i % r];
|
||||
i /= r;
|
||||
} while (i > 0);
|
||||
a[j] = '\0';
|
||||
reverse(a, j);
|
||||
return j;
|
||||
}
|
||||
|
||||
size_t int64toarray(int64_t i, char *a, int r) {
|
||||
if (i < 0) {
|
||||
*a++ = '-';
|
||||
i = -(uint64_t)i;
|
||||
void __clear_cache2(const void *base, const void *end) {
|
||||
#ifdef __aarch64__
|
||||
int icache, dcache;
|
||||
const char *p, *pe = end;
|
||||
static unsigned int ctr_el0 = 0;
|
||||
if (!ctr_el0) asm volatile("mrs\t%0,ctr_el0" : "=r"(ctr_el0));
|
||||
icache = 4 << (ctr_el0 & 15);
|
||||
dcache = 4 << ((ctr_el0 >> 16) & 15);
|
||||
for (p = (const char *)((uintptr_t)base & -dcache); p < pe; p += dcache) {
|
||||
asm volatile("dc\tcvau,%0" : : "r"(p) : "memory");
|
||||
}
|
||||
return uint64toarray(i, a, r);
|
||||
asm volatile("dsb\tish" ::: "memory");
|
||||
for (p = (const char *)((uintptr_t)base & -icache); p < pe; p += icache) {
|
||||
asm volatile("ic\tivau,%0" : : "r"(p) : "memory");
|
||||
}
|
||||
asm volatile("dsb\tish\nisb" ::: "memory");
|
||||
#endif
|
||||
}
|
|
@ -24,7 +24,7 @@
|
|||
* @param p needs at least 12 bytes
|
||||
* @return pointer to nul byte
|
||||
*/
|
||||
privileged dontinline char *FormatUint32(char p[hasatleast 12], uint32_t x) {
|
||||
dontinline char *FormatUint32(char p[hasatleast 12], uint32_t x) {
|
||||
char t;
|
||||
size_t i, a, b;
|
||||
i = 0;
|
||||
|
@ -49,7 +49,7 @@ privileged dontinline char *FormatUint32(char p[hasatleast 12], uint32_t x) {
|
|||
* @param p needs at least 12 bytes
|
||||
* @return pointer to nul byte
|
||||
*/
|
||||
privileged char *FormatInt32(char p[hasatleast 12], int32_t x) {
|
||||
char *FormatInt32(char p[hasatleast 12], int32_t x) {
|
||||
if (x < 0) *p++ = '-', x = -(uint32_t)x;
|
||||
return FormatUint32(p, x);
|
||||
}
|
||||
|
|
|
@ -18,32 +18,18 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/state.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/divmod10.internal.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/fmt/magnumstrs.internal.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/asancodes.h"
|
||||
#include "libc/intrin/asmflag.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/cmpxchg.h"
|
||||
#include "libc/intrin/getenv.internal.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/likely.h"
|
||||
#include "libc/intrin/nomultics.internal.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/alloca.h"
|
||||
#include "libc/nexgen32e/rdtsc.h"
|
||||
#include "libc/nexgen32e/uart.internal.h"
|
||||
#include "libc/nt/createfile.h"
|
||||
|
@ -56,25 +42,21 @@
|
|||
#include "libc/nt/process.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
#include "libc/nt/winsock.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/runtime/memtrack.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/stack.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
#include "libc/stdckdint.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tab.internal.h"
|
||||
#include "libc/str/utf16.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
#include "libc/sysv/consts/auxv.h"
|
||||
#include "libc/sysv/consts/f.h"
|
||||
#include "libc/sysv/consts/fd.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/consts/nr.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/thread/posixthread.internal.h"
|
||||
#include "libc/thread/tls.h"
|
||||
#include "libc/thread/tls2.internal.h"
|
||||
#include "libc/vga/vga.internal.h"
|
||||
|
@ -766,16 +748,9 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
|
|||
break;
|
||||
} else {
|
||||
type = 0;
|
||||
#if defined(SYSDEBUG) && _NTTRACE
|
||||
strerror_r(e, z, sizeof(z));
|
||||
s = z;
|
||||
#else
|
||||
s = _strerrno(e);
|
||||
if (!s) {
|
||||
FormatInt32(z, e);
|
||||
s = z;
|
||||
if (!(s = _strerrno(e))) {
|
||||
s = "EUNKNOWN";
|
||||
}
|
||||
#endif
|
||||
goto FormatString;
|
||||
}
|
||||
}
|
||||
|
@ -1145,8 +1120,7 @@ privileged void kvprintf(const char *fmt, va_list v) {
|
|||
*
|
||||
* Error numbers:
|
||||
*
|
||||
* - `%m` formats error (if strerror_wr if is linked)
|
||||
* - `%m` formats errno number (if strerror_wr isn't linked)
|
||||
* - `%m` formats errno as string
|
||||
* - `% m` formats error with leading space if errno isn't zero
|
||||
* - `%lm` means favor WSAGetLastError() over GetLastError() if linked
|
||||
*
|
||||
|
|
|
@ -17,21 +17,20 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/magnumstrs.internal.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
_Alignas(1) static char strerror_buf[128];
|
||||
|
||||
/**
|
||||
* Converts errno value to string non-reentrantly.
|
||||
* Returns string describing `err`.
|
||||
*
|
||||
* The application shall not modify the string returned.
|
||||
*
|
||||
* @see strerror_r()
|
||||
* @threadunsafe
|
||||
*/
|
||||
char *strerror(int err) {
|
||||
if (IsTiny()) {
|
||||
return (char *)firstnonnull(_strerrno(err), "EUNKNOWN");
|
||||
} else {
|
||||
_Alignas(1) static char buf[512];
|
||||
strerror_r(err, buf, sizeof(buf));
|
||||
return buf;
|
||||
}
|
||||
strerror_r(err, strerror_buf, sizeof(strerror_buf));
|
||||
return strerror_buf;
|
||||
}
|
||||
|
|
|
@ -16,25 +16,61 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#define ShouldUseMsabiAttribute() 1
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/fmt/magnumstrs.internal.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
#include "libc/str/str.h"
|
||||
// clang-format off
|
||||
|
||||
#if defined(SYSDEBUG) && _NTTRACE
|
||||
privileged
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Converts errno value to string.
|
||||
*
|
||||
* @param err is error number or zero if unknown
|
||||
* @return 0 on success, or error code
|
||||
* @return 0 on success, or errno on error
|
||||
* @raise ERANGE if insufficient buffer was available, in which case a
|
||||
* nul-terminated string is still copied to `buf`
|
||||
*/
|
||||
int strerror_r(int err, char *buf, size_t size) {
|
||||
int winerr = IsWindows() ? __imp_GetLastError() : 0;
|
||||
return strerror_wr(err, winerr, buf, size);
|
||||
errno_t strerror_r(int err, char *buf, size_t size) {
|
||||
|
||||
int c;
|
||||
char tmp[32];
|
||||
char *p = buf;
|
||||
char *pe = p + size;
|
||||
|
||||
// copy unix error information
|
||||
const char *msg;
|
||||
if (!err) {
|
||||
msg = "No error information";
|
||||
} else if (!(msg = _strerdoc(err))) {
|
||||
FormatInt32(stpcpy(tmp, "Error "), err);
|
||||
msg = tmp;
|
||||
}
|
||||
while ((c = *msg++) && p + 1 < pe) {
|
||||
*p++ = c;
|
||||
}
|
||||
|
||||
// copy windows error information
|
||||
if (IsWindows()) {
|
||||
uint32_t winerr;
|
||||
if ((winerr = GetLastError()) != err) {
|
||||
stpcpy(FormatUint32(stpcpy(tmp, " (win32 error "), winerr), ")");
|
||||
msg = tmp;
|
||||
while ((c = *msg++) && p + 1 < pe) {
|
||||
*p++ = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// force nul terminator
|
||||
if (p < pe) {
|
||||
*p++ = 0;
|
||||
}
|
||||
|
||||
// return result code
|
||||
if (p < pe) {
|
||||
return 0;
|
||||
} else {
|
||||
return ERANGE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
/*-*- 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 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. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#define ShouldUseMsabiAttribute() 1
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/magnumstrs.internal.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nt/enum/formatmessageflags.h"
|
||||
#include "libc/nt/enum/lang.h"
|
||||
#include "libc/nt/process.h"
|
||||
#include "libc/str/str.h"
|
||||
// clang-format off
|
||||
|
||||
#if defined(SYSDEBUG) && _NTTRACE
|
||||
privileged
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Converts errno value to string with explicit windows errno too.
|
||||
*
|
||||
* @param err is error number or zero if unknown
|
||||
* @return 0 on success, or error code
|
||||
*/
|
||||
int strerror_wr(int err, uint32_t winerr, char *buf, size_t size) {
|
||||
/* kprintf() weakly depends on this function */
|
||||
int c, n;
|
||||
char16_t winmsg[256];
|
||||
const char *sym, *msg;
|
||||
/* wanting = false; */
|
||||
if (!(sym = _strerrno(err))) {
|
||||
sym = "EUNKNOWN";
|
||||
/* wanting = true; */
|
||||
}
|
||||
if (!(msg = _strerdoc(err))) {
|
||||
msg = "No error information";
|
||||
/* wanting = true; */
|
||||
}
|
||||
if (IsTiny()) {
|
||||
if (!sym) sym = "EUNKNOWN";
|
||||
for (; (c = *sym++); --size)
|
||||
if (size > 1) *buf++ = c;
|
||||
if (size) *buf = 0;
|
||||
} else if (!IsWindows() /* || ((err == winerr || !winerr) && !wanting) */) {
|
||||
ksnprintf(buf, size, "%s/%d/%s", sym, err, msg);
|
||||
} else {
|
||||
if ((n = __imp_FormatMessageW(
|
||||
kNtFormatMessageFromSystem | kNtFormatMessageIgnoreInserts, 0,
|
||||
winerr, MAKELANGID(kNtLangNeutral, kNtSublangDefault), winmsg,
|
||||
ARRAYLEN(winmsg), 0))) {
|
||||
while ((n && winmsg[n - 1] <= ' ') || winmsg[n - 1] == '.') --n;
|
||||
ksnprintf(buf, size, "%s/%d/%s/%d/%.*hs", sym, err, msg, winerr, n,
|
||||
winmsg);
|
||||
} else {
|
||||
ksnprintf(buf, size, "%s/%d/%s/%d", sym, err, msg, winerr);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -38,5 +38,5 @@ static char g_strsignal[21];
|
|||
* @threadunsafe
|
||||
*/
|
||||
char *strsignal(int sig) {
|
||||
return strsignal_r(sig, g_strsignal);
|
||||
return (char *)strsignal_r(sig, g_strsignal);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/fmt/magnumstrs.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
|
@ -26,8 +25,7 @@
|
|||
*
|
||||
* This returns `"0"` for 0 which is the empty value. Symbolic names
|
||||
* should be available for signals 1 through 32. If the system supports
|
||||
* real-time signals, they're returned as `SIGRTMIN+%d`. For all other
|
||||
* 32-bit signed integer, a plain integer representation is returned.
|
||||
* real-time signals, they're returned as `SIGRTMIN+%d`.
|
||||
*
|
||||
* @param sig is signal number which should be in range 1 through 128
|
||||
* @param buf may be used to store output having at least 15 bytes
|
||||
|
@ -35,13 +33,14 @@
|
|||
* @see sigaction()
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
privileged char *strsignal_r(int sig, char buf[21]) {
|
||||
privileged const char *strsignal_r(int sig, char buf[21]) {
|
||||
char *p;
|
||||
const char *s;
|
||||
if (!sig) {
|
||||
return "0";
|
||||
}
|
||||
if ((s = GetMagnumStr(kSignalNames, sig))) {
|
||||
return (char *)s;
|
||||
return s;
|
||||
}
|
||||
if (SIGRTMIN <= sig && sig <= SIGRTMAX) {
|
||||
sig -= SIGRTMIN;
|
||||
|
@ -54,9 +53,13 @@ privileged char *strsignal_r(int sig, char buf[21]) {
|
|||
buf[6] = 'I';
|
||||
buf[7] = 'N';
|
||||
buf[8] = '+';
|
||||
FormatInt32(buf + 9, sig);
|
||||
p = buf + 9;
|
||||
} else {
|
||||
FormatInt32(buf, sig);
|
||||
p = buf;
|
||||
}
|
||||
if (sig >= 100) *p++ = '0' + (unsigned char)sig / 100 % 10;
|
||||
if (sig >= 10) *p++ = '0' + (unsigned char)sig / 10 % 10;
|
||||
*p++ = '0' + (unsigned char)sig % 10;
|
||||
*p = 0;
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/pushpop.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define _STDIO_H
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/stdio/dprintf.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/temp.h"
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/dprintf.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/stdlib.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "libc/temp.h"
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/log/color.internal.h"
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
|
@ -32,8 +31,6 @@
|
|||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
__static_yoink("strerror_wr");
|
||||
|
||||
/**
|
||||
* Handles failure of CHECK_xx() macros.
|
||||
*/
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/bsf.h"
|
||||
#include "libc/intrin/cxaatexit.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/log/gdb.h"
|
||||
#include "libc/log/log.h"
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -17,14 +17,13 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/stdio/dprintf.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/dprintf.h"
|
||||
|
||||
static void onmemchunk(void *start, void *end, size_t used_bytes, void *arg) {
|
||||
(dprintf)(*(int *)arg, "%p - %p : %08zx / %08lx\n", start, end, used_bytes,
|
||||
(intptr_t)end - (intptr_t)start);
|
||||
dprintf(*(int *)arg, "%p - %p : %08zx / %08lx\n", start, end, used_bytes,
|
||||
(intptr_t)end - (intptr_t)start);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,7 +31,6 @@ static void onmemchunk(void *start, void *end, size_t used_bytes, void *arg) {
|
|||
*/
|
||||
void _meminfo(int fd) {
|
||||
_memsummary(fd);
|
||||
(dprintf)(fd, "%*s %*s %*s %*s\n", POINTER_XDIGITS, "start",
|
||||
POINTER_XDIGITS, "end", 8, "used", 8, "size");
|
||||
dprintf(fd, "%12s %12s %8s %8s\n", "start", "end", "used", "size");
|
||||
malloc_inspect_all(onmemchunk, &fd);
|
||||
}
|
||||
|
|
|
@ -58,9 +58,6 @@
|
|||
#include "libc/thread/tls.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
__static_yoink("strerror_wr"); // for kprintf %m
|
||||
__static_yoink("strsignal_r"); // for kprintf %G
|
||||
|
||||
#define STACK_ERROR "error: not enough room on stack to print crash report\n"
|
||||
|
||||
static const char kGregOrder[17] forcealign(1) = {
|
||||
|
|
|
@ -51,9 +51,6 @@
|
|||
#include "libc/thread/thread.h"
|
||||
#ifdef __aarch64__
|
||||
|
||||
__static_yoink("strerror_wr"); // for kprintf %m
|
||||
__static_yoink("strsignal_r"); // for kprintf %G
|
||||
|
||||
#define STACK_ERROR "error: not enough room on stack to print crash report\n"
|
||||
|
||||
#define RESET "\e[0m"
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/libgen.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
|
|
18
libc/nt/kernel32/FormatMessageA.S
Normal file
18
libc/nt/kernel32/FormatMessageA.S
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "libc/nt/codegen.h"
|
||||
.imp kernel32,__imp_FormatMessageA,FormatMessageA
|
||||
|
||||
.text.windows
|
||||
.ftrace1
|
||||
FormatMessageA:
|
||||
.ftrace2
|
||||
#ifdef __x86_64__
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
mov __imp_FormatMessageA(%rip),%rax
|
||||
jmp __sysv2nt8
|
||||
#elif defined(__aarch64__)
|
||||
mov x0,#0
|
||||
ret
|
||||
#endif
|
||||
.endfn FormatMessageA,globl
|
||||
.previous
|
|
@ -87,6 +87,7 @@ imp 'FindNextVolume' FindNextVolumeW kernel32 3
|
|||
imp 'FindVolumeClose' FindVolumeClose kernel32 1
|
||||
imp 'FlushConsoleInputBuffer' FlushConsoleInputBuffer kernel32 1
|
||||
imp 'FormatMessage' FormatMessageW kernel32 7
|
||||
imp 'FormatMessageA' FormatMessageA kernel32 7
|
||||
imp 'FreeConsole' FreeConsole kernel32 0
|
||||
imp 'FreeEnvironmentStrings' FreeEnvironmentStringsW kernel32 1
|
||||
imp 'FreeLibrary' FreeLibrary kernel32 1
|
||||
|
|
|
@ -51,6 +51,9 @@ void SetLastError(uint32_t dwErrCode);
|
|||
uint32_t FormatMessage(uint32_t dwFlags, const void *lpSource,
|
||||
uint32_t dwMessageId, uint32_t dwLanguageId,
|
||||
char16_t *lpBuffer, uint32_t nSize, va_list *Arguments);
|
||||
uint32_t FormatMessageA(uint32_t dwFlags, const void *lpSource,
|
||||
uint32_t dwMessageId, uint32_t dwLanguageId,
|
||||
char *lpBuffer, uint32_t nSize, va_list *Arguments);
|
||||
int64_t OpenProcess(uint32_t dwDesiredAccess, bool32 bInheritHandle,
|
||||
uint32_t dwProcessId);
|
||||
uint32_t GetCurrentProcessId(void); /* %gs:0x40 */
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/nexgen32e/gc.internal.h"
|
||||
|
|
|
@ -115,6 +115,7 @@ bool32 _isheap(void *);
|
|||
/* code morphing */
|
||||
void __morph_begin(void);
|
||||
void __morph_end(void);
|
||||
void __clear_cache(void *, void *);
|
||||
/* portability */
|
||||
int NtGetVersion(void) pureconst;
|
||||
bool32 IsGenuineBlink(void);
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/sock/internal.h"
|
||||
#include "libc/sock/sock.h"
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/log/internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include "libc/cxxabi.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
│ Materiel Command, USAF, under agreement number F39502-99-1-0512. │
|
||||
│ SUCH DAMAGE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
│ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF │
|
||||
│ THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
│ Materiel Command, USAF, under agreement number F39502-99-1-0512. │
|
||||
│ SUCH DAMAGE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/struct/fd.internal.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/log.h"
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/mem/internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/struct/iovec.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nt/files.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/internal.h"
|
||||
#include "libc/stdckdint.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/internal.h"
|
||||
|
||||
struct StringScannerState {
|
||||
const unsigned char *s;
|
||||
|
|
12
libc/stdlib.h
Normal file
12
libc/stdlib.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_STDLIB_H_
|
||||
#define COSMOPOLITAN_LIBC_STDLIB_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
char *fcvt(double, int, int *, int *);
|
||||
char *ecvt(double, int, int *, int *);
|
||||
char *gcvt(double, int, char *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_STDLIB_H_ */
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
size_t mbstowcs(wchar_t *pwc, const char *s, size_t wn) {
|
||||
|
|
|
@ -168,10 +168,8 @@ wint_t towctrans(wint_t, wctrans_t);
|
|||
int getsubopt(char **, char *const *, char **) paramsnonnull();
|
||||
char *strsignal(int) returnsnonnull libcesque;
|
||||
char *strerror(int) returnsnonnull dontthrow nocallback;
|
||||
int strerror_r(int, char *, size_t)
|
||||
dontthrow nocallback;
|
||||
int __xpg_strerror_r(int, char *, size_t)
|
||||
dontthrow nocallback;
|
||||
errno_t strerror_r(int, char *, size_t) libcesque;
|
||||
char *__xpg_strerror_r(int, char *, size_t) libcesque;
|
||||
|
||||
#ifdef _COSMO_SOURCE
|
||||
uint64_t tpenc(uint32_t) pureconst;
|
||||
|
@ -183,9 +181,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;
|
||||
char *strsignal_r(int, char[21]) returnsnonnull libcesque __wur;
|
||||
int strerror_wr(int, uint32_t, char *, size_t)
|
||||
dontthrow nocallback;
|
||||
const char *strsignal_r(int, char[21]) returnsnonnull libcesque __wur;
|
||||
char16_t *chomp16(char16_t *) libcesque;
|
||||
size_t strlen16(const char16_t *) strlenesque;
|
||||
size_t strnlen16(const char16_t *, size_t) strlenesque;
|
||||
|
|
|
@ -469,7 +469,7 @@ syscon rlimit RLIMIT_RSS 5 5 5 5 5 5 5 127 # max physical mem
|
|||
syscon rlimit RLIMIT_NPROC 6 6 7 7 7 7 7 127 # max number of processes; see fork()→EAGAIN; bsd consensus
|
||||
syscon rlimit RLIMIT_NOFILE 7 7 8 8 8 8 8 127 # max number of open files; see accept()→EMFILE/ENFILE; bsd consensus
|
||||
syscon rlimit RLIMIT_MEMLOCK 8 8 6 6 6 6 6 127 # max locked-in-memory address space; bsd consensus
|
||||
syscon rlimit RLIMIT_AS 9 9 5 5 10 2 10 0 # max virtual memory size in bytes; this one actually works; fudged as RLIMIT_DATA on OpenBSD
|
||||
syscon rlimit RLIMIT_AS 9\ 9 5 5 10 2 10 0 # max virtual memory size in bytes; this one actually works; fudged as RLIMIT_DATA on OpenBSD
|
||||
syscon rlimit RLIMIT_LOCKS 10 10 127 127 127 127 127 127 # max flock() / fcntl() locks; bsd consensus
|
||||
syscon rlimit RLIMIT_SIGPENDING 11 11 127 127 127 127 127 127 # max sigqueue() can enqueue; bsd consensus
|
||||
syscon rlimit RLIMIT_MSGQUEUE 12 12 127 127 127 127 127 127 # meh posix message queues; bsd consensus
|
||||
|
|
|
@ -80,21 +80,22 @@ COSMOPOLITAN_C_END_
|
|||
* hasn't fleshed them out yet.
|
||||
*
|
||||
* - SIGTHR doesn't have a macro since it's internal to posix threads.
|
||||
*
|
||||
* - SIGSTKFLT is Linux-only so no macro is defined.
|
||||
*/
|
||||
|
||||
#define SIGBUS SIGBUS
|
||||
#define SIGCHLD SIGCHLD
|
||||
#define SIGCONT SIGCONT
|
||||
#define SIGEMT SIGEMT
|
||||
#define SIGINFO SIGINFO
|
||||
#define SIGPWR SIGPWR
|
||||
#define SIGSTKFLT SIGSTKFLT
|
||||
#define SIGSTOP SIGSTOP
|
||||
#define SIGSYS SIGSYS
|
||||
#define SIGTSTP SIGTSTP
|
||||
#define SIGURG SIGURG
|
||||
#define SIGUSR1 SIGUSR1
|
||||
#define SIGUSR2 SIGUSR2
|
||||
#define SIGBUS SIGBUS
|
||||
#define SIGCHLD SIGCHLD
|
||||
#define SIGCONT SIGCONT
|
||||
#define SIGEMT SIGEMT
|
||||
#define SIGINFO SIGINFO
|
||||
#define SIGPWR SIGPWR
|
||||
#define SIGSTOP SIGSTOP
|
||||
#define SIGSYS SIGSYS
|
||||
#define SIGTSTP SIGTSTP
|
||||
#define SIGURG SIGURG
|
||||
#define SIGUSR1 SIGUSR1
|
||||
#define SIGUSR2 SIGUSR2
|
||||
|
||||
#define SIG_BLOCK SIG_BLOCK
|
||||
#define SIG_SETMASK SIG_SETMASK
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/time/struct/tm.h"
|
||||
#include "libc/time/time.h"
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/inttypes.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/locale.h"
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include "libc/calls/internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/*-*- 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 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/fmt/itoa.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(itoa64radix16, test) {
|
||||
char buf[21];
|
||||
EXPECT_EQ(5, uint64toarray_radix16(0x31337, buf));
|
||||
EXPECT_STREQ("31337", buf);
|
||||
EXPECT_EQ(2, uint64toarray_radix16(0x13, buf));
|
||||
EXPECT_STREQ("13", buf);
|
||||
EXPECT_EQ(3, uint64toarray_radix16(0x113, buf));
|
||||
EXPECT_STREQ("113", buf);
|
||||
}
|
||||
|
||||
TEST(itoa64fixed16, test) {
|
||||
char buf[21];
|
||||
EXPECT_EQ(8, uint64toarray_fixed16(0x31337, buf, 32));
|
||||
EXPECT_STREQ("00031337", buf);
|
||||
}
|
|
@ -16,10 +16,9 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
|
@ -30,25 +29,25 @@
|
|||
*/
|
||||
|
||||
TEST(strerror, e2big) {
|
||||
EXPECT_STARTSWITH("E2BIG", strerror(E2BIG));
|
||||
EXPECT_STARTSWITH("Arg list too long", strerror(E2BIG));
|
||||
}
|
||||
|
||||
TEST(strerror, enosys) {
|
||||
EXPECT_STARTSWITH("ENOSYS", strerror(ENOSYS));
|
||||
EXPECT_STARTSWITH("Function not implemented", strerror(ENOSYS));
|
||||
}
|
||||
|
||||
TEST(strerror, einval) {
|
||||
EXPECT_STARTSWITH("EINVAL", strerror(EINVAL));
|
||||
EXPECT_STARTSWITH("Invalid argument", strerror(EINVAL));
|
||||
}
|
||||
|
||||
TEST(strerror, symbolizingTheseNumbersAsErrorsIsHeresyInUnixStyle) {
|
||||
EXPECT_STARTSWITH("EUNKNOWN", strerror(0));
|
||||
EXPECT_STARTSWITH("No error information", strerror(0));
|
||||
}
|
||||
|
||||
TEST(strerror, enotconn_orLinkerIsntUsingLocaleC_orCodeIsOutOfSync) {
|
||||
EXPECT_STARTSWITH("ENOTCONN", strerror(ENOTCONN));
|
||||
EXPECT_STARTSWITH("Transport endpoint is not connected", strerror(ENOTCONN));
|
||||
}
|
||||
|
||||
TEST(strerror, exfull_orLinkerIsntUsingLocaleC_orCodeIsOutOfSync) {
|
||||
EXPECT_STARTSWITH("ETXTBSY", strerror(ETXTBSY));
|
||||
EXPECT_STARTSWITH("Text file busy", strerror(ETXTBSY));
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/libgen.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
|
|
@ -27,9 +27,7 @@ TEST(strsignal, test) {
|
|||
EXPECT_STREQ("SIGALRM", strsignal(SIGALRM));
|
||||
EXPECT_STREQ("SIGUSR1", strsignal(SIGUSR1));
|
||||
EXPECT_STREQ("SIGSTOP", strsignal(SIGSTOP));
|
||||
EXPECT_STREQ("666", strsignal(666));
|
||||
EXPECT_STREQ("-1", strsignal(-1));
|
||||
EXPECT_STREQ("9001", strsignal(9001));
|
||||
EXPECT_STREQ("150", strsignal(150));
|
||||
}
|
||||
|
||||
TEST(strsignal, realtime) {
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "libc/calls/ucontext.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "libc/calls/ucontext.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/sched_param.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue