mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Get LIBC_FMT to build for aarch64
This commit is contained in:
parent
036b9a0002
commit
7e46645193
15 changed files with 482 additions and 618 deletions
|
@ -1,129 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 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 "ape/relocations.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
// Escapes byte for string literal.
|
||||
//
|
||||
// This turns stuff like (char)0xFF into \0377. The returned
|
||||
// string is word-encoded, e.g. '\\'|'0'<<010|'3'<<020|etc.
|
||||
//
|
||||
// @param dil contains byte to escape
|
||||
// @see libc/nexgen32e/cescapec.c
|
||||
_cescapec:
|
||||
.leafprologue
|
||||
.profilable
|
||||
movzbl %dil,%edi
|
||||
lea -7(%rdi),%ecx
|
||||
cmp $85,%cl
|
||||
ja 1f
|
||||
mov $'\\',%eax
|
||||
movzbl %cl,%ecx
|
||||
jmp *_cescapectab(,%rcx,8)
|
||||
.Lanchorpoint:
|
||||
.LBEL: mov $'a',%ah
|
||||
.leafepilogue
|
||||
.LBS: mov $'b',%ah
|
||||
.leafepilogue
|
||||
.LHT: mov $'t',%ah
|
||||
.leafepilogue
|
||||
.LLF: mov $'n',%ah
|
||||
.leafepilogue
|
||||
.LVT: mov $'v',%ah
|
||||
.leafepilogue
|
||||
.LFF: mov $'f',%ah
|
||||
.leafepilogue
|
||||
.LCR: mov $'r',%ah
|
||||
.leafepilogue
|
||||
.LDQ: mov $'\"',%ah
|
||||
.leafepilogue
|
||||
.LSQ: mov $'\'',%ah
|
||||
.leafepilogue
|
||||
.LBSL: mov $'\\',%ah
|
||||
.leafepilogue
|
||||
#ifdef __STRICT_ANSI__
|
||||
.LQM: mov $'?',%ah
|
||||
.leafepilogue
|
||||
#else
|
||||
.LQM:
|
||||
#endif
|
||||
1: mov %edi,%eax
|
||||
lea -0x20(%rax),%ecx
|
||||
cmp $0x5E,%ecx
|
||||
ja 2f
|
||||
.leafepilogue
|
||||
2: and $-64,%eax
|
||||
mov %edi,%ecx
|
||||
and $56,%ecx
|
||||
shl $13,%ecx
|
||||
and $7,%edi
|
||||
shl $24,%edi
|
||||
or %ecx,%edi
|
||||
lea (%rdi,%rax,4),%eax
|
||||
add $'0'<<030|'0'<<020|'0'<<010|'\\',%eax
|
||||
.leafepilogue
|
||||
.endfn _cescapec,globl
|
||||
|
||||
.initro 300,_init_cescapec
|
||||
_cescapectab.ro:
|
||||
.byte 1,.LBEL-.Lanchorpoint
|
||||
.byte 1,.LBS-.Lanchorpoint
|
||||
.byte 1,.LHT-.Lanchorpoint
|
||||
.byte 1,.LLF-.Lanchorpoint
|
||||
.byte 1,.LVT-.Lanchorpoint
|
||||
.byte 1,.LFF-.Lanchorpoint
|
||||
.byte 1,.LCR-.Lanchorpoint
|
||||
.byte 20,1b-.Lanchorpoint
|
||||
.byte 1,.LDQ-.Lanchorpoint
|
||||
.byte '\''-'\"'-1,1b-.Lanchorpoint
|
||||
.byte 1,.LSQ-.Lanchorpoint
|
||||
.byte '?'-'\''-1,1b-.Lanchorpoint
|
||||
.byte 1,.LQM-.Lanchorpoint
|
||||
.byte '\\'-'?'-1,1b-.Lanchorpoint
|
||||
.byte 1,.LBSL-.Lanchorpoint
|
||||
.equ .L_cescapectab.ro.size,.-_cescapectab.ro
|
||||
.org 8 - .L_cescapectab.ro.size % 8 + .
|
||||
.endobj _cescapectab.ro,globl,hidden
|
||||
.previous
|
||||
|
||||
.initbss 300,_init_cescapec
|
||||
_cescapectab:
|
||||
.rept '\\'-7+1
|
||||
.quad 0
|
||||
.endr
|
||||
.endobj _cescapectab
|
||||
.previous
|
||||
|
||||
.init.start 300,_init_cescapec
|
||||
ezlea .Lanchorpoint,dx
|
||||
mov $.L_cescapectab.ro.size/2,%ch
|
||||
0: xor %eax,%eax
|
||||
lodsb
|
||||
mov %al,%cl
|
||||
lodsb
|
||||
add %rdx,%rax
|
||||
1: stosq
|
||||
dec %cl
|
||||
jnz 1b
|
||||
dec %ch
|
||||
jnz 0b
|
||||
.if .L_cescapectab.ro.size % 8
|
||||
add $(8-.L_cescapectab.ro.size%8),%rsi
|
||||
.endif
|
||||
.init.end 300,_init_cescapec
|
56
libc/nexgen32e/cescapec.c
Normal file
56
libc/nexgen32e/cescapec.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*-*- 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 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 │
|
||||
│ 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"
|
||||
|
||||
/**
|
||||
* Converts byte to word-encoded C string literal representation.
|
||||
*/
|
||||
int _cescapec(int c) {
|
||||
switch ((c &= 255)) {
|
||||
case '\a':
|
||||
return '\\' | 'a' << 8;
|
||||
case '\b':
|
||||
return '\\' | 'b' << 8;
|
||||
case '\t':
|
||||
return '\\' | 't' << 8;
|
||||
case '\n':
|
||||
return '\\' | 'n' << 8;
|
||||
case '\v':
|
||||
return '\\' | 'v' << 8;
|
||||
case '\f':
|
||||
return '\\' | 'f' << 8;
|
||||
case '\r':
|
||||
return '\\' | 'r' << 8;
|
||||
case '"':
|
||||
return '\\' | '"' << 8;
|
||||
case '\'':
|
||||
return '\\' | '\'' << 8;
|
||||
case '\\':
|
||||
return '\\' | '\\' << 8;
|
||||
default:
|
||||
if (' ' <= c && c <= '~') {
|
||||
return c;
|
||||
} else {
|
||||
return '\\' | //
|
||||
('0' + (c >> 6)) << 8 | //
|
||||
('0' + ((c >> 3) & 7)) << 16 | //
|
||||
('0' + (c & 7)) << 24;
|
||||
}
|
||||
}
|
||||
}
|
84
libc/nexgen32e/kbase36.c
Normal file
84
libc/nexgen32e/kbase36.c
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*-*- 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 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 │
|
||||
│ 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/tab.internal.h"
|
||||
|
||||
_Alignas(uint8_t) const uint8_t kBase36[256] = {
|
||||
['0'] = 1, //
|
||||
['1'] = 2, //
|
||||
['2'] = 3, //
|
||||
['3'] = 4, //
|
||||
['4'] = 5, //
|
||||
['5'] = 6, //
|
||||
['6'] = 7, //
|
||||
['7'] = 8, //
|
||||
['8'] = 9, //
|
||||
['9'] = 10, //
|
||||
['A'] = 11, //
|
||||
['B'] = 12, //
|
||||
['C'] = 13, //
|
||||
['D'] = 14, //
|
||||
['E'] = 15, //
|
||||
['F'] = 16, //
|
||||
['G'] = 17, //
|
||||
['H'] = 18, //
|
||||
['I'] = 19, //
|
||||
['J'] = 20, //
|
||||
['K'] = 21, //
|
||||
['L'] = 22, //
|
||||
['M'] = 23, //
|
||||
['N'] = 24, //
|
||||
['O'] = 25, //
|
||||
['P'] = 26, //
|
||||
['Q'] = 27, //
|
||||
['R'] = 28, //
|
||||
['S'] = 29, //
|
||||
['T'] = 30, //
|
||||
['U'] = 31, //
|
||||
['V'] = 32, //
|
||||
['W'] = 33, //
|
||||
['X'] = 34, //
|
||||
['Y'] = 35, //
|
||||
['Z'] = 36, //
|
||||
['a'] = 11, //
|
||||
['b'] = 12, //
|
||||
['c'] = 13, //
|
||||
['d'] = 14, //
|
||||
['e'] = 15, //
|
||||
['f'] = 16, //
|
||||
['g'] = 17, //
|
||||
['h'] = 18, //
|
||||
['i'] = 19, //
|
||||
['j'] = 20, //
|
||||
['k'] = 21, //
|
||||
['l'] = 22, //
|
||||
['m'] = 23, //
|
||||
['n'] = 24, //
|
||||
['o'] = 25, //
|
||||
['p'] = 26, //
|
||||
['q'] = 27, //
|
||||
['r'] = 28, //
|
||||
['s'] = 29, //
|
||||
['t'] = 30, //
|
||||
['u'] = 31, //
|
||||
['v'] = 32, //
|
||||
['w'] = 33, //
|
||||
['x'] = 34, //
|
||||
['y'] = 35, //
|
||||
['z'] = 36, //
|
||||
};
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.rodata
|
||||
.balign 16
|
||||
.balign 2
|
||||
|
||||
// ibm cp437 unicode table w/ string literal safety
|
||||
//
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/tab.internal.h"
|
||||
|
||||
const uint8_t kToLower[256] = {
|
||||
_Alignas(uint8_t) const uint8_t kToLower[256] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
|
||||
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
|
||||
28, 29, 30, 31, ' ', '!', '\"', '#', '$', '%', '&', '\'', '(', ')',
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/tab.internal.h"
|
||||
|
||||
const uint8_t kToUpper[256] = {
|
||||
_Alignas(uint8_t) const uint8_t kToUpper[256] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
|
||||
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
|
||||
28, 29, 30, 31, ' ', '!', '\"', '#', '$', '%', '&', '\'', '(', ')',
|
||||
|
|
|
@ -1,142 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 sw=8 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/nexgen32e/x86feature.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
// Returns length of wchar_t string w/ security blankets.
|
||||
//
|
||||
// This is like wcsnlen() except it'll return 0 if (1) RDI is NULL
|
||||
// or (2) a NUL-terminator wasn't found in the first RSI chars.
|
||||
//
|
||||
// @param rdi is a nullable NUL-terminated wchar_t string pointer
|
||||
// @param rsi is the maximum number of chars to consider
|
||||
// @return rax is the number of chars, excluding the NUL
|
||||
wcsnlen_s:
|
||||
.leafprologue
|
||||
.profilable
|
||||
xor %eax,%eax
|
||||
xor %r10d,%r10d
|
||||
test %rdi,%rdi
|
||||
jnz 0f
|
||||
.leafepilogue
|
||||
.endfn wcsnlen_s,globl
|
||||
|
||||
// Returns length of NUL-terminated memory, with limit.
|
||||
//
|
||||
// @param rdi is non-null memory
|
||||
// @param rsi is the maximum number of chars to consider
|
||||
// @return rax is the number of chars, excluding the NUL
|
||||
// @asyncsignalsafe
|
||||
wcsnlen:
|
||||
.leafprologue
|
||||
.profilable
|
||||
or $-1,%r10
|
||||
0: xor %edx,%edx
|
||||
xor %r11d,%r11d
|
||||
mov %rdi,%r8
|
||||
jmp wcssak
|
||||
|
||||
// Returns pointer to first instance of character in range.
|
||||
//
|
||||
// @param rdi is a non-null pointer to memory
|
||||
// @param esi is the search word
|
||||
// @return rax points to word if found, or else undefined behavior
|
||||
rawwmemchr:
|
||||
or $-1,%rdx
|
||||
// fallthrough
|
||||
|
||||
// Returns pointer to first instance of character in range.
|
||||
//
|
||||
// @param rdi is a non-null pointer to memory
|
||||
// @param esi is the int32_t search word (officially wchar_t)
|
||||
// @param rdx is length of memory in chars
|
||||
// @return rax points to word if found or NULL
|
||||
// @asyncsignalsafe
|
||||
wmemchr:.leafprologue
|
||||
.profilable
|
||||
xor %r8,%r8
|
||||
xor %r10,%r10
|
||||
mov %rdx,%rcx
|
||||
mov %esi,%edx
|
||||
mov %esi,%r11d
|
||||
mov %rcx,%rsi
|
||||
// fallthrough
|
||||
|
||||
// Swiss army knife of wchar_t string scanning.
|
||||
// Seven fast functions in one.
|
||||
//
|
||||
// @param rdi is non-null wchar_t string memory
|
||||
// @param rsi is max number of chars to consider
|
||||
// @param edx is search character #1
|
||||
// @param r11d is search character #2
|
||||
// @param r8 is subtracted from result (for length vs. pointer)
|
||||
// @param r9 masks result if r11w is found (for NUL vs. NULL)
|
||||
// @param r10 masks result on chars exhausted (for length v. NULL)
|
||||
// @return rax end pointer after r8/r9/r10 modifications
|
||||
wcssak: lea -4(%rdi),%rax
|
||||
.balign 16
|
||||
1: add $4,%rax
|
||||
sub $1,%rsi
|
||||
jb .Lend
|
||||
test $31,%al
|
||||
jz .Lfast
|
||||
.Lint: mov (%rax),%ecx
|
||||
cmp %ecx,%edx
|
||||
je .Ldone
|
||||
cmp %ecx,%r11d
|
||||
je .Lnul
|
||||
jmp 1b
|
||||
.Ldone: sub %r8,%rax
|
||||
jmp .Lret
|
||||
.Lend: mov %r10,%r9
|
||||
.Lnul: sub %r8,%rax
|
||||
and %r9,%rax
|
||||
.Lret: test %r8,%r8
|
||||
jz 0f
|
||||
shr $2,%rax
|
||||
0: .leafepilogue
|
||||
.Lslow: add $8,%rsi
|
||||
jmp .Lint
|
||||
.Lfast:
|
||||
#if !X86_NEED(AVX2)
|
||||
testb X86_HAVE(AVX2)+kCpuids(%rip)
|
||||
jz .Lint
|
||||
#endif
|
||||
movd %edx,%xmm0
|
||||
movd %r11d,%xmm1
|
||||
vpbroadcastd %xmm0,%ymm0
|
||||
vpbroadcastd %xmm1,%ymm1
|
||||
sub $32,%rax
|
||||
1: add $32,%rax
|
||||
sub $8,%rsi
|
||||
jb .Lslow
|
||||
vmovdqa (%rax),%ymm2
|
||||
vpcmpeqd %ymm0,%ymm2,%ymm3
|
||||
vpcmpeqd %ymm1,%ymm2,%ymm2
|
||||
vpor %ymm3,%ymm2,%ymm2
|
||||
vpmovmskb %ymm2,%ecx
|
||||
bsf %ecx,%ecx
|
||||
je 1b
|
||||
vzeroupper
|
||||
add %rcx,%rax
|
||||
jmp .Lint
|
||||
.endfn wcssak
|
||||
.endfn wmemchr,globl
|
||||
.endfn rawwmemchr,globl
|
||||
.endfn wcsnlen,globl
|
|
@ -16,9 +16,9 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tab.internal.h"
|
||||
|
||||
const signed char kHexToInt[256] = {
|
||||
_Alignas(int8_t) const int8_t kHexToInt[256] = {
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x00
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x10
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x20
|
||||
|
|
|
@ -84,8 +84,6 @@ char *strstr(const char *, const char *) strlenesque;
|
|||
char *strcasestr(const char *, const char *) strlenesque;
|
||||
char16_t *strstr16(const char16_t *, const char16_t *) strlenesque;
|
||||
wchar_t *wcsstr(const wchar_t *, const wchar_t *) strlenesque;
|
||||
void *rawwmemchr(const void *, wchar_t)
|
||||
strlenesque returnsnonnull;
|
||||
int strcmp(const char *, const char *) strlenesque;
|
||||
int strncmp(const char *, const char *, size_t) strlenesque;
|
||||
int strcmp16(const char16_t *, const char16_t *) strlenesque;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- 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,30 +16,21 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
// Base 36 Decoder Table.
|
||||
//
|
||||
// This supports uppercase and lowercase. For encoding, the string
|
||||
// 0123456789abcdefghijklmnopqrstuvwxyz can be used, which linkers
|
||||
// are able to deduplicate.
|
||||
.initbss 300,_init_kBase36
|
||||
kBase36:.zero 256
|
||||
.endobj kBase36,globl,hidden
|
||||
.previous
|
||||
|
||||
.init.start 300,_init_kBase36
|
||||
add $'0',%rdi
|
||||
xor %eax,%eax
|
||||
pushpop 10,%rcx
|
||||
0: inc %eax
|
||||
stosb
|
||||
.loop 0b
|
||||
add $'A'-1-'9',%rdi
|
||||
pushpop 'Z'+1-'A',%rcx
|
||||
0: inc %eax
|
||||
mov %al,0x20(%rdi)
|
||||
stosb
|
||||
.loop 0b
|
||||
add $255-'Z',%rdi
|
||||
.init.end 300,_init_kBase36
|
||||
/**
|
||||
* Returns length of NUL-terminated wide string w/ limit.
|
||||
*
|
||||
* @param s is wide string
|
||||
* @param n is max length (a count of wide characters, not bytes)
|
||||
* @return length in characters
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
size_t wcsnlen(const wchar_t *s, size_t n) {
|
||||
wchar_t *p;
|
||||
if ((p = wmemchr(s, 0, n))) {
|
||||
return p - s;
|
||||
} else {
|
||||
return n;
|
||||
}
|
||||
}
|
32
libc/str/wcsnlen_s.c
Normal file
32
libc/str/wcsnlen_s.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*-*- 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 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 │
|
||||
│ 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"
|
||||
|
||||
/**
|
||||
* Returns length of NUL-terminated wide string w/ limit & blankets.
|
||||
*
|
||||
* @param s is wide string
|
||||
* @param n is max length (a count of wide characters, not bytes)
|
||||
* @return length in characters
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
size_t wcsnlen_s(const wchar_t *s, size_t n) {
|
||||
if (!s) return 0;
|
||||
return wcsnlen(s, n);
|
||||
}
|
|
@ -18,5 +18,17 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
|
||||
int _cescapec2(int c) {
|
||||
/**
|
||||
* Returns pointer to first instance of character in range.
|
||||
*
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n) {
|
||||
size_t i;
|
||||
for (i = 0; i < n; ++i) {
|
||||
if (s[i] == c) {
|
||||
return (void *)(s + i);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue