path
stringlengths 14
112
| content
stringlengths 0
6.32M
| size
int64 0
6.32M
| max_lines
int64 1
100k
| repo_name
stringclasses 2
values | autogenerated
bool 1
class |
---|---|---|---|---|---|
cosmopolitan/libc/str/getzipcfiletimestamps.c | /*-*- 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 â
â â
â 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/zip.h"
static inline int pop(int x) {
return !!(x & 1) + !!(x & 2) + !!(x & 4);
}
/**
* Extracts modified/access/creation timestamps from zip entry.
*
* @param cf is pointer to central directory header for file
* @param mtim optionally receives last modified timestamp
* @param atim optionally receives modified timestamp
* @param ctim optionally receives creation timestamp
* @param gmtoff is seconds adjustment for legacy dos timestamps
*/
void GetZipCfileTimestamps(const uint8_t *cf, struct timespec *mtim,
struct timespec *atim, struct timespec *ctim,
int gmtoff) {
const uint8_t *p, *pe;
if (mtim) *mtim = (struct timespec){0};
if (atim) *atim = (struct timespec){0};
if (ctim) *ctim = (struct timespec){0};
for (p = ZIP_CFILE_EXTRA(cf), pe = p + ZIP_CFILE_EXTRASIZE(cf); p + 4 <= pe;
p += ZIP_EXTRA_SIZE(p)) {
if (ZIP_EXTRA_HEADERID(p) == kZipExtraNtfs &&
ZIP_EXTRA_CONTENTSIZE(p) >= 4 + 4 + 8 &&
READ16LE(ZIP_EXTRA_CONTENT(p) + 4) == 1 &&
READ16LE(ZIP_EXTRA_CONTENT(p) + 6) >= 8) {
if (mtim) {
*mtim = WindowsTimeToTimeSpec(READ64LE(ZIP_EXTRA_CONTENT(p) + 8));
}
if (atim && ZIP_EXTRA_CONTENTSIZE(p) >= 4 + 4 + 8 * 2 &&
READ16LE(ZIP_EXTRA_CONTENT(p) + 6) >= 16) {
*atim = WindowsTimeToTimeSpec(READ64LE(ZIP_EXTRA_CONTENT(p) + 8 * 2));
}
if (ctim && ZIP_EXTRA_CONTENTSIZE(p) >= 4 + 4 + 8 * 3 &&
READ16LE(ZIP_EXTRA_CONTENT(p) + 6) >= 24) {
*ctim = WindowsTimeToTimeSpec(READ64LE(ZIP_EXTRA_CONTENT(p) + 8 * 3));
}
return;
}
}
for (p = ZIP_CFILE_EXTRA(cf), pe = p + ZIP_CFILE_EXTRASIZE(cf); p + 4 <= pe;
p += ZIP_EXTRA_SIZE(p)) {
if (ZIP_EXTRA_HEADERID(p) == kZipExtraExtendedTimestamp &&
ZIP_EXTRA_CONTENTSIZE(p) > 1 &&
ZIP_EXTRA_CONTENTSIZE(p) == 1 + 4 * pop(*ZIP_EXTRA_CONTENT(p) & 7)) {
if (mtim) {
if (*ZIP_EXTRA_CONTENT(p) & 1) {
mtim->tv_sec = (int32_t)READ32LE(ZIP_EXTRA_CONTENT(p) + 1);
} else {
mtim->tv_sec = DosDateTimeToUnix(ZIP_CFILE_LASTMODIFIEDDATE(cf),
ZIP_CFILE_LASTMODIFIEDTIME(cf)) -
gmtoff;
}
}
if (atim && (*ZIP_EXTRA_CONTENT(p) & 2)) {
atim->tv_sec = (int32_t)READ32LE(ZIP_EXTRA_CONTENT(p) + 1 +
4 * (*ZIP_EXTRA_CONTENT(p) & 1));
}
if (ctim && (*ZIP_EXTRA_CONTENT(p) & 4)) {
ctim->tv_sec = (int32_t)READ32LE(ZIP_EXTRA_CONTENT(p) + 1 +
4 * pop(*ZIP_EXTRA_CONTENT(p) & 3));
}
return;
}
}
for (p = ZIP_CFILE_EXTRA(cf), pe = p + ZIP_CFILE_EXTRASIZE(cf); p + 4 <= pe;
p += ZIP_EXTRA_SIZE(p)) {
if (ZIP_EXTRA_HEADERID(p) == kZipExtraUnix &&
ZIP_EXTRA_CONTENTSIZE(p) >= 4 + 4) {
if (atim) atim->tv_sec = (int32_t)READ32LE(ZIP_EXTRA_CONTENT(p) + 0);
if (mtim) mtim->tv_sec = (int32_t)READ32LE(ZIP_EXTRA_CONTENT(p) + 4);
return;
}
}
if (mtim) {
mtim->tv_sec = DosDateTimeToUnix(ZIP_CFILE_LASTMODIFIEDDATE(cf),
ZIP_CFILE_LASTMODIFIEDTIME(cf)) -
gmtoff;
}
}
| 5,151 | 102 | jart/cosmopolitan | false |
cosmopolitan/libc/str/lz4check.c | /*-*- 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/nexgen32e/kompressor.h"
#include "libc/nexgen32e/lz4.h"
const unsigned char *lz4check(const void *data) {
const unsigned char *frame = data;
if (LZ4_MAGIC(frame) == LZ4_MAGICNUMBER && LZ4_FRAME_VERSION(frame) == 1 &&
LZ4_FRAME_BLOCKINDEPENDENCE(frame) == true &&
LZ4_FRAME_BLOCKCONTENTSIZEFLAG(frame) == true &&
LZ4_FRAME_RESERVED1(frame) == 0 && LZ4_FRAME_RESERVED2(frame) == 0 &&
LZ4_FRAME_RESERVED3(frame) == 0) {
return frame;
} else {
return NULL;
}
}
| 2,349 | 34 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strxfrm.c | /*-*- 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â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â This is free and unencumbered software released into the public domain. â
â â
â Anyone is free to copy, modify, publish, use, compile, sell, or â
â distribute this software, either in source code form or as a compiled â
â binary, for any purpose, commercial or non-commercial, and by any â
â means. â
â â
â In jurisdictions that recognize copyright laws, the author or authors â
â of this software dedicate any and all copyright interest in the â
â software to the public domain. We make this dedication for the benefit â
â of the public at large and to the detriment of our heirs and â
â successors. We intend this dedication to be an overt act of â
â relinquishment in perpetuity of all present and future rights to this â
â software under copyright law. â
â â
â 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 BE LIABLE FOR ANY CLAIM, DAMAGES OR â
â OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, â
â ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR â
â OTHER DEALINGS IN THE SOFTWARE. â
â â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/assert.h"
#include "libc/str/str.h"
/**
* Transforms strings into current C locale.
* calling strcmp() on two strxfrm()-ed strings
* is same as calling strcoll() on the originals.
*
* @param dest is buffer which needn't be initialized
* @param src is a NUL-terminated string
* @param count is number of bytes to write to destination
* @return length of transformed string
* @note dest and src can't overlap
* @note dest array size should be greater than count
* @note if dest is NULL, count has to be zero
*/
size_t strxfrm(char *dest, const char *src, size_t count) {
_unassert(dest == NULL ? count == 0 : 1);
return strlcpy(dest, src, count);
}
| 3,280 | 48 | jart/cosmopolitan | false |
cosmopolitan/libc/str/islower.c | /*-*- 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/str/str.h"
/**
* Returns nonzero if c is lowercase alpha ascii character.
*/
int islower(int c) {
return 'a' <= c && c <= 'z';
}
| 1,985 | 27 | jart/cosmopolitan | false |
cosmopolitan/libc/str/wcrtomb.c | /*-*- 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â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â â
â Musl Libc â
â Copyright © 2005-2014 Rich Felker, et al. â
â â
â Permission is hereby granted, free of charge, to any person obtaining â
â a copy of this software and associated documentation files (the â
â "Software"), to deal in the Software without restriction, including â
â without limitation the rights to use, copy, modify, merge, publish, â
â distribute, sublicense, and/or sell copies of the Software, and to â
â permit persons to whom the Software is furnished to do so, subject to â
â the following conditions: â
â â
â The above copyright notice and this permission notice shall be â
â included in all copies or substantial portions of the Software. â
â â
â THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, â
â EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF â
â MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. â
â IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY â
â CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, â
â TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE â
â SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. â
â â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/errno.h"
#include "libc/limits.h"
#include "libc/str/mb.internal.h"
#include "libc/str/str.h"
asm(".ident\t\"\\n\\n\
Musl libc (MIT License)\\n\
Copyright 2005-2014 Rich Felker, et. al.\"");
asm(".include \"libc/disclaimer.inc\"");
size_t wcrtomb(char *s, wchar_t wc, mbstate_t *st) {
if (!s) return 1;
if ((unsigned)wc < 0x80) {
*s = wc;
return 1;
} else if (MB_CUR_MAX == 1) {
if (!IS_CODEUNIT(wc)) {
errno = EILSEQ;
return -1;
}
*s = wc;
return 1;
} else if ((unsigned)wc < 0x800) {
*s++ = 0xc0 | (wc >> 6);
*s = 0x80 | (wc & 0x3f);
return 2;
} else if ((unsigned)wc < 0xd800 || (unsigned)wc - 0xe000 < 0x2000) {
*s++ = 0xe0 | (wc >> 12);
*s++ = 0x80 | ((wc >> 6) & 0x3f);
*s = 0x80 | (wc & 0x3f);
return 3;
} else if ((unsigned)wc - 0x10000 < 0x100000) {
*s++ = 0xf0 | (wc >> 18);
*s++ = 0x80 | ((wc >> 12) & 0x3f);
*s++ = 0x80 | ((wc >> 6) & 0x3f);
*s = 0x80 | (wc & 0x3f);
return 4;
}
errno = EILSEQ;
return -1;
}
| 3,641 | 69 | jart/cosmopolitan | false |
cosmopolitan/libc/str/wcscmp.c | /*-*- 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/str/str.h"
/**
* Compares NUL-terminated wide strings.
*
* @param a is first non-null NUL-terminated string pointer
* @param b is second non-null NUL-terminated string pointer
* @return is <0, 0, or >0 based on uint8_t comparison
* @asyncsignalsafe
*/
int wcscmp(const wchar_t *a, const wchar_t *b) {
size_t i = 0;
if (a == b) return 0;
while (a[i] == b[i] && b[i]) ++i;
return (int)a[i] < (int)b[i] ? -1 : (int)a[i] > (int)b[i];
}
| 2,299 | 35 | jart/cosmopolitan | false |
cosmopolitan/libc/str/iswprint_l.c | /*-*- 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. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/locale.h"
#include "libc/str/str.h"
int iswprint_l(wint_t c, locale_t l) {
return iswprint(c);
}
| 1,955 | 25 | jart/cosmopolitan | false |
cosmopolitan/libc/str/blake2.c | /*-*- 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 Google LLC â
â â
â 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/blake2.h"
#include "libc/assert.h"
#include "libc/macros.internal.h"
#include "libc/str/str.h"
#define ROR(v, n) (((v) >> (n)) | ((v) << (64 - (n))))
asm(".ident\t\"\\n\\n\
boringssl blake2b (ISC License)\\n\
Copyright 2021 Google LLC\"");
asm(".include \"libc/disclaimer.inc\"");
// https://tools.ietf.org/html/rfc7693#section-2.6
static const uint64_t kIV[8] = {
0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b,
0xa54ff53a5f1d36f1, 0x510e527fade682d1, 0x9b05688c2b3e6c1f,
0x1f83d9abfb41bd6b, 0x5be0cd19137e2179,
};
// https://tools.ietf.org/html/rfc7693#section-2.7
static const uint8_t kSigma[10][16] = {
// clang-format off
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4},
{7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8},
{9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13},
{2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9},
{12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11},
{13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10},
{6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5},
{10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0},
// clang-format on
};
// https://tools.ietf.org/html/rfc7693#section-3.1
static void Blake2bMix(uint64_t v[16], int a, int b, int c, int d, uint64_t x,
uint64_t y) {
v[a] = v[a] + v[b] + x;
v[d] = ROR(v[d] ^ v[a], 32);
v[c] = v[c] + v[d];
v[b] = ROR(v[b] ^ v[c], 24);
v[a] = v[a] + v[b] + y;
v[d] = ROR(v[d] ^ v[a], 16);
v[c] = v[c] + v[d];
v[b] = ROR(v[b] ^ v[c], 63);
}
static void Blake2bTransform(
struct Blake2b *b2b, const uint64_t w[BLAKE2B_CBLOCK / sizeof(uint64_t)],
size_t num_bytes, int is_final_block) {
// https://tools.ietf.org/html/rfc7693#section-3.2
uint64_t v[16];
_Static_assert(sizeof(v) == sizeof(b2b->h) + sizeof(kIV), "");
memcpy(v, b2b->h, sizeof(b2b->h));
memcpy(&v[8], kIV, sizeof(kIV));
b2b->t_low += num_bytes;
if (b2b->t_low < num_bytes) {
b2b->t_high++;
}
v[12] ^= b2b->t_low;
v[13] ^= b2b->t_high;
if (is_final_block) {
v[14] = ~v[14];
}
for (int i = 0; i < 12; i++) {
Blake2bMix(v, 0, 4, 8, 12, w[kSigma[i % 10][0]], w[kSigma[i % 10][1]]);
Blake2bMix(v, 1, 5, 9, 13, w[kSigma[i % 10][2]], w[kSigma[i % 10][3]]);
Blake2bMix(v, 2, 6, 10, 14, w[kSigma[i % 10][4]], w[kSigma[i % 10][5]]);
Blake2bMix(v, 3, 7, 11, 15, w[kSigma[i % 10][6]], w[kSigma[i % 10][7]]);
Blake2bMix(v, 0, 5, 10, 15, w[kSigma[i % 10][8]], w[kSigma[i % 10][9]]);
Blake2bMix(v, 1, 6, 11, 12, w[kSigma[i % 10][10]], w[kSigma[i % 10][11]]);
Blake2bMix(v, 2, 7, 8, 13, w[kSigma[i % 10][12]], w[kSigma[i % 10][13]]);
Blake2bMix(v, 3, 4, 9, 14, w[kSigma[i % 10][14]], w[kSigma[i % 10][15]]);
}
for (size_t i = 0; i < ARRAYLEN(b2b->h); i++) {
b2b->h[i] ^= v[i];
b2b->h[i] ^= v[i + 8];
}
}
int BLAKE2B256_Init(struct Blake2b *b2b) {
bzero(b2b, sizeof(struct Blake2b));
_Static_assert(sizeof(kIV) == sizeof(b2b->h), "");
memcpy(&b2b->h, kIV, sizeof(kIV));
// https://tools.ietf.org/html/rfc7693#section-2.5
b2b->h[0] ^= 0x01010000 | BLAKE2B256_DIGEST_LENGTH;
return 0;
}
int BLAKE2B256_Process(struct Blake2b *b2b,
const uint64_t data[BLAKE2B_CBLOCK / 8]) {
Blake2bTransform(b2b, data, BLAKE2B_CBLOCK, /*is_final_block=*/0);
return 0;
}
int BLAKE2B256_Update(struct Blake2b *b2b, const void *in_data, size_t len) {
const uint8_t *data = (const uint8_t *)in_data;
size_t todo = sizeof(b2b->block.bytes) - b2b->block_used;
if (todo > len) {
todo = len;
}
if (todo) memcpy(&b2b->block.bytes[b2b->block_used], data, todo);
b2b->block_used += todo;
data += todo;
len -= todo;
if (!len) {
return 0;
}
// More input remains therefore we must have filled |b2b->block|.
_unassert(b2b->block_used == BLAKE2B_CBLOCK);
Blake2bTransform(b2b, b2b->block.words, BLAKE2B_CBLOCK,
/*is_final_block=*/0);
b2b->block_used = 0;
while (len > BLAKE2B_CBLOCK) {
uint64_t block_words[BLAKE2B_CBLOCK / sizeof(uint64_t)];
memcpy(block_words, data, sizeof(block_words));
Blake2bTransform(b2b, block_words, BLAKE2B_CBLOCK, /*is_final_block=*/0);
data += BLAKE2B_CBLOCK;
len -= BLAKE2B_CBLOCK;
}
if (len) memcpy(b2b->block.bytes, data, len);
b2b->block_used = len;
return 0;
}
int BLAKE2B256_Final(struct Blake2b *b2b,
uint8_t out[BLAKE2B256_DIGEST_LENGTH]) {
bzero(&b2b->block.bytes[b2b->block_used],
sizeof(b2b->block.bytes) - b2b->block_used);
Blake2bTransform(b2b, b2b->block.words, b2b->block_used,
/*is_final_block=*/1);
_Static_assert(BLAKE2B256_DIGEST_LENGTH <= sizeof(b2b->h), "");
memcpy(out, b2b->h, BLAKE2B256_DIGEST_LENGTH);
return 0;
}
/**
* Computes blake2b 256bit message digest.
*
* blake2b256 n=0 191 nanoseconds
* blake2b256 n=8 23 ns/byte 40,719 kb/s
* blake2b256 n=31 6 ns/byte 153 mb/s
* blake2b256 n=32 6 ns/byte 158 mb/s
* blake2b256 n=63 3 ns/byte 312 mb/s
* blake2b256 n=64 3 ns/byte 317 mb/s
* blake2b256 n=128 1 ns/byte 640 mb/s
* blake2b256 n=256 1 ns/byte 662 mb/s
* blake2b256 n=22851 1 ns/byte 683 mb/s
*
* @param data is binary memory to hash
* @param len is bytes in `data`
* @param out receives 32 byte binary digest
* @return 0 on success (always successful)
*/
int BLAKE2B256(const void *data, size_t len,
uint8_t out[BLAKE2B256_DIGEST_LENGTH]) {
struct Blake2b ctx;
BLAKE2B256_Init(&ctx);
BLAKE2B256_Update(&ctx, data, len);
BLAKE2B256_Final(&ctx, out);
return 0;
}
| 7,845 | 182 | jart/cosmopolitan | false |
cosmopolitan/libc/str/iswcntrl.c | /*-*- 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/str/str.h"
/**
* Returns nonzero if c is C0 or C1 control code.
*/
int iswcntrl(wint_t c) {
return (0x00 <= c && c <= 0x1F) || (0x7F <= c && c <= 0x9F);
}
| 2,011 | 27 | jart/cosmopolitan | false |
cosmopolitan/libc/str/isgraph.c | /*-*- 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/str/str.h"
/**
* Returns nonzero if c is printable ascii that isn't space.
*/
int isgraph(int c) {
return 0x21 <= c && c <= 0x7E;
}
| 1,988 | 27 | jart/cosmopolitan | false |
cosmopolitan/libc/str/getzipcfileuncompressedsize.c | /*-*- 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 â
â â
â 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/zip.h"
/**
* Returns uncompressed size in bytes from zip central directory header.
*/
uint64_t GetZipCfileUncompressedSize(const uint8_t *z) {
uint64_t x;
const uint8_t *p, *pe;
if ((x = ZIP_CFILE_UNCOMPRESSEDSIZE(z)) == 0xFFFFFFFF) {
for (p = ZIP_CFILE_EXTRA(z), pe = p + ZIP_CFILE_EXTRASIZE(z); p < pe;
p += ZIP_EXTRA_SIZE(p)) {
if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64 &&
0 + 8 <= ZIP_EXTRA_CONTENTSIZE(p)) {
return READ64LE(ZIP_EXTRA_CONTENT(p) + 0);
}
}
}
return x;
}
| 2,387 | 38 | jart/cosmopolitan | false |
cosmopolitan/libc/str/wcspbrk.c | /*-*- 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/nexgen32e/hascharacter.internal.h"
#include "libc/str/str.h"
/**
* Returns pointer to first byte matching any in accept, or NULL.
* @asyncsignalsafe
*/
wchar_t *wcspbrk(const wchar_t *s, const wchar_t *accept) {
size_t i;
if (accept[0]) {
if (!accept[1]) {
return wcschr(s, accept[0]);
} else {
for (i = 0; s[i]; ++i) {
if (HasCharacterWide(s[i], accept)) {
return (/*unconst*/ wchar_t *)&s[i];
}
}
}
}
return NULL;
}
| 2,337 | 41 | jart/cosmopolitan | false |
cosmopolitan/libc/str/mbsinit.c | /*-*- 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 â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/str.h"
int mbsinit(const mbstate_t *t) {
return !t || !*t;
}
| 1,919 | 24 | jart/cosmopolitan | false |
cosmopolitan/libc/str/windowsdurationtotimespec.c | /*-*- 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 â
â â
â 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"
struct timespec WindowsDurationToTimeSpec(int64_t x) {
return (struct timespec){x / HECTONANOSECONDS, x % HECTONANOSECONDS * 100};
}
| 1,999 | 24 | jart/cosmopolitan | false |
cosmopolitan/libc/str/istext.c | /*-*- 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 â
â â
â 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 true if buffer is most likely plaintext.
*/
bool _istext(const void *data, size_t size) {
const unsigned char *p, *pe;
for (p = data, pe = p + size; p < pe; ++p) {
if (*p <= 3) {
return false;
}
}
return true;
}
| 2,113 | 33 | jart/cosmopolitan | false |
cosmopolitan/libc/str/iswlower_l.c | /*-*- 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. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/locale.h"
#include "libc/str/str.h"
int iswlower_l(wint_t c, locale_t l) {
return iswlower(c);
}
| 1,955 | 25 | jart/cosmopolitan | false |
cosmopolitan/libc/str/iswupper_l.c | /*-*- 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. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/locale.h"
#include "libc/str/str.h"
int iswupper_l(wint_t c, locale_t l) {
return iswupper(c);
}
| 1,955 | 25 | jart/cosmopolitan | false |
cosmopolitan/libc/str/str.h | #ifndef COSMOPOLITAN_LIBC_STR_STR_H_
#define COSMOPOLITAN_LIBC_STR_STR_H_
#define INVALID_CODEPOINT 0xfffd
#define _tolower(u) (0040 | (u))
#define _toupper(u) (0137 & (u))
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int isascii(int);
int isspace(int);
int isalpha(int);
int isdigit(int);
int isalnum(int);
int isxdigit(int);
int isprint(int);
int islower(int);
int isupper(int);
int isblank(int);
int iscntrl(int);
int isgraph(int);
int tolower(int);
int ispunct(int);
int toupper(int);
int toascii(int);
int hextoint(int);
int _cescapec(int);
int iswalnum(wint_t);
int iswalpha(wint_t);
int iswblank(wint_t);
int iswcntrl(wint_t);
int iswdigit(wint_t);
int iswgraph(wint_t);
int iswlower(wint_t);
int iswspace(wint_t);
int iswupper(wint_t);
int iswxdigit(wint_t);
int iswpunct(wint_t);
int iswprint(wint_t);
int iswseparator(wint_t);
wint_t towlower(wint_t);
wint_t towupper(wint_t);
void bzero(void *, size_t) memcpyesque;
void *memset(void *, int, size_t) memcpyesque;
void *memmove(void *, const void *, size_t) memcpyesque;
void *memcpy(void *restrict, const void *restrict, size_t) memcpyesque;
void *mempcpy(void *restrict, const void *restrict, size_t) memcpyesque;
char *hexpcpy(char *restrict, const void *restrict, size_t) memcpyesque;
void *memccpy(void *restrict, const void *restrict, int, size_t) memcpyesque;
void bcopy(const void *, void *, size_t) memcpyesque;
void explicit_bzero(void *, size_t);
int bcmp(const void *, const void *, size_t) strlenesque;
int memcmp(const void *, const void *, size_t) strlenesque;
int timingsafe_bcmp(const void *, const void *, size_t);
int timingsafe_memcmp(const void *, const void *, size_t);
size_t strlen(const char *) strlenesque;
size_t strnlen(const char *, size_t) strlenesque;
size_t strnlen_s(const char *, size_t);
char *strchr(const char *, int) strlenesque;
char *index(const char *, int) strlenesque;
void *memchr(const void *, int, size_t) strlenesque;
char *strchrnul(const char *, int) strlenesque returnsnonnull;
void *rawmemchr(const void *, int) strlenesque returnsnonnull;
size_t strlen16(const char16_t *) strlenesque;
size_t strnlen16(const char16_t *, size_t) strlenesque;
char16_t *strchr16(const char16_t *, int) strlenesque;
void *memchr16(const void *, int, size_t) strlenesque;
char16_t *strchrnul16(const char16_t *, int) strlenesque returnsnonnull;
void *rawmemchr16(const void *, int) strlenesque returnsnonnull;
size_t wcslen(const wchar_t *) strlenesque;
size_t wcsnlen(const wchar_t *, size_t) strlenesque;
size_t wcsnlen_s(const wchar_t *, size_t);
wchar_t *wcschr(const wchar_t *, wchar_t) strlenesque;
wchar_t *wmemchr(const wchar_t *, wchar_t, size_t) strlenesque;
wchar_t *wcschrnul(const wchar_t *, wchar_t)
strlenesque returnsnonnull;
char *strstr(const char *, const char *) strlenesque;
char *strcasestr(const char *, const char *) strlenesque;
char16_t *strstr16(const char16_t *, const char16_t *) strlenesque;
wchar_t *wcsstr(const wchar_t *, const wchar_t *) strlenesque;
int strcmp(const char *, const char *) strlenesque;
int strncmp(const char *, const char *, size_t) strlenesque;
int strcmp16(const char16_t *, const char16_t *) strlenesque;
int strncmp16(const char16_t *, const char16_t *, size_t) strlenesque;
int wcscmp(const wchar_t *, const wchar_t *) strlenesque;
int wcsncmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
int wmemcmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
int strcasecmp(const char *, const char *) strlenesque;
int memcasecmp(const void *, const void *, size_t) strlenesque;
int strcasecmp16(const char16_t *, const char16_t *) strlenesque;
int wcscasecmp(const wchar_t *, const wchar_t *) strlenesque;
int strncasecmp(const char *, const char *, size_t) strlenesque;
int strncasecmp16(const char16_t *, const char16_t *, size_t) strlenesque;
int wcsncasecmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
char *strrchr(const char *, int) strlenesque;
void *memrchr(const void *, int, size_t) strlenesque;
char16_t *strrchr16(const char16_t *, int) strlenesque;
void *memrchr16(const void *, int, size_t) strlenesque;
wchar_t *wcsrchr(const wchar_t *, wchar_t) strlenesque;
void *wmemrchr(const wchar_t *, wchar_t, size_t) strlenesque;
char *strpbrk(const char *, const char *) strlenesque;
char16_t *strpbrk16(const char16_t *, const char16_t *) strlenesque;
wchar_t *wcspbrk(const wchar_t *, const wchar_t *) strlenesque;
size_t strspn(const char *, const char *) strlenesque;
size_t strspn16(const char16_t *, const char16_t *) strlenesque;
size_t wcsspn(const wchar_t *, const wchar_t *) strlenesque;
size_t strcspn(const char *, const char *) strlenesque;
size_t strcspn16(const char16_t *, const char16_t *) strlenesque;
size_t wcscspn(const wchar_t *, const wchar_t *) strlenesque;
void *memfrob(void *, size_t) memcpyesque;
int strcoll(const char *, const char *) strlenesque;
char *strsep(char **, const char *) paramsnonnull();
int strcmpzbw(const uint16_t *, const char *) strlenesque;
int strcasecmpzbw(const uint16_t *, const char *) strlenesque;
char *stpcpy(char *, const char *) memcpyesque;
char *stpncpy(char *, const char *, size_t) memcpyesque;
char *strcat(char *, const char *) memcpyesque;
char16_t *strcat16(char16_t *, const char16_t *) memcpyesque;
wchar_t *wcscat(wchar_t *, const wchar_t *) memcpyesque;
size_t strlcpy(char *, const char *, size_t);
size_t strlcat(char *, const char *, size_t);
size_t strxfrm(char *, const char *, size_t);
char *strcpy(char *, const char *) memcpyesque;
char16_t *strcpy16(char16_t *, const char16_t *) memcpyesque;
wchar_t *wcscpy(wchar_t *, const wchar_t *) memcpyesque;
char *strncat(char *, const char *, size_t) memcpyesque;
char16_t *strncat16(char16_t *, const char16_t *, size_t) memcpyesque;
wchar_t *wcsncat(wchar_t *, const wchar_t *, size_t) memcpyesque;
char *strncpy(char *, const char *, size_t) memcpyesque;
char *strtok(char *, const char *) paramsnonnull((2)) libcesque;
char *strtok_r(char *, const char *, char **) paramsnonnull((2, 3));
wchar_t *wcstok(wchar_t *, const wchar_t *, wchar_t **) paramsnonnull((2, 3));
char *wstrtrunc(uint16_t *) memcpyesque;
char *wstrntrunc(uint16_t *, size_t) memcpyesque;
bool _startswith(const char *, const char *) strlenesque;
bool _startswithi(const char *, const char *) strlenesque;
bool _startswith16(const char16_t *, const char16_t *) strlenesque;
bool _wcsstartswith(const wchar_t *, const wchar_t *) strlenesque;
bool _endswith(const char *, const char *) strlenesque;
bool _endswith16(const char16_t *, const char16_t *) strlenesque;
bool _wcsendswith(const wchar_t *, const wchar_t *) strlenesque;
const char *IndexDoubleNulString(const char *, unsigned) strlenesque;
int strverscmp(const char *, const char *);
wchar_t *wmemset(wchar_t *, wchar_t, size_t) memcpyesque;
char16_t *memset16(char16_t *, char16_t, size_t) memcpyesque;
wchar_t *wmemcpy(wchar_t *, const wchar_t *, size_t) memcpyesque;
wchar_t *wmempcpy(wchar_t *, const wchar_t *, size_t) memcpyesque;
wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t) memcpyesque;
void *tinymemccpy(void *, const void *, int, size_t) memcpyesque;
void *memmem(const void *, size_t, const void *, size_t)
libcesque nosideeffect;
ssize_t strfmon(char *, size_t, const char *, ...);
long a64l(const char *);
char *l64a(long);
char *strntolower(char *, size_t) libcesque;
char *strtolower(char *) libcesque paramsnonnull();
char *strntoupper(char *, size_t) libcesque;
char *strtoupper(char *) libcesque paramsnonnull();
char *_chomp(char *) libcesque;
char16_t *_chomp16(char16_t *) libcesque;
wchar_t *_wchomp(wchar_t *) libcesque;
bool _istext(const void *, size_t) libcesque;
bool _isutf8(const void *, size_t) libcesque;
bool _escapedos(char16_t *, unsigned, const char16_t *, unsigned) libcesque;
typedef unsigned mbstate_t;
axdx_t tprecode8to16(char16_t *, size_t, const char *);
axdx_t tprecode16to8(char *, size_t, const char16_t *);
wchar_t *wcsncpy(wchar_t *, const wchar_t *, size_t);
int mbtowc(wchar_t *, const char *, size_t);
size_t mbrtowc(wchar_t *, const char *, size_t, mbstate_t *);
size_t mbsrtowcs(wchar_t *, const char **, size_t, mbstate_t *);
size_t mbstowcs(wchar_t *, const char *, size_t);
size_t wcrtomb(char *, wchar_t, mbstate_t *);
size_t c32rtomb(char *, char32_t, mbstate_t *);
size_t mbrtoc32(char32_t *, const char *, size_t, mbstate_t *);
size_t c16rtomb(char *, char16_t, mbstate_t *);
size_t mbrtoc16(char16_t *, const char *, size_t, mbstate_t *);
size_t mbrlen(const char *, size_t, mbstate_t *);
size_t mbsnrtowcs(wchar_t *, const char **, size_t, size_t, mbstate_t *);
size_t wcsnrtombs(char *, const wchar_t **, size_t, size_t, mbstate_t *);
size_t wcsrtombs(char *, const wchar_t **, size_t, mbstate_t *);
size_t wcstombs(char *, const wchar_t *, size_t);
int mbsinit(const mbstate_t *);
int mblen(const char *, size_t);
int wctomb(char *, wchar_t);
int wctob(wint_t);
wint_t btowc(int);
typedef unsigned wctype_t;
wctype_t wctype(const char *) strlenesque;
int iswctype(wint_t, wctype_t) pureconst;
typedef const int *wctrans_t;
wctrans_t wctrans(const char *);
wint_t towctrans(wint_t, wctrans_t);
char *strsignal(int) returnsnonnull libcesque;
char *strsignal_r(int, char[hasatleast 15]) returnsnonnull libcesque;
char *strerror(int) returnsnonnull dontthrow nocallback;
int strerror_r(int, char *, size_t)
dontthrow nocallback;
int strerror_wr(int, uint32_t, char *, size_t)
dontthrow nocallback;
char *_strerrno(int) nosideeffect libcesque;
char *_strerdoc(int) nosideeffect libcesque;
int __xpg_strerror_r(int, char *, size_t)
dontthrow nocallback;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_STR_STR_H_ */
| 9,688 | 221 | jart/cosmopolitan | false |
cosmopolitan/libc/str/index.c | /*-*- 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 â
â â
â 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 pointer to first instance of character, the BSD way.
*
* @param s is a NUL-terminated string
* @param is masked with 255 as byte to search for
* @return is pointer to first instance of c or NULL if not found,
* noting that c being NUL will return a pointer to terminator
*/
char *index(const char *s, int c) {
return strchr(s, c);
}
| 2,223 | 32 | jart/cosmopolitan | false |
cosmopolitan/libc/str/locale.h | #ifndef COSMOPOLITAN_LIBC_STR_LOCALE_H_
#define COSMOPOLITAN_LIBC_STR_LOCALE_H_
#include "libc/fmt/conv.h"
#include "libc/time/struct/tm.h"
#define LC_CTYPE 0
#define LC_NUMERIC 1
#define LC_CTYPE_MASK 1
#define LC_TIME 2
#define LC_NUMERIC_MASK 2
#define LC_COLLATE 3
#define LC_MONETARY 4
#define LC_TIME_MASK 4
#define LC_MESSAGES 5
#define LC_ALL 6
#define LC_COLLATE_MASK 8
#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_
#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);
float strtof_l(const char *, char **, locale_t);
float wcstof_l(const wchar_t *, wchar_t **, locale_t);
int isdigit_l(int, locale_t);
int islower_l(int, locale_t);
int isupper_l(int, locale_t);
int iswalpha_l(wint_t, locale_t);
int iswblank_l(wint_t, locale_t);
int iswcntrl_l(wint_t, locale_t);
int iswdigit_l(wint_t, locale_t);
int iswlower_l(wint_t, locale_t);
int iswprint_l(wint_t, locale_t);
int iswpunct_l(wint_t, locale_t);
int iswspace_l(wint_t, locale_t);
int iswupper_l(wint_t, locale_t);
int iswxdigit_l(wint_t, locale_t);
int isxdigit_l(int, locale_t);
int strcoll_l(const char *, const char *, locale_t);
int tolower_l(int, locale_t);
int toupper_l(int, locale_t);
int wcscoll_l(const wchar_t *, const wchar_t *, locale_t);
locale_t duplocale(locale_t);
locale_t newlocale(int, const char *, locale_t);
locale_t uselocale(locale_t);
long double strtold_l(const char *, char **, locale_t);
long double wcstold_l(const wchar_t *, wchar_t **, locale_t);
long long strtoll_l(const char *, char **, int, locale_t);
long long wcstoll_l(const wchar_t *, wchar_t **, int, locale_t);
size_t strftime_l(char *, size_t, char const *, struct tm const *, locale_t);
size_t strxfrm_l(char *, const char *, size_t, locale_t);
size_t wcsxfrm_l(wchar_t *, const wchar_t *, size_t, locale_t);
unsigned long long strtoull_l(const char *, char **, int, locale_t);
unsigned long long wcstoull_l(const wchar_t *, wchar_t **, int, locale_t);
void freelocale(locale_t);
wint_t towlower_l(wint_t, locale_t);
wint_t towupper_l(wint_t, locale_t);
int strcasecmp_l(const char *, const char *, locale_t);
int strncasecmp_l(const char *, const char *, size_t, locale_t);
ssize_t strfmon_l(char *, size_t, locale_t, const char *, ...);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_STR_LOCALE_H_ */
| 2,909 | 86 | jart/cosmopolitan | false |
cosmopolitan/libc/str/isdigit.c | /*-*- 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/str/str.h"
/**
* Returns nonzero if c is decimal digit.
*/
int isdigit(int c) {
return '0' <= c && c <= '9';
}
| 1,967 | 27 | jart/cosmopolitan | false |
cosmopolitan/libc/str/memrchr16.c | /*-*- 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 â
â â
â 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/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/str/str.h"
typedef char16_t xmm_t __attribute__((__vector_size__(16), __aligned__(2)));
static inline const char16_t *memrchr16_pure(const char16_t *s, char16_t c,
size_t n) {
size_t i;
for (i = n; i--;) {
if (s[i] == c) {
return s + i;
}
}
return 0;
}
#ifdef __x86_64__
noasan static inline const char16_t *memrchr16_sse(const char16_t *s,
char16_t c, size_t n) {
size_t i;
unsigned k, m;
xmm_t v, t = {c, c, c, c, c, c, c, c};
for (i = n; i >= 8;) {
v = *(const xmm_t *)(s + (i -= 8));
m = __builtin_ia32_pmovmskb128(v == t);
if (m) {
m = __builtin_clzl(m) ^ (sizeof(long) * CHAR_BIT - 1);
return s + i + m / 2;
}
}
while (i--) {
if (s[i] == c) {
return s + i;
}
}
return 0;
}
#endif
/**
* Returns pointer to first instance of character.
*
* @param s is memory to search
* @param c is search byte which is masked with 65535
* @param n is number of char16_t elements in `s`
* @return is pointer to first instance of c or NULL if not found
* @asyncsignalsafe
*/
void *memrchr16(const void *s, int c, size_t n) {
#ifdef __x86_64__
const void *r;
if (!IsTiny() && X86_HAVE(SSE)) {
if (IsAsan()) __asan_verify(s, n * 2);
r = memrchr16_sse(s, c, n);
} else {
r = memrchr16_pure(s, c, n);
}
return (void *)r;
#else
return memrchr16_pure(s, c, n);
#endif
}
| 3,414 | 83 | jart/cosmopolitan | false |
cosmopolitan/libc/str/isblank.c | /*-*- 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/str/str.h"
/**
* Returns nonzero if c is space or tab.
*/
int isblank(int c) {
return c == ' ' || c == '\t';
}
| 1,967 | 27 | jart/cosmopolitan | false |
cosmopolitan/libc/str/windowsdurationtotimeval.c | /*-*- 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 â
â â
â 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"
struct timeval WindowsDurationToTimeVal(int64_t x) {
return (struct timeval){x / HECTONANOSECONDS, x % HECTONANOSECONDS / 10};
}
| 1,995 | 24 | jart/cosmopolitan | false |
cosmopolitan/libc/str/iswspace.c | /*-*- 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/str/str.h"
/**
* Returns nonzero if c is space character.
*
* We define this as invisible characters which move the cursor. That
* means `\t\r\n\f\v` and unicodes whose category begins with `Z` but
* not ogham since it's not invisible and non-breaking spaces neither
* since they're not invisible to emacs users.
*/
int iswspace(wint_t c) {
switch (c) {
case '\t': // CHARACTER TABULATION
case '\n': // LINE FEED
case '\f': // FORM FEED
case '\v': // LINE TABULATION
case '\r': // CARRIAGE RETURN
case ' ': // SPACE
case 0x2000: // EN QUAD (Zs)
case 0x2001: // EM QUAD (Zs)
case 0x2002: // EN SPACE (Zs)
case 0x2003: // EM SPACE (Zs)
case 0x2004: // THREE-PER-EM SPACE (Zs)
case 0x2005: // FOUR-PER-EM SPACE (Zs)
case 0x2006: // SIX-PER-EM SPACE (Zs)
case 0x2007: // FIGURE SPACE (Zs)
case 0x2008: // PUNCTUATION SPACE (Zs)
case 0x2009: // THIN SPACE (Zs)
case 0x200a: // HAIR SPACE (Zs)
case 0x2028: // LINE SEPARATOR (Zl)
case 0x2029: // PARAGRAPH SEPARATOR (Zp)
case 0x205f: // MEDIUM MATHEMATICAL SPACE (Zs)
case 0x3000: // IDEOGRAPHIC SPACE (Zs)
return 1;
default:
return 0;
}
}
| 3,081 | 57 | jart/cosmopolitan | false |
cosmopolitan/libc/str/wmemcpy.c | /*-*- 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/str/str.h"
wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t count) {
size_t bytes;
if (__builtin_mul_overflow(count, sizeof(wchar_t), &bytes)) bytes = -1;
return memcpy(dest, src, bytes);
}
| 2,058 | 26 | jart/cosmopolitan | false |
cosmopolitan/libc/str/wcsncmp.c | /*-*- 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/str/str.h"
/**
* Compares NUL-terminated wide strings w/ limit.
*
* @param a is first non-null NUL-terminated string pointer
* @param b is second non-null NUL-terminated string pointer
* @return is <0, 0, or >0 based on uint8_t comparison
* @asyncsignalsafe
*/
int wcsncmp(const wchar_t *a, const wchar_t *b, size_t n) {
size_t i = 0;
if (!n-- || a == b) return 0;
while (i < n && a[i] == b[i] && b[i]) ++i;
return (int)a[i] < (int)b[i] ? -1 : (int)a[i] > (int)b[i];
}
| 2,336 | 35 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strtok.c | /*-*- 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/str/str.h"
/**
* Extracts non-empty tokens from string.
*
* @param s is mutated and should be NULL on subsequent calls
* @param sep is a NUL-terminated set of bytes to consider separators
* @return pointer to next token or NULL for end
* @see strtok_r() and strsep() for superior functions
* @notasyncsignalsafe
*/
char *strtok(char *s, const char *sep) {
static char *state;
return strtok_r(s, sep, &state);
}
| 2,275 | 34 | jart/cosmopolitan | false |
cosmopolitan/libc/str/towlower_l.c | /*-*- 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. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/locale.h"
#include "libc/str/str.h"
wint_t towlower_l(wint_t c, locale_t l) {
return towlower(c);
}
| 1,958 | 25 | jart/cosmopolitan | false |
cosmopolitan/libc/str/mb.internal.h | #ifndef COSMOPOLITAN_LIBC_STR_MB_INTERNAL_H_
#define COSMOPOLITAN_LIBC_STR_MB_INTERNAL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define SA 0xc2u
#define SB 0xf4u
#define CODEUNIT(c) (0xdfff & (signed char)(c))
#define IS_CODEUNIT(c) ((unsigned)(c)-0xdf80 < 0x80)
#define R(a, b) ((uint32_t)((a == 0x80 ? 0x40u - b : 0u - a) << 23))
#define FAILSTATE R(0x80, 0x80)
#define OOB(c, b) \
(((((b) >> 3) - 0x10) | (((b) >> 3) + ((int32_t)(c) >> 26))) & ~7)
extern const uint32_t kMbBittab[51];
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_STR_MB_INTERNAL_H_ */
| 671 | 20 | jart/cosmopolitan | false |
cosmopolitan/libc/str/iswupper.c | /*-*- 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/str/str.h"
/**
* Returns nonzero if c is uppercase letter.
*/
int iswupper(wint_t c) {
int r;
if (c < 0200) {
return 'A' <= c && c <= 'Z';
} else {
if (towlower(c) != c) return 1;
switch (c) {
case 0x03d2: /* Ï Greek */
case 0x03d3: /* Ï Greek */
case 0x03d4: /* Ï Greek */
case 0x2102: /* â Letterlike */
case 0x2107: /* â Letterlike */
case 0x210b: /* â Letterlike */
case 0x210c: /* â Letterlike */
case 0x210d: /* â Letterlike */
case 0x2110: /* â Letterlike */
case 0x2111: /* â Letterlike */
case 0x2112: /* â Letterlike */
case 0x2115: /* â Letterlike */
case 0x2119: /* â Letterlike */
case 0x211a: /* â Letterlike */
case 0x211b: /* â Letterlike */
case 0x211c: /* â Letterlike */
case 0x211d: /* â Letterlike */
case 0x2124: /* ⤠Letterlike */
case 0x2128: /* ⨠Letterlike */
case 0x212c: /* ⬠Letterlike */
case 0x212d: /* â Letterlike */
case 0x2130: /* â° Letterlike */
case 0x2131: /* â± Letterlike */
case 0x2133: /* â³ Letterlike */
case 0x213e: /* â¾ Letterlike */
case 0x213f: /* â¿ Letterlike */
case 0x2145: /* â
Letterlike */
case 0x1d434: /* ð´ Math */
case 0x1d435: /* ðµ Math */
case 0x1d436: /* ð¶ Math */
case 0x1d437: /* ð· Math */
case 0x1d438: /* ð¸ Math */
case 0x1d439: /* ð¹ Math */
case 0x1d43a: /* ðº Math */
case 0x1d43b: /* ð» Math */
case 0x1d49c: /* ð Math */
case 0x1d49e: /* ð Math */
case 0x1d49f: /* ð Math */
case 0x1d4a2: /* ð¢ Math */
case 0x1d4a5: /* ð¥ Math */
case 0x1d4a6: /* ð¦ Math */
case 0x1d4a9: /* ð© Math */
case 0x1d4aa: /* ðª Math */
case 0x1d4ab: /* ð« Math */
case 0x1d4ac: /* ð¬ Math */
case 0x1d504: /* ð Math */
case 0x1d505: /* ð
Math */
case 0x1d507: /* ð Math */
case 0x1d508: /* ð Math */
case 0x1d509: /* ð Math */
case 0x1d50a: /* ð Math */
case 0x1d516: /* ð Math */
case 0x1d517: /* ð Math */
case 0x1d518: /* ð Math */
case 0x1d519: /* ð Math */
case 0x1d51a: /* ð Math */
case 0x1d51b: /* ð Math */
case 0x1d51c: /* ð Math */
case 0x1d538: /* ð¸ Math */
case 0x1d539: /* ð¹ Math */
case 0x1d53b: /* ð» Math */
case 0x1d53c: /* ð¼ Math */
case 0x1d53d: /* ð½ Math */
case 0x1d53e: /* ð¾ Math */
case 0x1d540: /* ð Math */
case 0x1d541: /* ð Math */
case 0x1d542: /* ð Math */
case 0x1d543: /* ð Math */
case 0x1d544: /* ð Math */
case 0x1d546: /* ð Math */
case 0x1d54a: /* ð Math */
case 0x1d54b: /* ð Math */
case 0x1d54c: /* ð Math */
case 0x1d54d: /* ð Math */
case 0x1d54e: /* ð Math */
case 0x1d54f: /* ð Math */
case 0x1d550: /* ð Math */
case 0x1d6e3: /* ð£ Math */
case 0x1d6e4: /* ð¤ Math */
case 0x1d6e5: /* ð¥ Math */
case 0x1d6e6: /* ð¦ Math */
case 0x1d6e7: /* ð§ Math */
case 0x1d6e8: /* ð¨ Math */
case 0x1d6e9: /* ð© Math */
case 0x1d6ea: /* ðª Math */
case 0x1d6eb: /* ð« Math */
case 0x1d6ec: /* ð¬ Math */
case 0x1d6ed: /* ð Math */
case 0x1d6ee: /* ð® Math */
case 0x1d6ef: /* ð¯ Math */
case 0x1d6f0: /* ð° Math */
case 0x1d6f1: /* ð± Math */
case 0x1d6f2: /* ð² Math */
case 0x1d6f3: /* ð³ Math */
case 0x1d6f4: /* ð´ Math */
case 0x1d6f5: /* ðµ Math */
case 0x1d6f6: /* ð¶ Math */
case 0x1d6f7: /* ð· Math */
case 0x1d6f8: /* ð¸ Math */
case 0x1d6f9: /* ð¹ Math */
case 0x1d6fa: /* ðº Math */
case 0x1d72d: /* ð Math */
case 0x1d72e: /* ð® Math */
case 0x1d72f: /* ð¯ Math */
case 0x1d730: /* ð° Math */
case 0x1d731: /* ð± Math */
case 0x1d732: /* ð² Math */
case 0x1d733: /* ð³ Math */
case 0x1d734: /* ð´ Math */
case 0x1d767: /* ð§ Math */
case 0x1d768: /* ð¨ Math */
case 0x1d769: /* ð© Math */
case 0x1d76a: /* ðª Math */
case 0x1d76b: /* ð« Math */
case 0x1d76c: /* ð¬ Math */
case 0x1d76d: /* ð Math */
case 0x1d76e: /* ð® Math */
case 0x1d7a1: /* ð¡ Math */
case 0x1d7a2: /* ð¢ Math */
case 0x1d7a3: /* ð£ Math */
case 0x1d7a4: /* ð¤ Math */
case 0x1d7a5: /* ð¥ Math */
case 0x1d7a6: /* ð¦ Math */
case 0x1d7a7: /* ð§ Math */
case 0x1d7a8: /* ð¨ Math */
case 0x1d7ca: /* ð Math */
return 1;
default:
return 0;
}
}
}
| 6,781 | 163 | jart/cosmopolitan | false |
cosmopolitan/libc/str/unicode-properties.txt | Lu = Letter, uppercase
Ll = Letter, lowercase
Lt = Letter, titlecase
Lm = Letter, modifier
Lo = Letter, other
Mn = Mark, nonspacing
Mc = Mark, spacing combining
Me = Mark, enclosing
Nd = Number, decimal digit
Nl = Number, letter
No = Number, other
Pc = Punctuation, connector
Pd = Punctuation, dash
Ps = Punctuation, open
Pe = Punctuation, close
Pi = Punctuation, initial quote (may behave like Ps or Pe depending on usage)
Pf = Punctuation, final quote (may behave like Ps or Pe depending on usage)
Po = Punctuation, other
Sm = Symbol, math
Sc = Symbol, currency
Sk = Symbol, modifier
So = Symbol, other
Zs = Separator, space
Zl = Separator, line
Zp = Separator, paragraph
Cc = Other, control
Cf = Other, format
Cs = Other, surrogate
Co = Other, private use
Cn = Other, not assigned (including noncharacters)
W Wide Naturally wide character, e.g. Hiragana.
Na Narrow Naturally narrow character, e.g. ISO Basic Latin alphabet.
F Fullwidth Wide variant with compatibility normalisation to naturally narrow character, e.g. fullwidth Latin script.
H Halfwidth Narrow variant with compatibility normalisation to naturally wide character, e.g. half-width kana. Includes U+20A9 (â©) as an exception.
A Ambiguous Characters included in East Asian DBCS codes but also in European SBCS codes, e.g. Greek alphabet. Duospaced behaviour can consequently vary.
N Neutral Characters which do not appear in East Asian DBCS codes, e.g. Devanagari.
| 1,449 | 38 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strpbrk16.c | /*-*- 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/nexgen32e/hascharacter.internal.h"
#include "libc/str/str.h"
/**
* Returns pointer to first byte matching any in accept, or NULL.
* @asyncsignalsafe
*/
char16_t *strpbrk16(const char16_t *s, const char16_t *accept) {
size_t i;
if (accept[0]) {
if (!accept[1]) {
return strchr16(s, accept[0]);
} else {
for (i = 0; s[i]; ++i) {
if (HasCharacter16(s[i], accept)) {
return (/*unconst*/ char16_t *)&s[i];
}
}
}
}
return NULL;
}
| 2,343 | 41 | jart/cosmopolitan | false |
cosmopolitan/libc/str/memset16.c | /*-*- 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/str/str.h"
/**
* Sets wide memory.
* @asyncsignalsafe
*/
char16_t *memset16(char16_t *p, char16_t c, size_t n) {
size_t i;
for (i = 0; i < n; ++i) {
p[i] = c;
}
return p;
}
| 2,040 | 32 | jart/cosmopolitan | false |
cosmopolitan/libc/str/iswpunct.c | /*-*- 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/str/str.h"
/**
* Returns nonzero if c is punctuation mark.
*/
int iswpunct(wint_t c) {
if (c < 0xa0) {
switch (c) {
case '!':
case '"':
case '#':
case '$':
case '%':
case '&':
case '\'':
case '(':
case ')':
case '*':
case '+':
case ',':
case '-':
case '.':
case '/':
case ':':
case ';':
case '<':
case '=':
case '>':
case '?':
case '@':
case '[':
case '\\':
case ']':
case '^':
case '_':
case '`':
case '{':
case '|':
case '}':
case '~':
return 1;
default:
return 0;
}
}
switch (c) {
case u'¡': // INVERTED EXCLAMATION MARK (0x00a1 Po)
case u'§': // SECTION SIGN (0x00a7 Po)
case u'«': // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK (0x00ab Pi)
case u'¶': // PILCROW SIGN (0x00b6 Po)
case u'·': // MIDDLE DOT (0x00b7 Po)
case u'»': // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK (0x00bb Pf)
case u'¿': // INVERTED QUESTION MARK (0x00bf Po)
case u';': // GREEK QUESTION MARK (0x037e Po)
case u'Î': // GREEK ANO TELEIA (0x0387 Po)
case u'Õ': // ARMENIAN APOSTROPHE (0x055a Po)
case u'Õ': // ARMENIAN EMPHASIS MARK (0x055b Po)
case u'Õ': // ARMENIAN EXCLAMATION MARK (0x055c Po)
case u'Õ': // ARMENIAN COMMA (0x055d Po)
case u'Õ': // ARMENIAN QUESTION MARK (0x055e Po)
case u'Õ': // ARMENIAN ABBREVIATION MARK (0x055f Po)
case u'Ö': // ARMENIAN FULL STOP (0x0589 Po)
case u'Ö': // ARMENIAN HYPHEN (0x058a Pd)
case 0x05be: // HEBREW PUNCTUATION MAQAF (0x05be Pd)
case 0x05c0: // HEBREW PUNCTUATION PASEQ (0x05c0 Po)
case 0x05c3: // HEBREW PUNCTUATION SOF PASUQ (0x05c3 Po)
case 0x05c6: // HEBREW PUNCTUATION NUN HAFUKHA (0x05c6 Po)
case 0x05f3: // HEBREW PUNCTUATION GERESH (0x05f3 Po)
case 0x05f4: // HEBREW PUNCTUATION GERSHAYIM (0x05f4 Po)
case 0x0609: // ARABIC-INDIC PER MILLE SIGN (0x0609 Po)
case 0x060a: // ARABIC-INDIC PER TEN THOUSAND SIGN (0x060a Po)
case 0x060c: // ARABIC COMMA (0x060c Po)
case 0x060d: // ARABIC DATE SEPARATOR (0x060d Po)
case 0x061b: // ARABIC SEMICOLON (0x061b Po)
case u'Ø': // ARABIC TRIPLE DOT PUNCTUATION MARK (0x061e Po)
case u'Ø': // ARABIC QUESTION MARK (0x061f Po)
case u'Ùª': // ARABIC PERCENT SIGN (0x066a Po)
case u'Ù«': // ARABIC DECIMAL SEPARATOR (0x066b Po)
case u'Ù¬': // ARABIC THOUSANDS SEPARATOR (0x066c Po)
case u'Ù': // ARABIC FIVE POINTED STAR (0x066d Po)
case u'Û': // ARABIC FULL STOP (0x06d4 Po)
case u'ß·': // NKO SYMBOL GBAKURUNEN (0x07f7 Po)
case u'߸': // NKO COMMA (0x07f8 Po)
case u'ß¹': // NKO EXCLAMATION MARK (0x07f9 Po)
case u'।': // DEVANAGARI DANDA (0x0964 Po)
case u'॥': // DEVANAGARI DOUBLE DANDA (0x0965 Po)
case u'॰': // DEVANAGARI ABBREVIATION SIGN (0x0970 Po)
case 0x09fd: // BENGALI ABBREVIATION SIGN (0x09fd Po)
case 0x0a76: // GURMUKHI ABBREVIATION SIGN (0x0a76 Po)
case 0x0af0: // GUJARATI ABBREVIATION SIGN (0x0af0 Po)
case 0x0c77: // TELUGU SIGN SIDDHAM (0x0c77 Po)
case 0x0c84: // KANNADA SIGN SIDDHAM (0x0c84 Po)
case u'à·´': // SINHALA PUNCTUATION KUNDDALIYA (0x0df4 Po)
case u'à¹': // THAI CHARACTER FONGMAN (0x0e4f Po)
case u'à¹': // THAI CHARACTER ANGKHANKHU (0x0e5a Po)
case u'à¹': // THAI CHARACTER KHOMUT (0x0e5b Po)
case u'à¼': // TIBETAN MARK INITIAL YIG MGO MDUN MA (0x0f04 Po)
case u'à¼
': // TIBETAN MARK CLOSING YIG MGO SGAB MA (0x0f05 Po)
case u'à¼': // TIBETAN MARK CARET YIG MGO PHUR SHAD MA (0x0f06 Po)
case u'à¼': // TIBETAN MARK YIG MGO TSHEG SHAD MA (0x0f07 Po)
case u'à¼': // TIBETAN MARK SBRUL SHAD (0x0f08 Po)
case u'à¼': // TIBETAN MARK BSKUR YIG MGO (0x0f09 Po)
case u'à¼': // TIBETAN MARK BKA- SHOG YIG MGO (0x0f0a Po)
case u'à¼': // TIBETAN MARK INTERSYLLABIC TSHEG (0x0f0b Po)
case u'à¼': // TIBETAN MARK DELIMITER TSHEG BSTAR (0x0f0c Po)
case u'à¼': // TIBETAN MARK SHAD (0x0f0d Po)
case u'à¼': // TIBETAN MARK NYIS SHAD (0x0f0e Po)
case u'à¼': // TIBETAN MARK TSHEG SHAD (0x0f0f Po)
case u'à¼': // TIBETAN MARK NYIS TSHEG SHAD (0x0f10 Po)
case u'à¼': // TIBETAN MARK RIN CHEN SPUNGS SHAD (0x0f11 Po)
case u'à¼': // TIBETAN MARK RGYA GRAM SHAD (0x0f12 Po)
case u'à¼': // TIBETAN MARK GTER TSHEG (0x0f14 Po)
case u'༺': // TIBETAN MARK GUG RTAGS GYON (0x0f3a Ps)
case u'༻': // TIBETAN MARK GUG RTAGS GYAS (0x0f3b Pe)
case u'༼': // TIBETAN MARK ANG KHANG GYON (0x0f3c Ps)
case u'༽': // TIBETAN MARK ANG KHANG GYAS (0x0f3d Pe)
case u'à¾
': // TIBETAN MARK PALUTA (0x0f85 Po)
case u'à¿': // TIBETAN MARK BSKA- SHOG GI MGO RGYAN (0x0fd0 Po)
case u'à¿': // TIBETAN MARK MNYAM YIG GI MGO RGYAN (0x0fd1 Po)
case u'à¿': // TIBETAN MARK NYIS TSHEG (0x0fd2 Po)
case u'à¿': // TIBETAN MARK INITIAL BRDA RNYING YIG MGO MDUN MA (0x0fd3 Po)
case u'à¿': // TIBETAN MARK CLOSING BRDA RNYING YIG MGO SGAB MA (0x0fd4 Po)
case u'à¿': // TIBETAN MARK LEADING MCHAN RTAGS (0x0fd9 Po)
case u'à¿': // TIBETAN MARK TRAILING MCHAN RTAGS (0x0fda Po)
case u'á': // MYANMAR SIGN LITTLE SECTION (0x104a Po)
case u'á': // MYANMAR SIGN SECTION (0x104b Po)
case u'á': // MYANMAR SYMBOL LOCATIVE (0x104c Po)
case u'á': // MYANMAR SYMBOL COMPLETED (0x104d Po)
case u'á': // MYANMAR SYMBOL AFOREMENTIONED (0x104e Po)
case u'á': // MYANMAR SYMBOL GENITIVE (0x104f Po)
case u'á»': // GEORGIAN PARAGRAPH SEPARATOR (0x10fb Po)
case u'á ': // ETHIOPIC SECTION MARK (0x1360 Po)
case u'á¡': // ETHIOPIC WORDSPACE (0x1361 Po)
case u'á¢': // ETHIOPIC FULL STOP (0x1362 Po)
case u'á£': // ETHIOPIC COMMA (0x1363 Po)
case u'á¤': // ETHIOPIC SEMICOLON (0x1364 Po)
case u'á¥': // ETHIOPIC COLON (0x1365 Po)
case u'á¦': // ETHIOPIC PREFACE COLON (0x1366 Po)
case u'á§': // ETHIOPIC QUESTION MARK (0x1367 Po)
case u'á¨': // ETHIOPIC PARAGRAPH SEPARATOR (0x1368 Po)
case u'á': // CANADIAN SYLLABICS HYPHEN (0x1400 Pd)
case u'á®': // CANADIAN SYLLABICS FULL STOP (0x166e Po)
case u'á': // OGHAM FEATHER MARK (0x169b Ps)
case u'á': // OGHAM REVERSED FEATHER MARK (0x169c Pe)
case u'á«': // RUNIC SINGLE PUNCTUATION (0x16eb Po)
case u'á¬': // RUNIC MULTIPLE PUNCTUATION (0x16ec Po)
case u'á': // RUNIC CROSS PUNCTUATION (0x16ed Po)
case u'áµ': // PHILIPPINE SINGLE PUNCTUATION (0x1735 Po)
case u'á¶': // PHILIPPINE DOUBLE PUNCTUATION (0x1736 Po)
case u'á': // KHMER SIGN KHAN (0x17d4 Po)
case u'á': // KHMER SIGN BARIYOOSAN (0x17d5 Po)
case u'á': // KHMER SIGN CAMNUC PII KUUH (0x17d6 Po)
case u'á': // KHMER SIGN BEYYAL (0x17d8 Po)
case u'á': // KHMER SIGN PHNAEK MUAN (0x17d9 Po)
case u'á': // KHMER SIGN KOOMUUT (0x17da Po)
case u'á ': // MONGOLIAN BIRGA (0x1800 Po)
case u'á ': // MONGOLIAN ELLIPSIS (0x1801 Po)
case u'á ': // MONGOLIAN COMMA (0x1802 Po)
case u'á ': // MONGOLIAN FULL STOP (0x1803 Po)
case u'á ': // MONGOLIAN COLON (0x1804 Po)
case u'á
': // MONGOLIAN FOUR DOTS (0x1805 Po)
case u'á ': // MONGOLIAN TODO SOFT HYPHEN (0x1806 Pd)
case u'á ': // MONGOLIAN SIBE SYLLABLE BOUNDARY MARKER (0x1807 Po)
case u'á ': // MONGOLIAN MANCHU COMMA (0x1808 Po)
case u'á ': // MONGOLIAN MANCHU FULL STOP (0x1809 Po)
case u'á ': // MONGOLIAN NIRUGU (0x180a Po)
case u'á¥': // LIMBU EXCLAMATION MARK (0x1944 Po)
case u'á¥
': // LIMBU QUESTION MARK (0x1945 Po)
case u'á¨': // BUGINESE PALLAWA (0x1a1e Po)
case u'á¨': // BUGINESE END OF SECTION (0x1a1f Po)
case u'á±¾': // OL CHIKI PUNCTUATION MUCAAD (0x1c7e Po)
case u'᱿': // OL CHIKI PUNCTUATION DOUBLE MUCAAD (0x1c7f Po)
case u'â': // HYPHEN (0x2010 Pd)
case u'â': // NON-BREAKING HYPHEN (0x2011 Pd)
case u'â': // FIGURE DASH (0x2012 Pd)
case u'â': // EN DASH (0x2013 Pd)
case u'â': // EM DASH (0x2014 Pd)
case u'â': // HORIZONTAL BAR (0x2015 Pd)
case u'â': // DOUBLE VERTICAL LINE (0x2016 Po)
case u'â': // DOUBLE LOW LINE (0x2017 Po)
case u'â': // LEFT SINGLE QUOTATION MARK (0x2018 Pi)
case u'â': // RIGHT SINGLE QUOTATION MARK (0x2019 Pf)
case u'â': // SINGLE LOW-9 QUOTATION MARK (0x201a Ps)
case u'â': // SINGLE HIGH-REVERSED-9 QUOTATION MARK (0x201b Pi)
case u'â': // LEFT DOUBLE QUOTATION MARK (0x201c Pi)
case u'â': // RIGHT DOUBLE QUOTATION MARK (0x201d Pf)
case u'â': // DOUBLE LOW-9 QUOTATION MARK (0x201e Ps)
case u'â': // DOUBLE HIGH-REVERSED-9 QUOTATION MARK (0x201f Pi)
case u'â ': // DAGGER (0x2020 Po)
case u'â¡': // DOUBLE DAGGER (0x2021 Po)
case u'â¢': // BULLET (0x2022 Po)
case u'â£': // TRIANGULAR BULLET (0x2023 Po)
case u'â¤': // ONE DOT LEADER (0x2024 Po)
case u'â¥': // TWO DOT LEADER (0x2025 Po)
case u'â¦': // HORIZONTAL ELLIPSIS (0x2026 Po)
case u'â§': // HYPHENATION POINT (0x2027 Po)
case u'â°': // PER MILLE SIGN (0x2030 Po)
case u'â±': // PER TEN THOUSAND SIGN (0x2031 Po)
case u'â²': // PRIME (0x2032 Po)
case u'â³': // DOUBLE PRIME (0x2033 Po)
case u'â´': // TRIPLE PRIME (0x2034 Po)
case u'âµ': // REVERSED PRIME (0x2035 Po)
case u'â¶': // REVERSED DOUBLE PRIME (0x2036 Po)
case u'â·': // REVERSED TRIPLE PRIME (0x2037 Po)
case u'â¸': // CARET (0x2038 Po)
case u'â¹': // SINGLE LEFT-POINTING ANGLE QUOTATION MARK (0x2039 Pi)
case u'âº': // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK (0x203a Pf)
case u'â»': // REFERENCE MARK (0x203b Po)
case u'â¼': // DOUBLE EXCLAMATION MARK (0x203c Po)
case u'â½': // INTERROBANG (0x203d Po)
case u'â¾': // OVERLINE (0x203e Po)
case u'â¿': // UNDERTIE (0x203f Pc)
case u'â': // CHARACTER TIE (0x2040 Pc)
case u'â': // CARET INSERTION POINT (0x2041 Po)
case u'â': // ASTERISM (0x2042 Po)
case u'â': // HYPHEN BULLET (0x2043 Po)
case u'â
': // LEFT SQUARE BRACKET WITH QUILL (0x2045 Ps)
case u'â': // RIGHT SQUARE BRACKET WITH QUILL (0x2046 Pe)
case u'â': // DOUBLE QUESTION MARK (0x2047 Po)
case u'â': // QUESTION EXCLAMATION MARK (0x2048 Po)
case u'â': // EXCLAMATION QUESTION MARK (0x2049 Po)
case u'â': // TIRONIAN SIGN ET (0x204a Po)
case u'â': // REVERSED PILCROW SIGN (0x204b Po)
case u'â': // BLACK LEFTWARDS BULLET (0x204c Po)
case u'â': // BLACK RIGHTWARDS BULLET (0x204d Po)
case u'â': // LOW ASTERISK (0x204e Po)
case u'â': // REVERSED SEMICOLON (0x204f Po)
case u'â': // CLOSE UP (0x2050 Po)
case u'â': // TWO ASTERISKS ALIGNED VERTICALLY (0x2051 Po)
case u'â': // SWUNG DASH (0x2053 Po)
case u'â': // INVERTED UNDERTIE (0x2054 Pc)
case u'â': // FLOWER PUNCTUATION MARK (0x2055 Po)
case u'â': // THREE DOT PUNCTUATION (0x2056 Po)
case u'â': // QUADRUPLE PRIME (0x2057 Po)
case u'â': // FOUR DOT PUNCTUATION (0x2058 Po)
case u'â': // FIVE DOT PUNCTUATION (0x2059 Po)
case u'â': // TWO DOT PUNCTUATION (0x205a Po)
case u'â': // FOUR DOT MARK (0x205b Po)
case u'â': // DOTTED CROSS (0x205c Po)
case u'â': // TRICOLON (0x205d Po)
case u'â': // VERTICAL FOUR DOTS (0x205e Po)
case u'â½': // SUPERSCRIPT LEFT PARENTHESIS (0x207d Ps)
case u'â¾': // SUPERSCRIPT RIGHT PARENTHESIS (0x207e Pe)
case u'â': // SUBSCRIPT LEFT PARENTHESIS (0x208d Ps)
case u'â': // SUBSCRIPT RIGHT PARENTHESIS (0x208e Pe)
case u'â': // LEFT CEILING (0x2308 Ps)
case u'â': // RIGHT CEILING (0x2309 Pe)
case u'â': // LEFT FLOOR (0x230a Ps)
case u'â': // RIGHT FLOOR (0x230b Pe)
case u'â©': // LEFT-POINTING ANGLE BRACKET (0x2329 Ps)
case u'âª': // RIGHT-POINTING ANGLE BRACKET (0x232a Pe)
case u'â¨': // MEDIUM LEFT PARENTHESIS ORNAMENT (0x2768 Ps)
case u'â©': // MEDIUM RIGHT PARENTHESIS ORNAMENT (0x2769 Pe)
case u'âª': // MEDIUM FLATTENED LEFT PARENTHESIS ORNAMENT (0x276a Ps)
case u'â«': // MEDIUM FLATTENED RIGHT PARENTHESIS ORNAMENT (0x276b Pe)
case u'â¬': // MEDIUM LEFT-POINTING ANGLE BRACKET ORNAMENT (0x276c Ps)
case u'â': // MEDIUM RIGHT-POINTING ANGLE BRACKET ORNAMENT (0x276d Pe)
case u'â®': // HEAVY LEFT-POINTING ANGLE QUOTATION MARK ORNAMENT (0x276e Ps)
case u'â¯': // HEAVY RIGHT-POINTING ANGLE QUOT MARK ORNAMENT (0x276f Pe)
case u'â°': // HEAVY LEFT-POINTING ANGLE BRACKET ORNAMENT (0x2770 Ps)
case u'â±': // HEAVY RIGHT-POINTING ANGLE BRACKET ORNAMENT (0x2771 Pe)
case u'â²': // LIGHT LEFT TORTOISE SHELL BRACKET ORNAMENT (0x2772 Ps)
case u'â³': // LIGHT RIGHT TORTOISE SHELL BRACKET ORNAMENT (0x2773 Pe)
case u'â´': // MEDIUM LEFT CURLY BRACKET ORNAMENT (0x2774 Ps)
case u'âµ': // MEDIUM RIGHT CURLY BRACKET ORNAMENT (0x2775 Pe)
case u'â
': // LEFT S-SHAPED BAG DELIMITER (0x27c5 Ps)
case u'â': // RIGHT S-SHAPED BAG DELIMITER (0x27c6 Pe)
case u'â¦': // MATHEMATICAL LEFT WHITE SQUARE BRACKET (0x27e6 Ps)
case u'â§': // MATHEMATICAL RIGHT WHITE SQUARE BRACKET (0x27e7 Pe)
case u'â¨': // MATHEMATICAL LEFT ANGLE BRACKET (0x27e8 Ps)
case u'â©': // MATHEMATICAL RIGHT ANGLE BRACKET (0x27e9 Pe)
case u'âª': // MATHEMATICAL LEFT DOUBLE ANGLE BRACKET (0x27ea Ps)
case u'â«': // MATHEMATICAL RIGHT DOUBLE ANGLE BRACKET (0x27eb Pe)
case u'â¬': // MATHEMATICAL LEFT WHITE TORTOISE SHELL BRACKET (0x27ec Ps)
case u'â': // MATHEMATICAL RIGHT WHITE TORTOISE SHELL BRACKET (0x27ed Pe)
case u'â®': // MATHEMATICAL LEFT FLATTENED PARENTHESIS (0x27ee Ps)
case u'â¯': // MATHEMATICAL RIGHT FLATTENED PARENTHESIS (0x27ef Pe)
case u'â¦': // LEFT WHITE CURLY BRACKET (0x2983 Ps)
case u'â¦': // RIGHT WHITE CURLY BRACKET (0x2984 Pe)
case u'â¦
': // LEFT WHITE PARENTHESIS (0x2985 Ps)
case u'â¦': // RIGHT WHITE PARENTHESIS (0x2986 Pe)
case u'â¦': // Z NOTATION LEFT IMAGE BRACKET (0x2987 Ps)
case u'â¦': // Z NOTATION RIGHT IMAGE BRACKET (0x2988 Pe)
case u'â¦': // Z NOTATION LEFT BINDING BRACKET (0x2989 Ps)
case u'â¦': // Z NOTATION RIGHT BINDING BRACKET (0x298a Pe)
case u'â¦': // LEFT SQUARE BRACKET WITH UNDERBAR (0x298b Ps)
case u'â¦': // RIGHT SQUARE BRACKET WITH UNDERBAR (0x298c Pe)
case u'â¦': // LEFT SQUARE BRACKET WITH TICK IN TOP CORNER (0x298d Ps)
case u'â¦': // RIGHT SQUARE BRACKET WITH TICK IN BOTTOM CORNER (0x298e Pe)
case u'â¦': // LEFT SQUARE BRACKET WITH TICK IN BOTTOM CORNER (0x298f Ps)
case u'â¦': // RIGHT SQUARE BRACKET WITH TICK IN TOP CORNER (0x2990 Pe)
case u'â¦': // LEFT ANGLE BRACKET WITH DOT (0x2991 Ps)
case u'â¦': // RIGHT ANGLE BRACKET WITH DOT (0x2992 Pe)
case u'â¦': // LEFT ARC LESS-THAN BRACKET (0x2993 Ps)
case u'â¦': // RIGHT ARC GREATER-THAN BRACKET (0x2994 Pe)
case u'â¦': // LEFT BLACK TORTOISE SHELL BRACKET (0x2997 Ps)
case u'â¦': // RIGHT BLACK TORTOISE SHELL BRACKET (0x2998 Pe)
case u'â§': // LEFT WIGGLY FENCE (0x29d8 Ps)
case u'â§': // RIGHT WIGGLY FENCE (0x29d9 Pe)
case u'â§': // LEFT DOUBLE WIGGLY FENCE (0x29da Ps)
case u'â§': // RIGHT DOUBLE WIGGLY FENCE (0x29db Pe)
case u'â§¼': // LEFT-POINTING CURVED ANGLE BRACKET (0x29fc Ps)
case u'â§½': // RIGHT-POINTING CURVED ANGLE BRACKET (0x29fd Pe)
case u'âµ°': // TIFINAGH SEPARATOR MARK (0x2d70 Po)
case u'â¸': // EDITORIAL CORONIS (0x2e0e Po)
case u'â¸': // PARAGRAPHOS (0x2e0f Po)
case u'â¸': // FORKED PARAGRAPHOS (0x2e10 Po)
case u'â¸': // REVERSED FORKED PARAGRAPHOS (0x2e11 Po)
case u'â¸': // HYPODIASTOLE (0x2e12 Po)
case u'â¸': // DOTTED OBELOS (0x2e13 Po)
case u'â¸': // DOWNWARDS ANCORA (0x2e14 Po)
case u'â¸': // UPWARDS ANCORA (0x2e15 Po)
case u'â¸': // DOTTED RIGHT-POINTING ANGLE (0x2e16 Po)
case u'â¸': // DOUBLE OBLIQUE HYPHEN (0x2e17 Pd)
case u'â¸': // PALM BRANCH (0x2e19 Po)
case u'â¸': // HYPHEN WITH DIAERESIS (0x2e1a Pd)
case u'â¸': // TILDE WITH RING ABOVE (0x2e1b Po)
case u'â¸': // TILDE WITH DOT ABOVE (0x2e1e Po)
case u'â¸': // TILDE WITH DOT BELOW (0x2e1f Po)
case u'⸪': // TWO DOTS OVER ONE DOT PUNCTUATION (0x2e2a Po)
case u'⸫': // ONE DOT OVER TWO DOTS PUNCTUATION (0x2e2b Po)
case u'⸬': // SQUARED FOUR DOT PUNCTUATION (0x2e2c Po)
case u'â¸': // FIVE DOT MARK (0x2e2d Po)
case u'⸮': // REVERSED QUESTION MARK (0x2e2e Po)
case u'⸰': // RING POINT (0x2e30 Po)
case u'⸱': // WORD SEPARATOR MIDDLE DOT (0x2e31 Po)
case u'⸲': // TURNED COMMA (0x2e32 Po)
case u'⸳': // RAISED DOT (0x2e33 Po)
case u'⸴': // RAISED COMMA (0x2e34 Po)
case u'⸵': // TURNED SEMICOLON (0x2e35 Po)
case u'⸶': // DAGGER WITH LEFT GUARD (0x2e36 Po)
case u'⸷': // DAGGER WITH RIGHT GUARD (0x2e37 Po)
case u'⸸': // TURNED DAGGER (0x2e38 Po)
case u'⸹': // TOP HALF SECTION SIGN (0x2e39 Po)
case u'⸺': // TWO-EM DASH (0x2e3a Pd)
case u'⸻': // THREE-EM DASH (0x2e3b Pd)
case u'⸼': // STENOGRAPHIC FULL STOP (0x2e3c Po)
case u'⸽': // VERTICAL SIX DOTS (0x2e3d Po)
case u'⸾': // WIGGLY VERTICAL LINE (0x2e3e Po)
case u'⸿': // CAPITULUM (0x2e3f Po)
case u'â¹': // DOUBLE HYPHEN (0x2e40 Pd)
case u'â¹': // REVERSED COMMA (0x2e41 Po)
case u'â¹': // DOUBLE LOW-REVERSED-9 QUOTATION MARK (0x2e42 Ps)
case u'â¹': // DASH WITH LEFT UPTURN (0x2e43 Po)
case u'â¹': // DOUBLE SUSPENSION MARK (0x2e44 Po)
case u'â¹
': // INVERTED LOW KAVYKA (0x2e45 Po)
case u'â¹': // INVERTED LOW KAVYKA WITH KAVYKA ABOVE (0x2e46 Po)
case u'â¹': // LOW KAVYKA (0x2e47 Po)
case u'â¹': // LOW KAVYKA WITH DOT (0x2e48 Po)
case u'â¹': // DOUBLE STACKED COMMA (0x2e49 Po)
case u'â¹': // DOTTED SOLIDUS (0x2e4a Po)
case u'â¹': // TRIPLE DAGGER (0x2e4b Po)
case u'â¹': // MEDIEVAL COMMA (0x2e4c Po)
case u'â¹': // PARAGRAPHUS MARK (0x2e4d Po)
case u'â¹': // PUNCTUS ELEVATUS MARK (0x2e4e Po)
case u'â¹': // CORNISH VERSE DIVIDER (0x2e4f Po)
case u'ã': // IDEOGRAPHIC COMMA (0x3001 Po)
case u'ã': // IDEOGRAPHIC FULL STOP (0x3002 Po)
case u'ã': // DITTO MARK (0x3003 Po)
case u'ã': // LEFT ANGLE BRACKET (0x3008 Ps)
case u'ã': // RIGHT ANGLE BRACKET (0x3009 Pe)
case u'ã': // LEFT DOUBLE ANGLE BRACKET (0x300a Ps)
case u'ã': // RIGHT DOUBLE ANGLE BRACKET (0x300b Pe)
case u'ã': // LEFT CORNER BRACKET (0x300c Ps)
case u'ã': // RIGHT CORNER BRACKET (0x300d Pe)
case u'ã': // LEFT WHITE CORNER BRACKET (0x300e Ps)
case u'ã': // RIGHT WHITE CORNER BRACKET (0x300f Pe)
case u'ã': // LEFT BLACK LENTICULAR BRACKET (0x3010 Ps)
case u'ã': // RIGHT BLACK LENTICULAR BRACKET (0x3011 Pe)
case u'ã': // LEFT TORTOISE SHELL BRACKET (0x3014 Ps)
case u'ã': // RIGHT TORTOISE SHELL BRACKET (0x3015 Pe)
case u'ã': // LEFT WHITE LENTICULAR BRACKET (0x3016 Ps)
case u'ã': // RIGHT WHITE LENTICULAR BRACKET (0x3017 Pe)
case u'ã': // LEFT WHITE TORTOISE SHELL BRACKET (0x3018 Ps)
case u'ã': // RIGHT WHITE TORTOISE SHELL BRACKET (0x3019 Pe)
case u'ã': // LEFT WHITE SQUARE BRACKET (0x301a Ps)
case u'ã': // RIGHT WHITE SQUARE BRACKET (0x301b Pe)
case u'ã': // WAVE DASH (0x301c Pd)
case u'ã': // REVERSED DOUBLE PRIME QUOTATION MARK (0x301d Ps)
case u'ã': // DOUBLE PRIME QUOTATION MARK (0x301e Pe)
case u'ã': // LOW DOUBLE PRIME QUOTATION MARK (0x301f Pe)
case u'ã°': // WAVY DASH (0x3030 Pd)
case u'ã½': // PART ALTERNATION MARK (0x303d Po)
case u'ã ': // KATAKANA-HIRAGANA DOUBLE HYPHEN (0x30a0 Pd)
case u'ã»': // KATAKANA MIDDLE DOT (0x30fb Po)
case u'ê¾': // LISU PUNCTUATION COMMA (0xa4fe Po)
case u'ê¿': // LISU PUNCTUATION FULL STOP (0xa4ff Po)
case u'ê': // VAI COMMA (0xa60d Po)
case u'ê': // VAI FULL STOP (0xa60e Po)
case u'ê': // VAI QUESTION MARK (0xa60f Po)
case u'ê¾': // CYRILLIC KAVYKA (0xa67e Po)
case u'ê¡´': // PHAGS-PA SINGLE HEAD MARK (0xa874 Po)
case u'꡵': // PHAGS-PA DOUBLE HEAD MARK (0xa875 Po)
case u'ê¡¶': // PHAGS-PA MARK SHAD (0xa876 Po)
case u'ê¡·': // PHAGS-PA MARK DOUBLE SHAD (0xa877 Po)
case u'ê£': // SAURASHTRA DANDA (0xa8ce Po)
case u'ê£': // SAURASHTRA DOUBLE DANDA (0xa8cf Po)
case u'꣸': // DEVANAGARI SIGN PUSHPIKA (0xa8f8 Po)
case u'꣹': // DEVANAGARI GAP FILLER (0xa8f9 Po)
case u'꣺': // DEVANAGARI CARET (0xa8fa Po)
case u'꣼': // DEVANAGARI SIGN SIDDHAM (0xa8fc Po)
case u'ê§': // JAVANESE LEFT RERENGGAN (0xa9c1 Po)
case u'ê§': // JAVANESE RIGHT RERENGGAN (0xa9c2 Po)
case u'ê§': // JAVANESE PADA ANDAP (0xa9c3 Po)
case u'ê§': // JAVANESE PADA MADYA (0xa9c4 Po)
case u'ê§
': // JAVANESE PADA LUHUR (0xa9c5 Po)
case u'ê§': // JAVANESE PADA WINDU (0xa9c6 Po)
case u'ê§': // JAVANESE PADA PANGKAT (0xa9c7 Po)
case u'ê§': // JAVANESE PADA LINGSA (0xa9c8 Po)
case u'ê§': // JAVANESE PADA LUNGSI (0xa9c9 Po)
case u'ê§': // JAVANESE PADA ADEG (0xa9ca Po)
case u'ê§': // JAVANESE PADA ADEG ADEG (0xa9cb Po)
case u'ê§': // JAVANESE PADA PISELEH (0xa9cc Po)
case u'ê§': // JAVANESE TURNED PADA PISELEH (0xa9cd Po)
case u'ê§': // JAVANESE PADA TIRTA TUMETES (0xa9de Po)
case u'ê§': // JAVANESE PADA ISEN-ISEN (0xa9df Po)
case u'ê©': // CHAM PUNCTUATION SPIRAL (0xaa5c Po)
case u'ê©': // CHAM PUNCTUATION DANDA (0xaa5d Po)
case u'ê©': // CHAM PUNCTUATION DOUBLE DANDA (0xaa5e Po)
case u'ê©': // CHAM PUNCTUATION TRIPLE DANDA (0xaa5f Po)
case u'ê«': // TAI VIET SYMBOL HO HOI (0xaade Po)
case u'ê«': // TAI VIET SYMBOL KOI KOI (0xaadf Po)
case u'ê«°': // MEETEI MAYEK CHEIKHAN (0xaaf0 Po)
case u'꫱': // MEETEI MAYEK AHANG KHUDAM (0xaaf1 Po)
case u'꯫': // MEETEI MAYEK CHEIKHEI (0xabeb Po)
case u'ï¸': // PRESENTATION FORM FOR VERTICAL COMMA (0xfe10 Po)
case u'ï¸': // PRESENTATION FORM FOR VERTICAL IDEOGRAPHIC COMMA (0xfe11 Po)
case u'ï¸': // PRESENTATION FORM FOR VERTICAL IDEO FULL STOP (0xfe12 Po)
case u'ï¸': // PRESENTATION FORM FOR VERTICAL COLON (0xfe13 Po)
case u'ï¸': // PRESENTATION FORM FOR VERTICAL SEMICOLON (0xfe14 Po)
case u'ï¸': // PRESENTATION FORM FOR VERTICAL EXCLAMATION MARK (0xfe15 Po)
case u'ï¸': // PRESENTATION FORM FOR VERTICAL QUESTION MARK (0xfe16 Po)
case u'ï¸': // PRESENTATION ... LEFT WHITE LENTICULAR BRACKET (0xfe17 Ps)
case u'ï¸': // PRESENTATION ... RIGHT WHITE LENTICULAR BRAKCET (0xfe18 Pe)
case u'ï¸': // PRESENTATION ... VERTICAL HORIZONTAL ELLIPSIS (0xfe19 Po)
case u'︰': // PRESENTATION FORM FOR VERTICAL TWO DOT LEADER (0xfe30 Po)
case u'︱': // PRESENTATION FORM FOR VERTICAL EM DASH (0xfe31 Pd)
case u'︲': // PRESENTATION FORM FOR VERTICAL EN DASH (0xfe32 Pd)
case u'︳': // PRESENTATION FORM FOR VERTICAL LOW LINE (0xfe33 Pc)
case u'︴': // PRESENTATION FORM FOR VERTICAL WAVY LOW LINE (0xfe34 Pc)
case u'︵': // PRESENTATION FORM FOR VERTICAL LEFT PARENTHESIS (0xfe35 Ps)
case u'︶': // PRESENTATION FORM FOR VERTICAL RIGHT PARENTHESIS (0xfe36 Pe)
case u'︷': // PRESENTATION ... VERTICAL LEFT CURLY BRACKET (0xfe37 Ps)
case u'︸': // PRESENTATION ... VERTICAL RIGHT CURLY BRACKET (0xfe38 Pe)
case u'︹': // PRESENTATION ... LEFT TORTOISE SHELL BRACKET (0xfe39 Ps)
case u'︺': // PRESENTATION ... RIGHT TORTOISE SHELL BRACKET (0xfe3a Pe)
case u'︻': // PRESENTATION ... LEFT BLACK LENTICULAR BRACKET (0xfe3b Ps)
case u'︼': // PRESENTATION ... RIGHT BLACK LENTICULAR BRACKET (0xfe3c Pe)
case u'︽': // PRESENTATION ... LEFT DOUBLE ANGLE BRACKET (0xfe3d Ps)
case u'︾': // PRESENTATION ... RIGHT DOUBLE ANGLE BRACKET (0xfe3e Pe)
case u'︿': // PRESENTATION ... LEFT ANGLE BRACKET (0xfe3f Ps)
case u'ï¹': // PRESENTATION ... RIGHT ANGLE BRACKET (0xfe40 Pe)
case u'ï¹': // PRESENTATION ... LEFT CORNER BRACKET (0xfe41 Ps)
case u'ï¹': // PRESENTATION ... RIGHT CORNER BRACKET (0xfe42 Pe)
case u'ï¹': // PRESENTATION ... LEFT WHITE CORNER BRACKET (0xfe43 Ps)
case u'ï¹': // PRESENTATION ... RIGHT WHITE CORNER BRACKET Pe)
case u'ï¹
': // SESAME DOT (0xfe45 Po)
case u'ï¹': // WHITE SESAME DOT (0xfe46 Po)
case u'ï¹': // PRESENTATION ... VERTICAL LEFT SQUARE BRACKET (0xfe47 Ps)
case u'ï¹': // PRESENTATION ... VERTICAL RIGHT SQUARE BRACKET (0xfe48 Pe)
case u'ï¹': // DASHED OVERLINE (0xfe49 Po)
case u'ï¹': // CENTRELINE OVERLINE (0xfe4a Po)
case u'ï¹': // WAVY OVERLINE (0xfe4b Po)
case u'ï¹': // DOUBLE WAVY OVERLINE (0xfe4c Po)
case u'ï¹': // DASHED LOW LINE (0xfe4d Pc)
case u'ï¹': // CENTRELINE LOW LINE (0xfe4e Pc)
case u'ï¹': // WAVY LOW LINE (0xfe4f Pc)
case u'ï¹': // SMALL COMMA (0xfe50 Po)
case u'ï¹': // SMALL IDEOGRAPHIC COMMA (0xfe51 Po)
case u'ï¹': // SMALL FULL STOP (0xfe52 Po)
case u'ï¹': // SMALL SEMICOLON (0xfe54 Po)
case u'ï¹': // SMALL COLON (0xfe55 Po)
case u'ï¹': // SMALL QUESTION MARK (0xfe56 Po)
case u'ï¹': // SMALL EXCLAMATION MARK (0xfe57 Po)
case u'ï¹': // SMALL EM DASH (0xfe58 Pd)
case u'ï¹': // SMALL LEFT PARENTHESIS (0xfe59 Ps)
case u'ï¹': // SMALL RIGHT PARENTHESIS (0xfe5a Pe)
case u'ï¹': // SMALL LEFT CURLY BRACKET (0xfe5b Ps)
case u'ï¹': // SMALL RIGHT CURLY BRACKET (0xfe5c Pe)
case u'ï¹': // SMALL LEFT TORTOISE SHELL BRACKET (0xfe5d Ps)
case u'ï¹': // SMALL RIGHT TORTOISE SHELL BRACKET (0xfe5e Pe)
case u'ï¹': // SMALL NUMBER SIGN (0xfe5f Po)
case u'ï¹ ': // SMALL AMPERSAND (0xfe60 Po)
case u'﹡': // SMALL ASTERISK (0xfe61 Po)
case u'ï¹£': // SMALL HYPHEN-MINUS (0xfe63 Pd)
case u'﹨': // SMALL REVERSE SOLIDUS (0xfe68 Po)
case u'﹪': // SMALL PERCENT SIGN (0xfe6a Po)
case u'﹫': // SMALL COMMERCIAL AT (0xfe6b Po)
case u'ï¼': // FULLWIDTH EXCLAMATION MARK (0xff01 Po)
case u'ï¼': // FULLWIDTH QUOTATION MARK (0xff02 Po)
case u'ï¼': // FULLWIDTH NUMBER SIGN (0xff03 Po)
case u'ï¼
': // FULLWIDTH PERCENT SIGN (0xff05 Po)
case u'ï¼': // FULLWIDTH AMPERSAND (0xff06 Po)
case u'ï¼': // FULLWIDTH APOSTROPHE (0xff07 Po)
case u'ï¼': // FULLWIDTH LEFT PARENTHESIS (0xff08 Ps)
case u'ï¼': // FULLWIDTH RIGHT PARENTHESIS (0xff09 Pe)
case u'ï¼': // FULLWIDTH ASTERISK (0xff0a Po)
case u'ï¼': // FULLWIDTH COMMA (0xff0c Po)
case u'ï¼': // FULLWIDTH HYPHEN-MINUS (0xff0d Pd)
case u'ï¼': // FULLWIDTH FULL STOP (0xff0e Po)
case u'ï¼': // FULLWIDTH SOLIDUS (0xff0f Po)
case u'ï¼': // FULLWIDTH COLON (0xff1a Po)
case u'ï¼': // FULLWIDTH SEMICOLON (0xff1b Po)
case u'ï¼': // FULLWIDTH QUESTION MARK (0xff1f Po)
case u'ï¼ ': // FULLWIDTH COMMERCIAL AT (0xff20 Po)
case u'ï¼»': // FULLWIDTH LEFT SQUARE BRACKET (0xff3b Ps)
case u'ï¼¼': // FULLWIDTH REVERSE SOLIDUS (0xff3c Po)
case u'ï¼½': // FULLWIDTH RIGHT SQUARE BRACKET (0xff3d Pe)
case u'_': // FULLWIDTH LOW LINE (0xff3f Pc)
case u'ï½': // FULLWIDTH LEFT CURLY BRACKET (0xff5b Ps)
case u'ï½': // FULLWIDTH RIGHT CURLY BRACKET (0xff5d Pe)
case u'ï½': // FULLWIDTH LEFT WHITE PARENTHESIS (0xff5f Ps)
case u'ï½ ': // FULLWIDTH RIGHT WHITE PARENTHESIS (0xff60 Pe)
case u'。': // HALFWIDTH IDEOGRAPHIC FULL STOP (0xff61 Po)
case u'ï½¢': // HALFWIDTH LEFT CORNER BRACKET (0xff62 Ps)
case u'ï½£': // HALFWIDTH RIGHT CORNER BRACKET (0xff63 Pe)
case u'、': // HALFWIDTH IDEOGRAPHIC COMMA (0xff64 Po)
case u'ï½¥': // HALFWIDTH KATAKANA MIDDLE DOT (0xff65 Po)
return 1;
default:
return 0;
}
}
| 30,525 | 542 | jart/cosmopolitan | false |
cosmopolitan/libc/str/wmemcmp.c | /*-*- 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. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/str.h"
/**
* Compares arrays of 32-bit signed integers.
*
* @param a is first memory array
* @param b is second memory array
* @param n is number of elements in `a` and `b` to consider
* @return is <0, 0, or >0 based on int32_t comparison
* @asyncsignalsafe
*/
int wmemcmp(const wchar_t *a, const wchar_t *b, size_t n) {
size_t i;
for (i = 0; i < n; ++i) {
if (a[i] != b[i]) {
return a[i] - b[i];
}
}
return 0;
}
| 2,299 | 39 | jart/cosmopolitan | false |
cosmopolitan/libc/str/towupper.c | /*-*- 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 â
â â
â 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/dce.h"
#include "libc/macros.internal.h"
#include "libc/str/str.h"
/* clang-format off */
static const struct {
unsigned short x;
unsigned short y;
short d;
} kUpper[] = {
{0x00b5, 0x00b5, +743}, /* 1x µ ..µ â Î ..Î Watin */
{0x00e0, 0x00f6, -32}, /* 23x à ..ö â à ..à Watin */
{0x00f8, 0x00fe, -32}, /* 7x ø ..þ â à ..à Watin */
{0x00ff, 0x00ff, +121}, /* 1x ÿ ..ÿ â Ÿ ..Ÿ Watin */
{0x017a, 0x017a, -1}, /* 1x ź ..ź â Ź ..Ź Watin-A */
{0x017c, 0x017c, -1}, /* 1x ż ..ż â Å» ..Å» Watin-A */
{0x017e, 0x017e, -1}, /* 1x ž ..ž â Ž ..Ž Watin-A */
{0x017f, 0x017f, -300}, /* 1x Å¿ ..Å¿ â S ..S Watin-A */
{0x0180, 0x0180, +195}, /* 1x Æ ..Æ â É ..É Watin-B */
{0x0183, 0x0183, -1}, /* 1x Æ ..Æ â Æ ..Æ Watin-B */
{0x0185, 0x0185, -1}, /* 1x Æ
..Æ
â Æ ..Æ Watin-B */
{0x0188, 0x0188, -1}, /* 1x Æ ..Æ â Æ ..Æ Watin-B */
{0x018c, 0x018c, -1}, /* 1x Æ ..Æ â Æ ..Æ Watin-B */
{0x0192, 0x0192, -1}, /* 1x Æ ..Æ â Æ ..Æ Watin-B */
{0x0195, 0x0195, +97}, /* 1x Æ ..Æ â Ƕ ..Ƕ Watin-B */
{0x0199, 0x0199, -1}, /* 1x Æ ..Æ â Æ ..Æ Watin-B */
{0x019a, 0x019a, +163}, /* 1x Æ ..Æ â Ƚ ..Ƚ Watin-B */
{0x019e, 0x019e, +130}, /* 1x Æ ..Æ â È ..È Watin-B */
{0x01a1, 0x01a1, -1}, /* 1x Æ¡ ..Æ¡ â Æ ..Æ Watin-B */
{0x01a3, 0x01a3, -1}, /* 1x Æ£ ..Æ£ â Æ¢ ..Æ¢ Watin-B */
{0x01a5, 0x01a5, -1}, /* 1x Æ¥ ..Æ¥ â Æ¤ ..Ƥ Watin-B */
{0x01a8, 0x01a8, -1}, /* 1x ƨ ..ƨ â Æ§ ..Ƨ Watin-B */
{0x01ad, 0x01ad, -1}, /* 1x Æ ..Æ â Æ¬ ..Ƭ Watin-B */
{0x01b0, 0x01b0, -1}, /* 1x ư ..ư â Æ¯ ..Ư Watin-B */
{0x01b4, 0x01b4, -1}, /* 1x Æ´ ..Æ´ â Æ³ ..Ƴ Watin-B */
{0x01b6, 0x01b6, -1}, /* 1x ƶ ..ƶ â Æµ ..Ƶ Watin-B */
{0x01b9, 0x01b9, -1}, /* 1x ƹ ..ƹ â Æ¸ ..Ƹ Watin-B */
{0x01bd, 0x01bd, -1}, /* 1x ƽ ..ƽ â Æ¼ ..Ƽ Watin-B */
{0x01bf, 0x01bf, +56}, /* 1x Æ¿ ..Æ¿ â Ç· ..Ç· Watin-B */
{0x01c5, 0x01c5, -1}, /* 1x Ç
..Ç
â Ç ..Ç Watin-B */
{0x01c6, 0x01c6, -2}, /* 1x Ç ..Ç â Ç ..Ç Watin-B */
{0x01c8, 0x01c8, -1}, /* 1x Ç ..Ç â Ç ..Ç Watin-B */
{0x01c9, 0x01c9, -2}, /* 1x Ç ..Ç â Ç ..Ç Watin-B */
{0x01cb, 0x01cb, -1}, /* 1x Ç ..Ç â Ç ..Ç Watin-B */
{0x01cc, 0x01cc, -2}, /* 1x Ç ..Ç â Ç ..Ç Watin-B */
{0x01ce, 0x01ce, -1}, /* 1x Ç ..Ç â Ç ..Ç Watin-B */
{0x01dd, 0x01dd, -79}, /* 1x Ç ..Ç â Æ ..Æ Watin-B */
{0x01f2, 0x01f2, -1}, /* 1x Dz ..Dz â DZ ..DZ Watin-B */
{0x01f3, 0x01f3, -2}, /* 1x dz ..dz â DZ ..DZ Watin-B */
{0x01f5, 0x01f5, -1}, /* 1x ǵ ..ǵ â Ç´ ..Ç´ Watin-B */
{0x023c, 0x023c, -1}, /* 1x ȼ ..ȼ â È» ..È» Watin-B */
{0x023f, 0x0240, +10815}, /* 2x È¿ ..É â â±¾ ..Ɀ Watin-B */
{0x0242, 0x0242, -1}, /* 1x É ..É â É ..É Watin-B */
{0x0247, 0x0247, -1}, /* 1x É ..É â É ..É Watin-B */
{0x0249, 0x0249, -1}, /* 1x É ..É â É ..É Watin-B */
{0x024b, 0x024b, -1}, /* 1x É ..É â É ..É Watin-B */
{0x024d, 0x024d, -1}, /* 1x É ..É â É ..É Watin-B */
{0x024f, 0x024f, -1}, /* 1x É ..É â É ..É Watin-B */
{0x037b, 0x037d, +130}, /* 3x Í» ..ͽ â Ͻ ..Ï¿ Greek */
{0x03ac, 0x03ac, -38}, /* 1x ά ..ά â Î ..Î Greek */
{0x03ad, 0x03af, -37}, /* 3x Î ..ί â Î ..Î Greek */
{0x03b1, 0x03c1, -32}, /* 17x α ..Ï â Î ..Ρ Greek */
{0x03c2, 0x03c2, -31}, /* 1x Ï ..Ï â Σ ..Σ Greek */
{0x03c3, 0x03cb, -32}, /* 9x Ï ..Ï â Σ ..Ϋ Greek */
{0x03cc, 0x03cc, -64}, /* 1x Ï ..Ï â Î ..Î Greek */
{0x03cd, 0x03ce, -63}, /* 2x Ï ..Ï â Î ..Î Greek */
{0x03d0, 0x03d0, -62}, /* 1x Ï ..Ï â Î ..Î Greek */
{0x03d1, 0x03d1, -57}, /* 1x Ï ..Ï â Î ..Î Greek */
{0x03d5, 0x03d5, -47}, /* 1x Ï ..Ï â Φ ..Φ Greek */
{0x03d6, 0x03d6, -54}, /* 1x Ï ..Ï â Î ..Î Greek */
{0x03dd, 0x03dd, -1}, /* 1x Ï ..Ï â Ï ..Ï Greek */
{0x03f0, 0x03f0, -86}, /* 1x ϰ ..ϰ â Î ..Î Greek */
{0x03f1, 0x03f1, -80}, /* 1x ϱ ..ϱ â Ρ ..Ρ Greek */
{0x03f5, 0x03f5, -96}, /* 1x ϵ ..ϵ â Î ..Î Greek */
{0x0430, 0x044f, -32}, /* 32x а ..Ñ â Ð ..Я Cyrillic */
{0x0450, 0x045f, -80}, /* 16x Ñ ..Ñ â Ð ..Ð Cyrillic */
{0x0461, 0x0461, -1}, /* 1x Ñ¡ ..Ñ¡ â Ñ ..Ñ Cyrillic */
{0x0463, 0x0463, -1}, /* 1x Ñ£ ..Ñ£ â Ñ¢ ..Ñ¢ Cyrillic */
{0x0465, 0x0465, -1}, /* 1x Ñ¥ ..Ñ¥ â Ѥ ..Ѥ Cyrillic */
{0x0473, 0x0473, -1}, /* 1x ѳ ..ѳ â Ѳ ..Ѳ Cyrillic */
{0x0491, 0x0491, -1}, /* 1x Ò ..Ò â Ò ..Ò Cyrillic */
{0x0499, 0x0499, -1}, /* 1x Ò ..Ò â Ò ..Ò Cyrillic */
{0x049b, 0x049b, -1}, /* 1x Ò ..Ò â Ò ..Ò Cyrillic */
{0x0561, 0x0586, -48}, /* 38x Õ¡ ..Ö â Ô± ..Õ Armenian */
{0x10d0, 0x10fa, +3008}, /* 43x á ..Ạâ á² ..Ჺ Georgian */
{0x10fd, 0x10ff, +3008}, /* 3x á½ ..á¿ â á²½ ..Ჿ Georgian */
{0x13f8, 0x13fd, -8}, /* 6x Ḡ..á½ â á° ..áµ Cherokee */
{0x214e, 0x214e, -28}, /* 1x â
..â
â â² ..â² Letterlike */
{0x2170, 0x217f, -16}, /* 16x â
° ..â
¿ â â
..â
¯ Numbery */
{0x2184, 0x2184, -1}, /* 1x â ..â â â ..â Numbery */
{0x24d0, 0x24e9, -26}, /* 26x â ..â© â â¶ ..â Enclosed */
{0x2c30, 0x2c5e, -48}, /* 47x â°° ..â± â â° ..â°® Glagolitic */
{0x2d00, 0x2d25, -7264}, /* 38x â´ ..â´¥ â á ..á
Georgian2 */
{0x2d27, 0x2d27, -7264}, /* 1x â´§ ..â´§ â á ..á Georgian2 */
{0x2d2d, 0x2d2d, -7264}, /* 1x â´ ..â´ â á ..á Georgian2 */
{0xff41, 0xff5a, -32}, /* 26x ï½..ï½ â A..Z Dubs */
};
static const int kAstralUpper[][3] = {
{0x10428, 0x1044f, -40}, /* 40x ð¨..ð â ð..ð§ Deseret */
{0x104d8, 0x104fb, -40}, /* 36x ð..ð» â ð°..ð Osage */
{0x1d41a, 0x1d433, -26}, /* 26x ð..ð³ â ð..ð Math */
{0x1d456, 0x1d467, -26}, /* 18x ð..ð§ â ð¼..ð Math */
{0x1d482, 0x1d49b, -26}, /* 26x ð..ð â ð¨..ð Math */
{0x1d4c8, 0x1d4cf, -26}, /* 8x ð..ð â ð®..ðµ Math */
{0x1d4ea, 0x1d503, -26}, /* 26x ðª..ð â ð..ð© Math */
{0x1d527, 0x1d52e, -26}, /* 8x ð§..ð® â ð..ð Math */
{0x1d586, 0x1d59f, -26}, /* 26x ð..ð â ð¬..ð
Math */
{0x1d5ba, 0x1d5d3, -26}, /* 26x ðº..ð â ð ..ð¹ Math */
{0x1d5ee, 0x1d607, -26}, /* 26x ð®..ð â ð..ð Math */
{0x1d622, 0x1d63b, -26}, /* 26x ð¢..ð» â ð..ð¡ Math */
{0x1d68a, 0x1d6a3, +442}, /* 26x ð..ð â ð¼..ð Math */
{0x1d6c2, 0x1d6d2, -26}, /* 26x ð..ð£ â ð°..ð Math */
{0x1d6fc, 0x1d70c, -26}, /* 17x ð..ð â ð¨..ð¸ Math */
{0x1d736, 0x1d746, -26}, /* 17x ð¼..ð â ð¢..ð² Math */
{0x1d770, 0x1d780, -26}, /* 17x ð¶..ð â ð..ð¬ Math */
{0x1d770, 0x1d756, -26}, /* 17x ð°..ð â ð..ð¦ Math */
{0x1d736, 0x1d790, -90}, /* 17x ð¶..ð â ð..ð Math */
};
/**
* Converts wide character to upper case.
*/
wint_t towupper(wint_t c) {
int m, l, r, n;
if (c < 0200) {
if ('a' <= c && c <= 'z') {
return c - 32;
} else {
return c;
}
} else if (c <= 0xffff) {
if ((0x0101 <= c && c <= 0x0177) || /* 60x Ä..ŵ â Ä..Ä Watin-A */
(0x01df <= c && c <= 0x01ef) || /* 9x Ç..ǯ â Ç..Ç® Watin-B */
(0x01f8 <= c && c <= 0x021e) || /* 20x ǹ..È â Ǹ..È Watin-B */
(0x0222 <= c && c <= 0x0232) || /* 9x È£..ȳ â È¢..Ȳ Watin-B */
(0x1e01 <= c && c <= 0x1eff)) { /*256x á¸..ỿ â á¸..Ỿ Watin-C */
if (c == 0x0131) return c + 232;
if (c == 0x1e9e) return c;
return c - (c & 1);
} else if (0x01d0 <= c && c <= 0x01dc) {
return c - (~c & 1); /* 7x Ç..Ç â Ç..Ç Watin-B */
} else if (0xab70 <= c && c <= 0xabbf) {
return c - 38864; /* 80x ê° ..ꮿ â á ..ᯠCherokee Supplement */
} else {
l = 0;
r = n = sizeof(kUpper) / sizeof(kUpper[0]);
while (l < r) {
m = (l + r) >> 1;
if (kUpper[m].y < c) {
l = m + 1;
} else {
r = m;
}
}
if (l < n && kUpper[l].x <= c && c <= kUpper[l].y) {
return c + kUpper[l].d;
} else {
return c;
}
}
} else {
l = 0;
r = n = sizeof(kAstralUpper) / sizeof(kAstralUpper[0]);
while (l < r) {
m = (l + r) >> 1;
if (kAstralUpper[m][1] < c) {
l = m + 1;
} else {
r = m;
}
}
if (l < n && kAstralUpper[l][0] <= c && c <= kAstralUpper[l][1]) {
return c + kAstralUpper[l][2];
} else {
return c;
}
}
}
| 11,161 | 198 | jart/cosmopolitan | false |
cosmopolitan/libc/str/rawmemchr.c | /*-*- 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 â
â â
â 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/assert.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/str/str.h"
static inline const unsigned char *rawmemchr_pure(const unsigned char *s,
unsigned char c) {
for (;; ++s) {
if (*s == c) {
return s;
}
}
}
#ifdef __x86_64__
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
noasan static inline const char *rawmemchr_sse(const char *s, unsigned char c) {
unsigned k;
unsigned m;
xmm_t v, *p;
xmm_t n = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
k = (uintptr_t)s & 15;
p = (const xmm_t *)((uintptr_t)s & -16);
v = *p;
m = __builtin_ia32_pmovmskb128(v == n);
m >>= k;
m <<= k;
while (!m) {
v = *++p;
m = __builtin_ia32_pmovmskb128(v == n);
}
m = __builtin_ctzll(m);
return (const char *)p + m;
}
#endif
static inline noasan uint64_t UncheckedAlignedRead64(unsigned char *p) {
return (uint64_t)p[7] << 070 | (uint64_t)p[6] << 060 | (uint64_t)p[5] << 050 |
(uint64_t)p[4] << 040 | (uint64_t)p[3] << 030 | (uint64_t)p[2] << 020 |
(uint64_t)p[1] << 010 | (uint64_t)p[0] << 000;
}
/**
* Returns pointer to first instance of character.
*
* @param m is memory to search
* @param c is search byte which is masked with 255
* @return is pointer to first instance of c
*/
void *rawmemchr(const void *s, int c) {
#ifdef __x86_64__
const void *r;
if (X86_HAVE(SSE)) {
if (IsAsan()) __asan_verify(s, 1);
r = rawmemchr_sse(s, c);
} else {
r = rawmemchr_pure(s, c);
}
return (void *)r;
#else
uint64_t v, w;
const unsigned char *p;
p = s;
c &= 255;
v = 0x0101010101010101ul * c;
for (; (uintptr_t)p & 7; ++p) {
if (*p == c) return p;
}
for (;; p += 8) {
w = UncheckedAlignedRead64(p);
if ((w = ~(w ^ v) & ((w ^ v) - 0x0101010101010101) & 0x8080808080808080)) {
p += (unsigned)__builtin_ctzll(w) >> 3;
break;
}
}
assert(*p == c);
return p;
#endif
}
| 3,886 | 99 | jart/cosmopolitan | false |
cosmopolitan/libc/str/iswlower.c | /*-*- 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/str/str.h"
/**
* Returns nonzero if c is lowercase letter.
*/
int iswlower(wint_t c) {
int r;
if (c < 0200) {
return 'a' <= c && c <= 'z';
} else {
if (towupper(c) != c) return 1;
switch (c) {
case 0x00df: /* Ã Watin */
case 0x0138: /* ĸ Watin-A */
case 0x0149: /* Å Watin-A */
case 0x018d: /* Æ Watin-B */
case 0x019b: /* Æ Watin-B */
case 0x01aa: /* ƪ Watin-B */
case 0x01ab: /* Æ« Watin-B */
case 0x01ba: /* ƺ Watin-B */
case 0x01be: /* ƾ Watin-B */
case 0x01f0: /* ǰ Watin-B */
case 0x0221: /* È¡ Watin-B */
case 0x0234: /* È´ Watin-B */
case 0x0235: /* ȵ Watin-B */
case 0x0236: /* ȶ Watin-B */
case 0x0237: /* È· Watin-B */
case 0x0238: /* ȸ Watin-B */
case 0x0239: /* ȹ Watin-B */
case 0x0255: /* É IPA */
case 0x0258: /* É IPA */
case 0x025a: /* É IPA */
case 0x025d: /* É IPA */
case 0x025e: /* É IPA */
case 0x025f: /* É IPA */
case 0x0262: /* ɢ IPA */
case 0x0264: /* ɤ IPA */
case 0x0267: /* ɧ IPA */
case 0x026d: /* É IPA */
case 0x026e: /* É® IPA */
case 0x0270: /* ɰ IPA */
case 0x0273: /* ɳ IPA */
case 0x0274: /* É´ IPA */
case 0x0276: /* ɶ IPA */
case 0x0277: /* É· IPA */
case 0x0278: /* ɸ IPA */
case 0x0279: /* ɹ IPA */
case 0x027a: /* ɺ IPA */
case 0x027b: /* É» IPA */
case 0x027c: /* ɼ IPA */
case 0x027e: /* ɾ IPA */
case 0x027f: /* É¿ IPA */
case 0x0281: /* Ê IPA */
case 0x0284: /* Ê IPA */
case 0x0285: /* Ê
IPA */
case 0x0286: /* Ê IPA */
case 0x028d: /* Ê IPA */
case 0x028e: /* Ê IPA */
case 0x028f: /* Ê IPA */
case 0x0290: /* Ê IPA */
case 0x0291: /* Ê IPA */
case 0x0293: /* Ê IPA */
case 0x0295: /* Ê IPA */
case 0x0296: /* Ê IPA */
case 0x0297: /* Ê IPA */
case 0x0298: /* Ê IPA */
case 0x0299: /* Ê IPA */
case 0x029a: /* Ê IPA */
case 0x029b: /* Ê IPA */
case 0x029c: /* Ê IPA */
case 0x029f: /* Ê IPA */
case 0x02a0: /* Ê IPA */
case 0x02a1: /* Ê¡ IPA */
case 0x02a2: /* ʢ IPA */
case 0x02a3: /* ʣ IPA */
case 0x02a4: /* ʤ IPA */
case 0x02a5: /* ʥ IPA */
case 0x02a6: /* ʦ IPA */
case 0x02a7: /* ʧ IPA */
case 0x02a8: /* ʨ IPA */
case 0x02a9: /* Ê© IPA */
case 0x02aa: /* ʪ IPA */
case 0x02ab: /* Ê« IPA */
case 0x02ac: /* ʬ IPA */
case 0x02ad: /* Ê IPA */
case 0x02ae: /* Ê® IPA */
case 0x02af: /* ʯ IPA */
case 0x0390: /* Î Greek */
case 0x03b0: /* ΰ Greek */
case 0x03fc: /* ϼ Greek */
case 0x0560: /* Õ Armenian */
case 0x0587: /* Ö Armenian */
case 0x0588: /* Ö Armenian */
case 0x1d00: /* á´ Phonetic Extensions */
case 0x1d01: /* á´ Phonetic Extensions */
case 0x1d02: /* á´ Phonetic Extensions */
case 0x1d03: /* á´ Phonetic Extensions */
case 0x1d04: /* á´ Phonetic Extensions */
case 0x1d05: /* á´
Phonetic Extensions */
case 0x1d06: /* á´ Phonetic Extensions */
case 0x1d07: /* á´ Phonetic Extensions */
case 0x1d08: /* á´ Phonetic Extensions */
case 0x1d09: /* á´ Phonetic Extensions */
case 0x1d0a: /* á´ Phonetic Extensions */
case 0x1d0b: /* á´ Phonetic Extensions */
case 0x1d0c: /* á´ Phonetic Extensions */
case 0x1d0d: /* á´ Phonetic Extensions */
case 0x1d0e: /* á´ Phonetic Extensions */
case 0x1d0f: /* á´ Phonetic Extensions */
case 0x1d10: /* á´ Phonetic Extensions */
case 0x1d11: /* á´ Phonetic Extensions */
case 0x1d12: /* á´ Phonetic Extensions */
case 0x1d13: /* á´ Phonetic Extensions */
case 0x1d14: /* á´ Phonetic Extensions */
case 0x1d15: /* á´ Phonetic Extensions */
case 0x1d16: /* á´ Phonetic Extensions */
case 0x1d17: /* á´ Phonetic Extensions */
case 0x1d18: /* á´ Phonetic Extensions */
case 0x1d19: /* á´ Phonetic Extensions */
case 0x1d1a: /* á´ Phonetic Extensions */
case 0x1d1b: /* á´ Phonetic Extensions */
case 0x1d1c: /* á´ Phonetic Extensions */
case 0x1d1d: /* á´ Phonetic Extensions */
case 0x1d1e: /* á´ Phonetic Extensions */
case 0x1d1f: /* á´ Phonetic Extensions */
case 0x1d20: /* á´ Phonetic Extensions */
case 0x1d21: /* á´¡ Phonetic Extensions */
case 0x1d22: /* á´¢ Phonetic Extensions */
case 0x1d23: /* á´£ Phonetic Extensions */
case 0x1d24: /* á´¤ Phonetic Extensions */
case 0x1d25: /* á´¥ Phonetic Extensions */
case 0x1d26: /* á´¦ Phonetic Extensions */
case 0x1d27: /* á´§ Phonetic Extensions */
case 0x1d28: /* á´¨ Phonetic Extensions */
case 0x1d29: /* á´© Phonetic Extensions */
case 0x1d2a: /* á´ª Phonetic Extensions */
case 0x1d2b: /* á´« Phonetic Extensions */
case 0x1d6b: /* ᵫ Phonetic Extensions */
case 0x1d6c: /* ᵬ Phonetic Extensions */
case 0x1d6d: /* áµ Phonetic Extensions */
case 0x1d6e: /* áµ® Phonetic Extensions */
case 0x1d6f: /* ᵯ Phonetic Extensions */
case 0x1d70: /* áµ° Phonetic Extensions */
case 0x1d71: /* áµ± Phonetic Extensions */
case 0x1d72: /* áµ² Phonetic Extensions */
case 0x1d73: /* áµ³ Phonetic Extensions */
case 0x1d74: /* áµ´ Phonetic Extensions */
case 0x1d75: /* áµµ Phonetic Extensions */
case 0x1d76: /* áµ¶ Phonetic Extensions */
case 0x1d77: /* áµ· Phonetic Extensions */
case 0x1d7a: /* ᵺ Phonetic Extensions */
case 0x1d7b: /* áµ» Phonetic Extensions */
case 0x1d7c: /* áµ¼ Phonetic Extensions */
case 0x1d7e: /* áµ¾ Phonetic Extensions */
case 0x1d7f: /* ᵿ Phonetic Extensions */
case 0x1d80: /* . Phonetic Extensions Supplement */
case 0x1d81: /* . Phonetic Extensions Supplement */
case 0x1d82: /* . Phonetic Extensions Supplement */
case 0x1d83: /* . Phonetic Extensions Supplement */
case 0x1d84: /* . Phonetic Extensions Supplement */
case 0x1d85: /* . Phonetic Extensions Supplement */
case 0x1d86: /* . Phonetic Extensions Supplement */
case 0x1d87: /* . Phonetic Extensions Supplement */
case 0x1d88: /* . Phonetic Extensions Supplement */
case 0x1d89: /* . Phonetic Extensions Supplement */
case 0x1d8a: /* . Phonetic Extensions Supplement */
case 0x1d8b: /* . Phonetic Extensions Supplement */
case 0x1d8c: /* . Phonetic Extensions Supplement */
case 0x1d8d: /* . Phonetic Extensions Supplement */
case 0x1d8f: /* . Phonetic Extensions Supplement */
case 0x1d90: /* . Phonetic Extensions Supplement */
case 0x1d91: /* . Phonetic Extensions Supplement */
case 0x1d92: /* . Phonetic Extensions Supplement */
case 0x1d93: /* . Phonetic Extensions Supplement */
case 0x1d94: /* . Phonetic Extensions Supplement */
case 0x1d95: /* . Phonetic Extensions Supplement */
case 0x1d96: /* . Phonetic Extensions Supplement */
case 0x1d97: /* . Phonetic Extensions Supplement */
case 0x1d98: /* . Phonetic Extensions Supplement */
case 0x1d99: /* . Phonetic Extensions Supplement */
case 0x1d9a: /* . Phonetic Extensions Supplement */
case 0x1e96: /* ẠWatin-C */
case 0x1e97: /* ẠWatin-C */
case 0x1e98: /* ẠWatin-C */
case 0x1e99: /* ẠWatin-C */
case 0x1e9a: /* ẠWatin-C */
case 0x1e9c: /* ẠWatin-C */
case 0x1e9d: /* ẠWatin-C */
case 0x1e9f: /* ẠWatin-C */
case 0x1f50: /* á½ Greek2 */
case 0x1f52: /* á½ Greek2 */
case 0x1f54: /* á½ Greek2 */
case 0x1f56: /* á½ Greek2 */
case 0x1fb2: /* á¾² Greek2 */
case 0x1fb4: /* á¾´ Greek2 */
case 0x1fb6: /* á¾¶ Greek2 */
case 0x1fb7: /* á¾· Greek2 */
case 0x1fc2: /* á¿ Greek2 */
case 0x1fc4: /* á¿ Greek2 */
case 0x1fc6: /* á¿ Greek2 */
case 0x1fc7: /* á¿ Greek2 */
case 0x1fd2: /* á¿ Greek2 */
case 0x1fd3: /* á¿ Greek2 */
case 0x1fd6: /* á¿ Greek2 */
case 0x1fd7: /* á¿ Greek2 */
case 0x1fe2: /* á¿¢ Greek2 */
case 0x1fe3: /* á¿£ Greek2 */
case 0x1fe4: /* ῤ Greek2 */
case 0x1fe6: /* ῦ Greek2 */
case 0x1fe7: /* á¿§ Greek2 */
case 0x1ff2: /* ῲ Greek2 */
case 0x1ff4: /* á¿´ Greek2 */
case 0x1ff6: /* á¿¶ Greek2 */
case 0x1ff7: /* á¿· Greek2 */
case 0x210a: /* â Letterlike */
case 0x210e: /* â Letterlike */
case 0x210f: /* â Letterlike */
case 0x2113: /* â Letterlike */
case 0x212f: /* ⯠Letterlike */
case 0x2134: /* â´ Letterlike */
case 0x2139: /* â¹ Letterlike */
case 0x213c: /* â¼ Letterlike */
case 0x213d: /* â½ Letterlike */
case 0x2146: /* â
Letterlike */
case 0x2147: /* â
Letterlike */
case 0x2148: /* â
Letterlike */
case 0x2149: /* â
Letterlike */
case 0x2c71: /* . Watin-D */
case 0x2c74: /* . Watin-D */
case 0x2c77: /* . Watin-D */
case 0x2c78: /* . Watin-D */
case 0x2c79: /* . Watin-D */
case 0x2c7a: /* . Watin-D */
case 0x2c7b: /* . Watin-D */
case 0x2ce4: /* . Coptic */
case 0xa730: /* . Latin Extended-D */
case 0xa731: /* . Latin Extended-D */
case 0xa771: /* . Latin Extended-D */
case 0xa772: /* . Latin Extended-D */
case 0xa773: /* . Latin Extended-D */
case 0xa774: /* . Latin Extended-D */
case 0xa775: /* . Latin Extended-D */
case 0xa776: /* . Latin Extended-D */
case 0xa777: /* . Latin Extended-D */
case 0xa778: /* . Latin Extended-D */
case 0xa78e: /* . Latin Extended-D */
case 0xa795: /* . Latin Extended-D */
case 0xa7af: /* . Latin Extended-D */
case 0xa7fa: /* . Latin Extended-D */
case 0xab30: /* . Latin Extended-E */
case 0xab31: /* . Latin Extended-E */
case 0xab32: /* . Latin Extended-E */
case 0xab33: /* . Latin Extended-E */
case 0xab34: /* . Latin Extended-E */
case 0xab35: /* . Latin Extended-E */
case 0xab36: /* . Latin Extended-E */
case 0xab37: /* . Latin Extended-E */
case 0xab38: /* . Latin Extended-E */
case 0xab39: /* . Latin Extended-E */
case 0xab3a: /* . Latin Extended-E */
case 0xab3b: /* . Latin Extended-E */
case 0xab3c: /* . Latin Extended-E */
case 0xab3d: /* . Latin Extended-E */
case 0xab3e: /* . Latin Extended-E */
case 0xab3f: /* . Latin Extended-E */
case 0xab40: /* . Latin Extended-E */
case 0xab41: /* . Latin Extended-E */
case 0xab42: /* . Latin Extended-E */
case 0xab43: /* . Latin Extended-E */
case 0xab44: /* . Latin Extended-E */
case 0xab45: /* . Latin Extended-E */
case 0xab46: /* . Latin Extended-E */
case 0xab47: /* . Latin Extended-E */
case 0xab48: /* . Latin Extended-E */
case 0xab49: /* . Latin Extended-E */
case 0xab4a: /* . Latin Extended-E */
case 0xab4b: /* . Latin Extended-E */
case 0xab4c: /* . Latin Extended-E */
case 0xab4d: /* . Latin Extended-E */
case 0xab4e: /* . Latin Extended-E */
case 0xab4f: /* . Latin Extended-E */
case 0xab50: /* . Latin Extended-E */
case 0xab51: /* . Latin Extended-E */
case 0xab52: /* . Latin Extended-E */
case 0xab54: /* . Latin Extended-E */
case 0xab55: /* . Latin Extended-E */
case 0xab56: /* . Latin Extended-E */
case 0xab57: /* . Latin Extended-E */
case 0xab58: /* . Latin Extended-E */
case 0xab59: /* . Latin Extended-E */
case 0xab5a: /* . Latin Extended-E */
case 0xab60: /* . Latin Extended-E */
case 0xab61: /* . Latin Extended-E */
case 0xab62: /* . Latin Extended-E */
case 0xab63: /* . Latin Extended-E */
case 0xab64: /* . Latin Extended-E */
case 0xab65: /* . Latin Extended-E */
case 0xab66: /* . Latin Extended-E */
case 0xab67: /* . Latin Extended-E */
case 0xfb00: /* . Alphabetic Presentation Forms */
case 0xfb01: /* . Alphabetic Presentation Forms */
case 0xfb02: /* . Alphabetic Presentation Forms */
case 0xfb03: /* . Alphabetic Presentation Forms */
case 0xfb04: /* . Alphabetic Presentation Forms */
case 0xfb05: /* . Alphabetic Presentation Forms */
case 0xfb06: /* . Alphabetic Presentation Forms */
case 0xfb13: /* . Alphabetic Presentation Forms */
case 0xfb14: /* . Alphabetic Presentation Forms */
case 0xfb15: /* . Alphabetic Presentation Forms */
case 0xfb16: /* . Alphabetic Presentation Forms */
case 0xfb17: /* . Alphabetic Presentation Forms */
case 0x1d44e: /* ð Math */
case 0x1d44f: /* ð Math */
case 0x1d450: /* ð Math */
case 0x1d451: /* ð Math */
case 0x1d452: /* ð Math */
case 0x1d453: /* ð Math */
case 0x1d454: /* ð Math */
case 0x1d45e: /* ð Math */
case 0x1d45f: /* ð Math */
case 0x1d460: /* ð Math */
case 0x1d461: /* ð¡ Math */
case 0x1d462: /* ð¢ Math */
case 0x1d463: /* ð£ Math */
case 0x1d464: /* ð¤ Math */
case 0x1d465: /* ð¥ Math */
case 0x1d466: /* ð¦ Math */
case 0x1d467: /* ð§ Math */
case 0x1d4b6: /* ð¶ Math */
case 0x1d4b7: /* ð· Math */
case 0x1d4b8: /* ð¸ Math */
case 0x1d4b9: /* ð¹ Math */
case 0x1d4bb: /* ð» Math */
case 0x1d4bd: /* ð½ Math */
case 0x1d4be: /* ð¾ Math */
case 0x1d4bf: /* ð¿ Math */
case 0x1d4c0: /* ð Math */
case 0x1d4c1: /* ð Math */
case 0x1d4c2: /* ð Math */
case 0x1d4c3: /* ð Math */
case 0x1d4c5: /* ð
Math */
case 0x1d4c6: /* ð Math */
case 0x1d4c7: /* ð Math */
case 0x1d51e: /* ð Math */
case 0x1d51f: /* ð Math */
case 0x1d520: /* ð Math */
case 0x1d521: /* ð¡ Math */
case 0x1d522: /* ð¢ Math */
case 0x1d523: /* ð£ Math */
case 0x1d524: /* ð¤ Math */
case 0x1d525: /* ð¥ Math */
case 0x1d526: /* ð¦ Math */
case 0x1d52f: /* ð¯ Math */
case 0x1d530: /* ð° Math */
case 0x1d531: /* ð± Math */
case 0x1d532: /* ð² Math */
case 0x1d533: /* ð³ Math */
case 0x1d534: /* ð´ Math */
case 0x1d535: /* ðµ Math */
case 0x1d536: /* ð¶ Math */
case 0x1d537: /* ð· Math */
case 0x1d552: /* ð Math */
case 0x1d553: /* ð Math */
case 0x1d554: /* ð Math */
case 0x1d555: /* ð Math */
case 0x1d556: /* ð Math */
case 0x1d557: /* ð Math */
case 0x1d558: /* ð Math */
case 0x1d559: /* ð Math */
case 0x1d55a: /* ð Math */
case 0x1d55b: /* ð Math */
case 0x1d55c: /* ð Math */
case 0x1d55d: /* ð Math */
case 0x1d55e: /* ð Math */
case 0x1d55f: /* ð Math */
case 0x1d560: /* ð Math */
case 0x1d561: /* ð¡ Math */
case 0x1d562: /* ð¢ Math */
case 0x1d563: /* ð£ Math */
case 0x1d564: /* ð¤ Math */
case 0x1d565: /* ð¥ Math */
case 0x1d566: /* ð¦ Math */
case 0x1d567: /* ð§ Math */
case 0x1d568: /* ð¨ Math */
case 0x1d569: /* ð© Math */
case 0x1d56a: /* ðª Math */
case 0x1d56b: /* ð« Math */
case 0x1d656: /* ð Math */
case 0x1d657: /* ð Math */
case 0x1d658: /* ð Math */
case 0x1d659: /* ð Math */
case 0x1d65a: /* ð Math */
case 0x1d65b: /* ð Math */
case 0x1d65c: /* ð Math */
case 0x1d65d: /* ð Math */
case 0x1d65e: /* ð Math */
case 0x1d65f: /* ð Math */
case 0x1d660: /* ð Math */
case 0x1d661: /* ð¡ Math */
case 0x1d662: /* ð¢ Math */
case 0x1d663: /* ð£ Math */
case 0x1d664: /* ð¤ Math */
case 0x1d665: /* ð¥ Math */
case 0x1d666: /* ð¦ Math */
case 0x1d667: /* ð§ Math */
case 0x1d668: /* ð¨ Math */
case 0x1d669: /* ð© Math */
case 0x1d66a: /* ðª Math */
case 0x1d66b: /* ð« Math */
case 0x1d66c: /* ð¬ Math */
case 0x1d66d: /* ð Math */
case 0x1d66e: /* ð® Math */
case 0x1d66f: /* ð¯ Math */
case 0x1d6da: /* ð Math */
case 0x1d6dc: /* ð Math */
case 0x1d6dd: /* ð Math */
case 0x1d6de: /* ð Math */
case 0x1d6df: /* ð Math */
case 0x1d6e0: /* ð Math */
case 0x1d6e1: /* ð¡ Math */
case 0x1d70d: /* ð Math */
case 0x1d70e: /* ð Math */
case 0x1d70f: /* ð Math */
case 0x1d710: /* ð Math */
case 0x1d711: /* ð Math */
case 0x1d712: /* ð Math */
case 0x1d713: /* ð Math */
case 0x1d714: /* ð Math */
case 0x1d716: /* ð Math */
case 0x1d717: /* ð Math */
case 0x1d718: /* ð Math */
case 0x1d719: /* ð Math */
case 0x1d71a: /* ð Math */
case 0x1d71b: /* ð Math */
case 0x1d747: /* ð Math */
case 0x1d748: /* ð Math */
case 0x1d749: /* ð Math */
case 0x1d74a: /* ð Math */
case 0x1d74b: /* ð Math */
case 0x1d74c: /* ð Math */
case 0x1d74d: /* ð Math */
case 0x1d74e: /* ð Math */
case 0x1d750: /* ð Math */
case 0x1d751: /* ð Math */
case 0x1d752: /* ð Math */
case 0x1d753: /* ð Math */
case 0x1d754: /* ð Math */
case 0x1d755: /* ð Math */
case 0x1d781: /* ð Math */
case 0x1d782: /* ð Math */
case 0x1d783: /* ð Math */
case 0x1d784: /* ð Math */
case 0x1d785: /* ð
Math */
case 0x1d786: /* ð Math */
case 0x1d787: /* ð Math */
case 0x1d788: /* ð Math */
case 0x1d78a: /* ð Math */
case 0x1d78b: /* ð Math */
case 0x1d78c: /* ð Math */
case 0x1d78d: /* ð Math */
case 0x1d78e: /* ð Math */
case 0x1d78f: /* ð Math */
case 0x1d7aa: /* ðª Math */
case 0x1d7ab: /* ð« Math */
case 0x1d7ac: /* ð¬ Math */
case 0x1d7ad: /* ð Math */
case 0x1d7ae: /* ð® Math */
case 0x1d7af: /* ð¯ Math */
case 0x1d7b0: /* ð° Math */
case 0x1d7b1: /* ð± Math */
case 0x1d7b2: /* ð² Math */
case 0x1d7b3: /* ð³ Math */
case 0x1d7b4: /* ð´ Math */
case 0x1d7b5: /* ðµ Math */
case 0x1d7b6: /* ð¶ Math */
case 0x1d7b7: /* ð· Math */
case 0x1d7b8: /* ð¸ Math */
case 0x1d7b9: /* ð¹ Math */
case 0x1d7ba: /* ðº Math */
case 0x1d7bb: /* ð» Math */
case 0x1d7bc: /* ð¼ Math */
case 0x1d7bd: /* ð½ Math */
case 0x1d7be: /* ð¾ Math */
case 0x1d7bf: /* ð¿ Math */
case 0x1d7c0: /* ð Math */
case 0x1d7c1: /* ð Math */
case 0x1d7c2: /* ð Math */
case 0x1d7c4: /* ð Math */
case 0x1d7c5: /* ð
Math */
case 0x1d7c6: /* ð Math */
case 0x1d7c7: /* ð Math */
case 0x1d7c8: /* ð Math */
case 0x1d7c9: /* ð Math */
case 0x1d7cb: /* ð Math */
return 1;
default:
return 0;
}
}
}
| 21,735 | 519 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strchrnul16.c | /*-*- 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 pointer to first instance of character.
*/
char16_t *strchrnul16(const char16_t *s, int c) {
for (;; ++s) {
if ((*s & 65535) == (c & 65535)) return (char16_t *)s;
if (!*s) return (char16_t *)s;
}
}
| 2,089 | 30 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strlcpy.c | /*-*- 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â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright (c) 1998, 2015 Todd C. Miller <[email protected]> â
â â
â 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"
// clang-format off
// $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $
asm(".ident\t\"\\n\\n\
OpenBSD Strings (ISC)\\n\
Copyright (c) 1998, 2015 Todd C. Miller <[email protected]>\"");
asm(".include \"libc/disclaimer.inc\"");
/**
* Copies string, the BSD way.
*
* Copy string src to buffer `dst` of size `dsize`. At most `dsize-1`
* chars will be copied. Always NUL terminates (unless `dsize == 0`).
* Returns `strlen(src)`; if `retval >= dsize`, truncation occurred.
*/
size_t
strlcpy(char *dst, const char *src, size_t dsize)
{
const char *osrc = src;
size_t nleft = dsize;
/* Copy as many bytes as will fit. */
if (nleft != 0) {
while (--nleft != 0) {
if ((*dst++ = *src++) == '\0')
break;
}
}
/* Not enough room in dst, add NUL and traverse rest of src. */
if (nleft == 0) {
if (dsize != 0)
*dst = '\0'; /* NUL-terminate dst */
while (*src++)
;
}
return(src - osrc - 1); /* count does not include NUL */
}
| 2,829 | 59 | jart/cosmopolitan | false |
cosmopolitan/libc/str/dosdatetimetounix.c | /*-*- 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/macros.internal.h"
#include "libc/time/time.h"
/**
* Converts MS-DOS timestamp to UNIX.
*
* @note type signature supports dates greater than 2100
* @see PKZIP, FAT
*/
int64_t DosDateTimeToUnix(unsigned date, unsigned time) {
unsigned weekday, year, month, day, hour, minute, second, yday, leap;
year = ((date & 0xfffffe00) >> 9) + 1980 - 1900;
month = MAX(1, MIN(12, (date & 0x01e0) >> 5));
day = (date & 0x001f) ? (date & 0x001f) - 1 : 0;
hour = (time & 0x0000f800) >> 11;
minute = (time & 0x000007e0) >> 5;
second = (time & 0x0000001f) << 1;
leap = year % 4 == 0 && (year % 100 || year % 400 == 0);
yday = day + kMonthYearDay[leap][month - 1];
return second + minute * 60 + hour * 3600 + yday * 86400 +
(year - 70) * 31536000ull + ((year - 69) / 4) * 86400ull -
((year - 1) / 100) * 86400ull + ((year + 299) / 400) * 86400ull;
}
| 2,753 | 43 | jart/cosmopolitan | false |
cosmopolitan/libc/str/mbstowcs.c | /*-*- 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/fmt.h"
#include "libc/str/str.h"
size_t mbstowcs(wchar_t *pwc, const char *s, size_t wn) {
return mbsrtowcs(pwc, (void *)&s, wn, 0);
}
| 1,993 | 25 | jart/cosmopolitan | false |
cosmopolitan/libc/str/isxdigit.c | /*-*- 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/assert.h"
#include "libc/calls/calls.h"
#include "libc/limits.h"
#include "libc/str/str.h"
/**
* Returns true if c is hexadecimal digit.
*/
int isxdigit(int c) {
return ('0' <= c && c <= '9') || ('A' <= c && c <= 'F') ||
('a' <= c && c <= 'f');
}
| 2,112 | 31 | jart/cosmopolitan | false |
cosmopolitan/libc/str/toupper_l.c | /*-*- 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. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/locale.h"
#include "libc/str/str.h"
int toupper_l(int c, locale_t l) {
return toupper(c);
}
| 1,950 | 25 | jart/cosmopolitan | false |
cosmopolitan/libc/str/wcsstartswith.c | /*-*- 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/str/str.h"
/**
* Returns true if s has prefix.
*
* @param s is a NUL-terminated string
* @param prefix is also NUL-terminated
*/
bool _wcsstartswith(const wchar_t *s, const wchar_t *prefix) {
for (;;) {
if (!*prefix) return true;
if (!*s) return false;
if (*s++ != *prefix++) return false;
}
}
| 2,167 | 34 | jart/cosmopolitan | false |
cosmopolitan/libc/str/blocks.txt | # Blocks-14.0.0.txt
# Date: 2021-01-22, 23:29:00 GMT [KW]
# © 2021 Unicode®, Inc.
# For terms of use, see http://www.unicode.org/terms_of_use.html
#
# Unicode Character Database
# For documentation, see http://www.unicode.org/reports/tr44/
#
# Format:
# Start Code..End Code; Block Name
# ================================================
# Note: When comparing block names, casing, whitespace, hyphens,
# and underbars are ignored.
# For example, "Latin Extended-A" and "latin extended a" are equivalent.
# For more information on the comparison of property values,
# see UAX #44: http://www.unicode.org/reports/tr44/
#
# All block ranges start with a value where (cp MOD 16) = 0,
# and end with a value where (cp MOD 16) = 15. In other words,
# the last hexadecimal digit of the start of range is ...0
# and the last hexadecimal digit of the end of range is ...F.
# This constraint on block ranges guarantees that allocations
# are done in terms of whole columns, and that code chart display
# never involves splitting columns in the charts.
#
# All code points not explicitly listed for Block
# have the value No_Block.
# Property: Block
#
# @missing: 0000..10FFFF; No_Block
0000..007F; Basic Latin
0080..00FF; Latin-1 Supplement
0100..017F; Latin Extended-A
0180..024F; Latin Extended-B
0250..02AF; IPA Extensions
02B0..02FF; Spacing Modifier Letters
0300..036F; Combining Diacritical Marks
0370..03FF; Greek and Coptic
0400..04FF; Cyrillic
0500..052F; Cyrillic Supplement
0530..058F; Armenian
0590..05FF; Hebrew
0600..06FF; Arabic
0700..074F; Syriac
0750..077F; Arabic Supplement
0780..07BF; Thaana
07C0..07FF; NKo
0800..083F; Samaritan
0840..085F; Mandaic
0860..086F; Syriac Supplement
0870..089F; Arabic Extended-B
08A0..08FF; Arabic Extended-A
0900..097F; Devanagari
0980..09FF; Bengali
0A00..0A7F; Gurmukhi
0A80..0AFF; Gujarati
0B00..0B7F; Oriya
0B80..0BFF; Tamil
0C00..0C7F; Telugu
0C80..0CFF; Kannada
0D00..0D7F; Malayalam
0D80..0DFF; Sinhala
0E00..0E7F; Thai
0E80..0EFF; Lao
0F00..0FFF; Tibetan
1000..109F; Myanmar
10A0..10FF; Georgian
1100..11FF; Hangul Jamo
1200..137F; Ethiopic
1380..139F; Ethiopic Supplement
13A0..13FF; Cherokee
1400..167F; Unified Canadian Aboriginal Syllabics
1680..169F; Ogham
16A0..16FF; Runic
1700..171F; Tagalog
1720..173F; Hanunoo
1740..175F; Buhid
1760..177F; Tagbanwa
1780..17FF; Khmer
1800..18AF; Mongolian
18B0..18FF; Unified Canadian Aboriginal Syllabics Extended
1900..194F; Limbu
1950..197F; Tai Le
1980..19DF; New Tai Lue
19E0..19FF; Khmer Symbols
1A00..1A1F; Buginese
1A20..1AAF; Tai Tham
1AB0..1AFF; Combining Diacritical Marks Extended
1B00..1B7F; Balinese
1B80..1BBF; Sundanese
1BC0..1BFF; Batak
1C00..1C4F; Lepcha
1C50..1C7F; Ol Chiki
1C80..1C8F; Cyrillic Extended-C
1C90..1CBF; Georgian Extended
1CC0..1CCF; Sundanese Supplement
1CD0..1CFF; Vedic Extensions
1D00..1D7F; Phonetic Extensions
1D80..1DBF; Phonetic Extensions Supplement
1DC0..1DFF; Combining Diacritical Marks Supplement
1E00..1EFF; Latin Extended Additional
1F00..1FFF; Greek Extended
2000..206F; General Punctuation
2070..209F; Superscripts and Subscripts
20A0..20CF; Currency Symbols
20D0..20FF; Combining Diacritical Marks for Symbols
2100..214F; Letterlike Symbols
2150..218F; Number Forms
2190..21FF; Arrows
2200..22FF; Mathematical Operators
2300..23FF; Miscellaneous Technical
2400..243F; Control Pictures
2440..245F; Optical Character Recognition
2460..24FF; Enclosed Alphanumerics
2500..257F; Box Drawing
2580..259F; Block Elements
25A0..25FF; Geometric Shapes
2600..26FF; Miscellaneous Symbols
2700..27BF; Dingbats
27C0..27EF; Miscellaneous Mathematical Symbols-A
27F0..27FF; Supplemental Arrows-A
2800..28FF; Braille Patterns
2900..297F; Supplemental Arrows-B
2980..29FF; Miscellaneous Mathematical Symbols-B
2A00..2AFF; Supplemental Mathematical Operators
2B00..2BFF; Miscellaneous Symbols and Arrows
2C00..2C5F; Glagolitic
2C60..2C7F; Latin Extended-C
2C80..2CFF; Coptic
2D00..2D2F; Georgian Supplement
2D30..2D7F; Tifinagh
2D80..2DDF; Ethiopic Extended
2DE0..2DFF; Cyrillic Extended-A
2E00..2E7F; Supplemental Punctuation
2E80..2EFF; CJK Radicals Supplement
2F00..2FDF; Kangxi Radicals
2FF0..2FFF; Ideographic Description Characters
3000..303F; CJK Symbols and Punctuation
3040..309F; Hiragana
30A0..30FF; Katakana
3100..312F; Bopomofo
3130..318F; Hangul Compatibility Jamo
3190..319F; Kanbun
31A0..31BF; Bopomofo Extended
31C0..31EF; CJK Strokes
31F0..31FF; Katakana Phonetic Extensions
3200..32FF; Enclosed CJK Letters and Months
3300..33FF; CJK Compatibility
3400..4DBF; CJK Unified Ideographs Extension A
4DC0..4DFF; Yijing Hexagram Symbols
4E00..9FFF; CJK Unified Ideographs
A000..A48F; Yi Syllables
A490..A4CF; Yi Radicals
A4D0..A4FF; Lisu
A500..A63F; Vai
A640..A69F; Cyrillic Extended-B
A6A0..A6FF; Bamum
A700..A71F; Modifier Tone Letters
A720..A7FF; Latin Extended-D
A800..A82F; Syloti Nagri
A830..A83F; Common Indic Number Forms
A840..A87F; Phags-pa
A880..A8DF; Saurashtra
A8E0..A8FF; Devanagari Extended
A900..A92F; Kayah Li
A930..A95F; Rejang
A960..A97F; Hangul Jamo Extended-A
A980..A9DF; Javanese
A9E0..A9FF; Myanmar Extended-B
AA00..AA5F; Cham
AA60..AA7F; Myanmar Extended-A
AA80..AADF; Tai Viet
AAE0..AAFF; Meetei Mayek Extensions
AB00..AB2F; Ethiopic Extended-A
AB30..AB6F; Latin Extended-E
AB70..ABBF; Cherokee Supplement
ABC0..ABFF; Meetei Mayek
AC00..D7AF; Hangul Syllables
D7B0..D7FF; Hangul Jamo Extended-B
D800..DB7F; High Surrogates
DB80..DBFF; High Private Use Surrogates
DC00..DFFF; Low Surrogates
E000..F8FF; Private Use Area
F900..FAFF; CJK Compatibility Ideographs
FB00..FB4F; Alphabetic Presentation Forms
FB50..FDFF; Arabic Presentation Forms-A
FE00..FE0F; Variation Selectors
FE10..FE1F; Vertical Forms
FE20..FE2F; Combining Half Marks
FE30..FE4F; CJK Compatibility Forms
FE50..FE6F; Small Form Variants
FE70..FEFF; Arabic Presentation Forms-B
FF00..FFEF; Halfwidth and Fullwidth Forms
FFF0..FFFF; Specials
10000..1007F; Linear B Syllabary
10080..100FF; Linear B Ideograms
10100..1013F; Aegean Numbers
10140..1018F; Ancient Greek Numbers
10190..101CF; Ancient Symbols
101D0..101FF; Phaistos Disc
10280..1029F; Lycian
102A0..102DF; Carian
102E0..102FF; Coptic Epact Numbers
10300..1032F; Old Italic
10330..1034F; Gothic
10350..1037F; Old Permic
10380..1039F; Ugaritic
103A0..103DF; Old Persian
10400..1044F; Deseret
10450..1047F; Shavian
10480..104AF; Osmanya
104B0..104FF; Osage
10500..1052F; Elbasan
10530..1056F; Caucasian Albanian
10570..105BF; Vithkuqi
10600..1077F; Linear A
10780..107BF; Latin Extended-F
10800..1083F; Cypriot Syllabary
10840..1085F; Imperial Aramaic
10860..1087F; Palmyrene
10880..108AF; Nabataean
108E0..108FF; Hatran
10900..1091F; Phoenician
10920..1093F; Lydian
10980..1099F; Meroitic Hieroglyphs
109A0..109FF; Meroitic Cursive
10A00..10A5F; Kharoshthi
10A60..10A7F; Old South Arabian
10A80..10A9F; Old North Arabian
10AC0..10AFF; Manichaean
10B00..10B3F; Avestan
10B40..10B5F; Inscriptional Parthian
10B60..10B7F; Inscriptional Pahlavi
10B80..10BAF; Psalter Pahlavi
10C00..10C4F; Old Turkic
10C80..10CFF; Old Hungarian
10D00..10D3F; Hanifi Rohingya
10E60..10E7F; Rumi Numeral Symbols
10E80..10EBF; Yezidi
10F00..10F2F; Old Sogdian
10F30..10F6F; Sogdian
10F70..10FAF; Old Uyghur
10FB0..10FDF; Chorasmian
10FE0..10FFF; Elymaic
11000..1107F; Brahmi
11080..110CF; Kaithi
110D0..110FF; Sora Sompeng
11100..1114F; Chakma
11150..1117F; Mahajani
11180..111DF; Sharada
111E0..111FF; Sinhala Archaic Numbers
11200..1124F; Khojki
11280..112AF; Multani
112B0..112FF; Khudawadi
11300..1137F; Grantha
11400..1147F; Newa
11480..114DF; Tirhuta
11580..115FF; Siddham
11600..1165F; Modi
11660..1167F; Mongolian Supplement
11680..116CF; Takri
11700..1174F; Ahom
11800..1184F; Dogra
118A0..118FF; Warang Citi
11900..1195F; Dives Akuru
119A0..119FF; Nandinagari
11A00..11A4F; Zanabazar Square
11A50..11AAF; Soyombo
11AB0..11ABF; Unified Canadian Aboriginal Syllabics Extended-A
11AC0..11AFF; Pau Cin Hau
11C00..11C6F; Bhaiksuki
11C70..11CBF; Marchen
11D00..11D5F; Masaram Gondi
11D60..11DAF; Gunjala Gondi
11EE0..11EFF; Makasar
11FB0..11FBF; Lisu Supplement
11FC0..11FFF; Tamil Supplement
12000..123FF; Cuneiform
12400..1247F; Cuneiform Numbers and Punctuation
12480..1254F; Early Dynastic Cuneiform
12F90..12FFF; Cypro-Minoan
13000..1342F; Egyptian Hieroglyphs
13430..1343F; Egyptian Hieroglyph Format Controls
14400..1467F; Anatolian Hieroglyphs
16800..16A3F; Bamum Supplement
16A40..16A6F; Mro
16A70..16ACF; Tangsa
16AD0..16AFF; Bassa Vah
16B00..16B8F; Pahawh Hmong
16E40..16E9F; Medefaidrin
16F00..16F9F; Miao
16FE0..16FFF; Ideographic Symbols and Punctuation
17000..187FF; Tangut
18800..18AFF; Tangut Components
18B00..18CFF; Khitan Small Script
18D00..18D7F; Tangut Supplement
1AFF0..1AFFF; Kana Extended-B
1B000..1B0FF; Kana Supplement
1B100..1B12F; Kana Extended-A
1B130..1B16F; Small Kana Extension
1B170..1B2FF; Nushu
1BC00..1BC9F; Duployan
1BCA0..1BCAF; Shorthand Format Controls
1CF00..1CFCF; Znamenny Musical Notation
1D000..1D0FF; Byzantine Musical Symbols
1D100..1D1FF; Musical Symbols
1D200..1D24F; Ancient Greek Musical Notation
1D2E0..1D2FF; Mayan Numerals
1D300..1D35F; Tai Xuan Jing Symbols
1D360..1D37F; Counting Rod Numerals
1D400..1D7FF; Mathematical Alphanumeric Symbols
1D800..1DAAF; Sutton SignWriting
1DF00..1DFFF; Latin Extended-G
1E000..1E02F; Glagolitic Supplement
1E100..1E14F; Nyiakeng Puachue Hmong
1E290..1E2BF; Toto
1E2C0..1E2FF; Wancho
1E7E0..1E7FF; Ethiopic Extended-B
1E800..1E8DF; Mende Kikakui
1E900..1E95F; Adlam
1EC70..1ECBF; Indic Siyaq Numbers
1ED00..1ED4F; Ottoman Siyaq Numbers
1EE00..1EEFF; Arabic Mathematical Alphabetic Symbols
1F000..1F02F; Mahjong Tiles
1F030..1F09F; Domino Tiles
1F0A0..1F0FF; Playing Cards
1F100..1F1FF; Enclosed Alphanumeric Supplement
1F200..1F2FF; Enclosed Ideographic Supplement
1F300..1F5FF; Miscellaneous Symbols and Pictographs
1F600..1F64F; Emoticons
1F650..1F67F; Ornamental Dingbats
1F680..1F6FF; Transport and Map Symbols
1F700..1F77F; Alchemical Symbols
1F780..1F7FF; Geometric Shapes Extended
1F800..1F8FF; Supplemental Arrows-C
1F900..1F9FF; Supplemental Symbols and Pictographs
1FA00..1FA6F; Chess Symbols
1FA70..1FAFF; Symbols and Pictographs Extended-A
1FB00..1FBFF; Symbols for Legacy Computing
20000..2A6DF; CJK Unified Ideographs Extension B
2A700..2B73F; CJK Unified Ideographs Extension C
2B740..2B81F; CJK Unified Ideographs Extension D
2B820..2CEAF; CJK Unified Ideographs Extension E
2CEB0..2EBEF; CJK Unified Ideographs Extension F
2F800..2FA1F; CJK Compatibility Ideographs Supplement
30000..3134F; CJK Unified Ideographs Extension G
E0000..E007F; Tags
E0100..E01EF; Variation Selectors Supplement
F0000..FFFFF; Supplementary Private Use Area-A
100000..10FFFF; Supplementary Private Use Area-B
# EOF
| 10,720 | 357 | jart/cosmopolitan | false |
cosmopolitan/libc/str/langinfo.h | #ifndef COSMOPOLITAN_LIBC_STR_LANGINFO_H_
#define COSMOPOLITAN_LIBC_STR_LANGINFO_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define ABDAY_1 0x20000
#define ABDAY_2 0x20001
#define ABDAY_3 0x20002
#define ABDAY_4 0x20003
#define ABDAY_5 0x20004
#define ABDAY_6 0x20005
#define ABDAY_7 0x20006
#define DAY_1 0x20007
#define DAY_2 0x20008
#define DAY_3 0x20009
#define DAY_4 0x2000A
#define DAY_5 0x2000B
#define DAY_6 0x2000C
#define DAY_7 0x2000D
#define ABMON_1 0x2000E
#define ABMON_2 0x2000F
#define ABMON_3 0x20010
#define ABMON_4 0x20011
#define ABMON_5 0x20012
#define ABMON_6 0x20013
#define ABMON_7 0x20014
#define ABMON_8 0x20015
#define ABMON_9 0x20016
#define ABMON_10 0x20017
#define ABMON_11 0x20018
#define ABMON_12 0x20019
#define MON_1 0x2001A
#define MON_2 0x2001B
#define MON_3 0x2001C
#define MON_4 0x2001D
#define MON_5 0x2001E
#define MON_6 0x2001F
#define MON_7 0x20020
#define MON_8 0x20021
#define MON_9 0x20022
#define MON_10 0x20023
#define MON_11 0x20024
#define MON_12 0x20025
#define AM_STR 0x20026
#define PM_STR 0x20027
#define D_T_FMT 0x20028
#define D_FMT 0x20029
#define T_FMT 0x2002A
#define T_FMT_AMPM 0x2002B
#define ERA 0x2002C
#define ERA_D_FMT 0x2002E
#define ALT_DIGITS 0x2002F
#define ERA_D_T_FMT 0x20030
#define ERA_T_FMT 0x20031
#define CODESET 14
#define CRNCYSTR 0x4000F
#define RADIXCHAR 0x10000
#define THOUSEP 0x10001
#define YESEXPR 0x50000
#define NOEXPR 0x50001
#define _NL_LOCALE_NAME(cat) (((cat) << 16) | 0xffff)
#if defined(_GNU_SOURCE)
#define NL_LOCALE_NAME(cat) _NL_LOCALE_NAME(cat)
#endif
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#define YESSTR 0x50002
#define NOSTR 0x50003
#endif
char *nl_langinfo(int);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_STR_LANGINFO_H_ */
| 1,874 | 87 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strncasecmp.c | /*-*- 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/str/str.h"
#include "libc/str/tab.internal.h"
/**
* Compares NUL-terminated strings case-insensitively w/ limit.
*
* @param a is first non-null NUL-terminated string pointer
* @param b is second non-null NUL-terminated string pointer
* @return is <0, 0, or >0 based on uint8_t comparison
* @asyncsignalsafe
*/
int strncasecmp(const char *a, const char *b, size_t n) {
int x, y;
size_t i = 0;
if (!n-- || a == b) return 0;
while ((x = kToLower[a[i] & 0xff]) == (y = kToLower[b[i] & 0xff]) && b[i] &&
i < n) {
++i;
}
return x - y;
}
| 2,415 | 40 | jart/cosmopolitan | false |
cosmopolitan/libc/str/kmonthyearday.c | /*-*- 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/time/time.h"
_Hide const unsigned short kMonthYearDay[2][12] = {
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335},
};
| 2,042 | 25 | jart/cosmopolitan | false |
cosmopolitan/libc/str/tolower.c | /*-*- 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/str/str.h"
/**
* Converts character to ascii lower case.
*/
int tolower(int c) {
return 'A' <= c && c <= 'Z' ? c + ('a' - 'A') : c;
}
| 1,990 | 27 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strchr16.c | /*-*- 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 pointer to first instance of character.
*/
char16_t *strchr16(const char16_t *s, int c) {
for (;; ++s) {
if ((*s & 65535) == (c & 65535)) return (char16_t *)s;
if (!*s) return (char16_t *)0;
}
}
| 2,086 | 30 | jart/cosmopolitan | false |
cosmopolitan/libc/str/towupper_l.c | /*-*- 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. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/locale.h"
#include "libc/str/str.h"
wint_t towupper_l(wint_t c, locale_t l) {
return towupper(c);
}
| 1,958 | 25 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strrchr16.c | /*-*- 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/str/str.h"
/**
* Searches for last instance of char16_t in string.
*
* @param s is NUL-terminated char16_t string to search
* @param c is treated as char16_t
* @return address of last c in s, or NULL if not found
* @asyncsignalsafe
*/
char16_t *strrchr16(const char16_t *s, int c) {
return memrchr16(s, c, strlen16(s));
}
| 2,183 | 32 | jart/cosmopolitan | false |
cosmopolitan/libc/str/hexpcpy.c | /*-*- 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. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/str.h"
/**
* Turns data into lowercase hex.
*
* This routine always writes a nul terminator, even if `n` is zero.
* There's no failure condition for this function.
*
* @param s must have `n*2+1` bytes
* @param p must have `n` bytes
* @param n is byte length of p
* @return pointer to nul byte in `s`
*/
char *hexpcpy(char *restrict s, const void *restrict p, size_t n) {
const char *d, *e;
for (d = p, e = d + n; d < e; ++d) {
*s++ = "0123456789abcdef"[(*d >> 4) & 15];
*s++ = "0123456789abcdef"[(*d >> 0) & 15];
}
*s = 0;
return s;
}
| 2,419 | 41 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strcasestr.c | /*-*- 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/str/str.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/str/tab.internal.h"
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
/**
* Searches for substring case-insensitively.
*
* @param haystack is the search area, as a NUL-terminated string
* @param needle is the desired substring, also NUL-terminated
* @return pointer to first substring within haystack, or NULL
* @note this implementation goes fast in practice but isn't hardened
* against pathological cases, and therefore shouldn't be used on
* untrustworthy data
* @asyncsignalsafe
* @see strstr()
*/
noasan char *strcasestr(const char *haystack, const char *needle) {
#ifdef __x86_64__
char c;
xmm_t *p;
size_t i;
unsigned k, m;
xmm_t v, n1, n2, z = {0};
if (IsAsan()) __asan_verify(needle, 1);
if (IsAsan()) __asan_verify(haystack, 1);
if (haystack == needle || !*needle) return haystack;
c = *needle;
n1 = (xmm_t){c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
c = kToLower[c & 255];
n2 = (xmm_t){c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
for (;;) {
k = (uintptr_t)haystack & 15;
p = (const xmm_t *)((uintptr_t)haystack & -16);
v = *p;
m = __builtin_ia32_pmovmskb128((v == z) | (v == n1) | (v == n2));
m >>= k;
m <<= k;
while (!m) {
v = *++p;
m = __builtin_ia32_pmovmskb128((v == z) | (v == n1) | (v == n2));
}
haystack = (const char *)p + __builtin_ctzl(m);
for (i = 0;; ++i) {
if (!needle[i]) return (/*unconst*/ char *)haystack;
if (!haystack[i]) break;
if (kToLower[needle[i] & 255] != kToLower[haystack[i] & 255]) break;
}
if (!*haystack++) break;
}
return 0;
#else
size_t i;
unsigned k, m;
if (haystack == needle || !*needle) return haystack;
for (;;) {
for (i = 0;; ++i) {
if (!needle[i]) return (/*unconst*/ char *)haystack;
if (!haystack[i]) break;
if (kToLower[needle[i] & 255] != kToLower[haystack[i] & 255]) break;
}
if (!*haystack++) break;
}
return 0;
#endif
}
| 3,922 | 87 | jart/cosmopolitan | false |
cosmopolitan/libc/str/wcsncasecmp.c | /*-*- 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/str/str.h"
/**
* Compares NUL-terminated wide strings case-insensitively w/ limit.
*
* @param a is first non-null NUL-terminated string pointer
* @param b is second non-null NUL-terminated string pointer
* @return is <0, 0, or >0 based on uint8_t comparison
* @asyncsignalsafe
*/
int wcsncasecmp(const wchar_t *a, const wchar_t *b, size_t n) {
size_t i = 0;
unsigned x, y;
if (!n-- || a == b) return 0;
while ((x = towlower(a[i])) == (y = towlower(b[i])) && b[i] && i < n) ++i;
return x - y;
}
| 2,363 | 36 | jart/cosmopolitan | false |
cosmopolitan/libc/str/wcwidth_osx.internal.h | #ifndef COSMOPOLITAN_LIBC_STR_WCWIDTH_OSX_H_
#define COSMOPOLITAN_LIBC_STR_WCWIDTH_OSX_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
extern const uint32_t kWcwidthOsx[591];
extern const uint8_t kWcwidthOsxIndex1[136];
extern const uint16_t kWcwidthOsxIndex2[228];
extern const uint32_t kWcwidthOsxIndex3[917];
static inline int _wcwidth_osx(uint32_t codePoint) {
uint32_t a, b, c, d;
a = kWcwidthOsxIndex1[codePoint >> 13];
b = kWcwidthOsxIndex2[a + ((codePoint >> 9) & 0xf)];
c = kWcwidthOsxIndex3[b + ((codePoint >> 5) & 0xf)];
d = c + (codePoint & 0x1f);
return (kWcwidthOsx[d >> 4] >> ((d & 0xf) << 1)) & 3;
}
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_STR_WCWIDTH_OSX_H_ */
| 763 | 23 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strntoupper.c | /*-*- 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/str/str.h"
/**
* Mutates string to ASCII uppercase w/ limit.
*
* @praam s is string
* @praam n is max bytes to consider
* @return string
*/
char *strntoupper(char *s, size_t n) {
size_t i;
for (i = 0; s[i] && i < n; ++i) {
if ('a' <= s[i] && s[i] <= 'z') {
s[i] -= 'a' - 'A';
}
}
return s;
}
| 2,172 | 37 | jart/cosmopolitan | false |
cosmopolitan/libc/str/uselocale.c | /*-*- 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. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/locale.h"
#include "libc/sysv/errfuns.h"
locale_t uselocale(locale_t l) {
// TODO: implement me!
return 0;
}
| 1,969 | 26 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strnlen_s.c | /*-*- 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. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/assert.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/str/str.h"
static noasan size_t strnlen_s_x64(const char *s, size_t n, size_t i) {
uint64_t w;
for (; i + 8 < n; i += 8) {
w = *(uint64_t *)(s + i);
if ((w = ~w & (w - 0x0101010101010101) & 0x8080808080808080)) {
i += (unsigned)__builtin_ctzll(w) >> 3;
break;
}
}
return i;
}
/**
* Returns length of NUL-terminated string... securely.
*
* This is like strnlen() except it'll return 0 if `s` is null. We also
* make the assumption for the purposes of ASAN that `n` is the size of
* the buffer if `s` is non-null.
*
* @param s is string
* @param n is max length
* @return byte length
* @asyncsignalsafe
*/
noasan size_t strnlen_s(const char *s, size_t n) {
size_t i;
if (!s) return 0;
if (IsAsan()) __asan_verify(s, n);
for (i = 0; (uintptr_t)(s + i) & 7; ++i) {
if (i == n || !s[i]) return i;
}
i = strnlen_s_x64(s, n, i);
for (;; ++i) {
if (i == n || !s[i]) break;
}
_unassert(i == n || (i < n && !s[i]));
return i;
}
| 2,928 | 62 | jart/cosmopolitan | false |
cosmopolitan/libc/str/memcasecmp.c | /*-*- 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/intrin/bits.h"
#include "libc/str/str.h"
#include "libc/str/tab.internal.h"
/**
* Compares memory case-insensitively.
*
* memcasecmp n=0 992 picoseconds
* memcasecmp n=1 1 ns/byte 590 mb/s
* memcasecmp n=2 1 ns/byte 843 mb/s
* memcasecmp n=3 1 ns/byte 885 mb/s
* memcasecmp n=4 1 ns/byte 843 mb/s
* memcasecmp n=5 1 ns/byte 820 mb/s
* memcasecmp n=6 1 ns/byte 770 mb/s
* memcasecmp n=7 1 ns/byte 765 mb/s
* memcasecmp n=8 206 ps/byte 4,724 mb/s
* memcasecmp n=9 220 ps/byte 4,428 mb/s
* memcasecmp n=15 617 ps/byte 1,581 mb/s
* memcasecmp n=16 124 ps/byte 7,873 mb/s
* memcasecmp n=17 155 ps/byte 6,274 mb/s
* memcasecmp n=31 341 ps/byte 2,860 mb/s
* memcasecmp n=32 82 ps/byte 11,810 mb/s
* memcasecmp n=33 100 ps/byte 9,743 mb/s
* memcasecmp n=80 53 ps/byte 18,169 mb/s
* memcasecmp n=128 49 ps/byte 19,890 mb/s
* memcasecmp n=256 45 ps/byte 21,595 mb/s
* memcasecmp n=16384 42 ps/byte 22,721 mb/s
* memcasecmp n=32768 40 ps/byte 24,266 mb/s
* memcasecmp n=131072 40 ps/byte 24,337 mb/s
*
* @return is <0, 0, or >0 based on uint8_t comparison
*/
int memcasecmp(const void *p, const void *q, size_t n) {
int c;
size_t i;
unsigned u;
uint64_t w;
const unsigned char *a, *b;
if ((a = p) != (b = q)) {
for (i = 0; i < n; ++i) {
while (i + 8 <= n) {
if ((w = (((uint64_t)a[0] << 000 | (uint64_t)a[1] << 010 |
(uint64_t)a[2] << 020 | (uint64_t)a[3] << 030 |
(uint64_t)a[4] << 040 | (uint64_t)a[5] << 050 |
(uint64_t)a[6] << 060 | (uint64_t)a[7] << 070) ^
((uint64_t)b[0] << 000 | (uint64_t)b[1] << 010 |
(uint64_t)b[2] << 020 | (uint64_t)b[3] << 030 |
(uint64_t)b[4] << 040 | (uint64_t)b[5] << 050 |
(uint64_t)b[6] << 060 | (uint64_t)b[7] << 070)))) {
u = __builtin_ctzll(w);
i += u >> 3;
break;
} else {
i += 8;
}
}
if (i == n) {
break;
} else if ((c = kToLower[a[i]] - kToLower[b[i]])) {
return c;
}
}
}
return 0;
}
| 4,680 | 84 | jart/cosmopolitan | false |
cosmopolitan/libc/str/wcscspn.c | /*-*- 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/nexgen32e/hascharacter.internal.h"
#include "libc/str/str.h"
/**
* 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;
}
| 2,315 | 39 | jart/cosmopolitan | false |
cosmopolitan/libc/str/isdirsep.c | /*-*- 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. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/dce.h"
#include "libc/str/str.h"
/**
* Returns true if character is directory separator slash.
*/
bool _isdirsep(int c) {
return c == '/' || c == '\\';
}
| 2,010 | 28 | jart/cosmopolitan | false |
cosmopolitan/libc/str/getzipcdir.c | /*-*- 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 â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/intrin/bits.h"
#include "libc/zip.h"
typedef char v16qi __attribute__((__vector_size__(16)));
typedef short v8hi __attribute__((__vector_size__(16)));
typedef long long v2di __attribute__((__vector_size__(16), __aligned__(1)));
/**
* Locates End Of Central Directory record in ZIP file.
*
* The ZIP spec says this header can be anywhere in the last 64kb. We
* search it backwards for the ZIP-64 "PKâ â¢" magic number. If that's not
* found, then we search again for the original "PKâ£â " magnum. The
* caller needs to check the first four bytes of the returned value to
* determine whether to use ZIP_CDIR_xxx() or ZIP_CDIR64_xxx() macros.
*
* @param p points to file memory
* @param n is byte size of file
* @return pointer to EOCD64 or EOCD, or NULL if not found
*/
void *GetZipCdir(const uint8_t *p, size_t n) {
v2di x;
size_t i, j;
uint32_t magic;
i = n - 4;
do {
#ifdef __x86_64__
v8hi pk = {READ16LE("PK"), READ16LE("PK"), READ16LE("PK"), READ16LE("PK"),
READ16LE("PK"), READ16LE("PK"), READ16LE("PK"), READ16LE("PK")};
asm("" : "+x"(pk));
if (i >= 14) {
x = *(const v2di *)(p + i - 14);
if (!(__builtin_ia32_pmovmskb128(
(v16qi)__builtin_ia32_pcmpeqw128((v8hi)x, pk)) |
__builtin_ia32_pmovmskb128((v16qi)__builtin_ia32_pcmpeqw128(
(v8hi)__builtin_ia32_psrldqi128(x, 8), pk)))) {
i -= 13;
continue;
}
}
#endif
while (magic = READ32LE(p + i), magic != kZipCdir64LocatorMagic &&
magic != kZipCdirHdrMagic &&
i + 0x10000 + 0x1000 >= n && i > 0) {
--i;
}
if (magic == kZipCdir64LocatorMagic && i + kZipCdir64LocatorSize <= n &&
IsZipCdir64(p, n, ZIP_LOCATE64_OFFSET(p + i))) {
return p + ZIP_LOCATE64_OFFSET(p + i);
} else if (magic == kZipCdirHdrMagic && IsZipCdir32(p, n, i)) {
j = i;
do {
if (READ32LE(p + j) == kZipCdir64LocatorMagic &&
j + kZipCdir64LocatorSize <= n &&
IsZipCdir64(p, n, ZIP_LOCATE64_OFFSET(p + j))) {
return p + ZIP_LOCATE64_OFFSET(p + j);
}
} while (j-- && i - j < 128);
return p + i;
}
} while (i > 0 && i-- + 0x10000 + 0x1000 >= n);
return 0;
}
| 4,159 | 82 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strncpy.c | /*-*- 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/str/str.h"
/**
* Prepares static search buffer.
*
* 1. If SRC is too long, it's truncated and *not* NUL-terminated.
* 2. If SRC is too short, the remainder is zero-filled.
*
* Please note this function isn't designed to prevent untrustworthy
* data from modifying memory without authorization; the memccpy()
* function can be used for that purpose.
*
* Here's an example of the only use case we know of for strncpy:
*
* static const struct People {
* char name[8];
* int age;
* } kPeople[] = {
* {"alice", 29}, //
* {"bob", 42}, //
* };
*
* int GetAge(const char *name) {
* char k[8];
* int m, l, r;
* l = 0;
* r = ARRAYLEN(kPeople) - 1;
* strncpy(k, name, 8);
* while (l <= r) {
* m = (l + r) >> 1;
* if (READ64BE(kPeople[m].name) < READ64BE(k)) {
* l = m + 1;
* } else if (READ64BE(kPeople[m].name) > READ64BE(k)) {
* r = m - 1;
* } else {
* return kPeople[m].age;
* }
* }
* return -1;
* }
*
* @return dest
* @see stpncpy(), memccpy()
* @asyncsignalsafe
* @vforksafe
*/
char *strncpy(char *dest, const char *src, size_t stride) {
size_t i;
for (i = 0; i < stride; ++i) {
if (!(dest[i] = src[i])) break;
}
bzero(dest + i, stride - i);
return dest;
}
| 3,230 | 73 | jart/cosmopolitan | false |
cosmopolitan/libc/str/mbsrtowcs.c | /*-*- 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â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â â
â Musl Libc â
â Copyright © 2005-2014 Rich Felker, et al. â
â â
â Permission is hereby granted, free of charge, to any person obtaining â
â a copy of this software and associated documentation files (the â
â "Software"), to deal in the Software without restriction, including â
â without limitation the rights to use, copy, modify, merge, publish, â
â distribute, sublicense, and/or sell copies of the Software, and to â
â permit persons to whom the Software is furnished to do so, subject to â
â the following conditions: â
â â
â The above copyright notice and this permission notice shall be â
â included in all copies or substantial portions of the Software. â
â â
â THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, â
â EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF â
â MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. â
â IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY â
â CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, â
â TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE â
â SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. â
â â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/errno.h"
#include "libc/limits.h"
#include "libc/macros.internal.h"
#include "libc/str/mb.internal.h"
#include "libc/str/str.h"
asm(".ident\t\"\\n\\n\
Musl libc (MIT License)\\n\
Copyright 2005-2014 Rich Felker, et. al.\"");
asm(".include \"libc/disclaimer.inc\"");
size_t mbsrtowcs(wchar_t *ws, const char **src, size_t wn, mbstate_t *st) {
const unsigned char *s = (const void *)*src;
size_t wn0 = wn;
unsigned c = 0;
if (st && (c = *(unsigned *)st)) {
if (ws) {
*(unsigned *)st = 0;
goto resume;
} else {
goto resume0;
}
}
if (MB_CUR_MAX == 1) {
if (!ws) return strlen((const char *)s);
for (;;) {
if (!wn) {
*src = (const void *)s;
return wn0;
}
if (!*s) break;
c = *s++;
*ws++ = CODEUNIT(c);
wn--;
}
*ws = 0;
*src = 0;
return wn0 - wn;
}
if (!ws)
for (;;) {
if (*s - 1u < 0x7f) {
s++;
wn--;
continue;
}
if (*s - SA > SB - SA) break;
c = kMbBittab[*s++ - SA];
resume0:
if (OOB(c, *s)) {
s--;
break;
}
s++;
if (c & (1U << 25)) {
if (*s - 0x80u >= 0x40) {
s -= 2;
break;
}
s++;
if (c & (1U << 19)) {
if (*s - 0x80u >= 0x40) {
s -= 3;
break;
}
s++;
}
}
wn--;
c = 0;
}
else
for (;;) {
if (!wn) {
*src = (const void *)s;
return wn0;
}
if (*s - 1u < 0x7f) {
*ws++ = *s++;
wn--;
continue;
}
if (*s - SA > SB - SA) break;
c = kMbBittab[*s++ - SA];
resume:
if (OOB(c, *s)) {
s--;
break;
}
c = (c << 6) | *s++ - 0x80;
if (c & (1U << 31)) {
if (*s - 0x80u >= 0x40) {
s -= 2;
break;
}
c = (c << 6) | *s++ - 0x80;
if (c & (1U << 31)) {
if (*s - 0x80u >= 0x40) {
s -= 3;
break;
}
c = (c << 6) | *s++ - 0x80;
}
}
*ws++ = c;
wn--;
c = 0;
}
if (!c && !*s) {
if (ws) {
*ws = 0;
*src = 0;
}
return wn0 - wn;
}
errno = EILSEQ;
if (ws) *src = (const void *)s;
return -1;
}
| 4,931 | 147 | jart/cosmopolitan | false |
cosmopolitan/libc/str/iswxdigit.c | /*-*- 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/str/str.h"
/**
* Returns nonzero if c is ascii hex digit.
*/
int iswxdigit(wint_t c) {
return ('0' <= c && c <= '9') || ('A' <= c && c <= 'F') ||
('a' <= c && c <= 'f');
}
| 2,037 | 28 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strstr16.c | /*-*- 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/str/str.h"
/**
* Searches for substring.
*
* @param haystack is the search area, as a NUL-terminated string
* @param needle is the desired substring, also NUL-terminated
* @return pointer to first substring within haystack, or NULL
* @asyncsignalsafe
* @see memmem()
*/
char16_t *strstr16(const char16_t *haystack, const char16_t *needle) {
size_t i;
for (;;) {
for (i = 0;;) {
if (!needle[i]) return (/*unconst*/ char16_t *)haystack;
if (!haystack[i]) break;
if (needle[i] != haystack[i]) break;
++i;
}
if (!*haystack++) break;
}
return NULL;
}
| 2,450 | 43 | jart/cosmopolitan | false |
cosmopolitan/libc/str/wcsncpy.c | /*-*- 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/str/str.h"
wchar_t *wcsncpy(wchar_t *d, const wchar_t *s, size_t n) {
wchar_t *a;
for (a = d; n && *s; --n) {
*d++ = *s++;
}
wmemset(d, 0, n);
return a;
}
| 2,021 | 29 | jart/cosmopolitan | false |
cosmopolitan/libc/str/intsort.c | /*-*- 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 â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/intrin/strace.internal.h"
#include "libc/runtime/runtime.h"
static inline void InsertionSort(int *A, long n) {
long i, j, t;
for (i = 1; i < n; i++) {
t = A[i];
j = i - 1;
while (j >= 0 && A[j] > t) {
A[j + 1] = A[j];
j = j - 1;
}
A[j + 1] = t;
}
}
static void IntSort(int *A, long n) {
int t, p;
long i, j;
if (n <= 32) {
InsertionSort(A, n);
} else {
for (p = A[n >> 1], i = 0, j = n - 1;; i++, j--) {
while (A[i] < p) i++;
while (A[j] > p) j--;
if (i >= j) break;
t = A[i];
A[i] = A[j];
A[j] = t;
}
IntSort(A, i);
IntSort(A + i, n - i);
}
}
/**
* Tiny and reasonably fast sorting for ints.
* @see djbsort
*/
void _intsort(int *A, size_t n) {
IntSort(A, n);
if (n > 1000) {
STRACE("_intsort(%p, %'zu)", A, n);
}
}
| 2,687 | 64 | jart/cosmopolitan | false |
cosmopolitan/libc/str/isabspath.c | /*-*- 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/str/path.h"
#include "libc/str/str.h"
/**
* Returns true if pathname is considered absolute.
*
* - `/home/jart/foo.txt` is absolute
* - `C:/Users/jart/foo.txt` is absolute on Windows
* - `C:\Users\jart\foo.txt` is absolute on Windows
* - `\??\C:\Users\jart\foo.txt` is absolute on Windows
* - `\\.\C:\Users\jart\foo.txt` is absolute on Windows
* - `/Users/jart/foo.txt` is effectively absolute on Windows
* - `\Users\jart\foo.txt` is effectively absolute on Windows
*
*/
bool _isabspath(const char *path) {
return _classifypath(path) & _kPathAbs;
}
| 2,414 | 37 | jart/cosmopolitan | false |
cosmopolitan/libc/str/wcsstr.c | /*-*- 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/str/str.h"
/**
* Searches for substring.
*
* @param haystack is the search area, as a NUL-terminated string
* @param needle is the desired substring, also NUL-terminated
* @return pointer to first substring within haystack, or NULL
* @asyncsignalsafe
* @see memmem()
*/
wchar_t *wcsstr(const wchar_t *haystack, const wchar_t *needle) {
size_t i;
for (;;) {
for (i = 0;;) {
if (!needle[i]) return (/*unconst*/ wchar_t *)haystack;
if (!haystack[i]) break;
if (needle[i] != haystack[i]) break;
++i;
}
if (!*haystack++) break;
}
return NULL;
}
| 2,444 | 43 | jart/cosmopolitan | false |
cosmopolitan/libc/str/iswctype.c | /*-*- 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/macros.internal.h"
#include "libc/str/str.h"
typedef int (*isw_f)(wint_t);
static const isw_f kWcTypeFuncs[] = {
iswalnum, //
iswalpha, //
iswblank, //
iswcntrl, //
iswdigit, //
iswgraph, //
iswlower, //
iswprint, //
iswpunct, //
iswspace, //
iswupper, //
iswxdigit, //
};
/**
* Returns nonzero if c has property.
*
* @param t is number returned by wctype
*/
int iswctype(wint_t c, wctype_t t) {
if (1 <= t && t <= ARRAYLEN(kWcTypeFuncs)) {
return kWcTypeFuncs[t - 1](c);
} else {
return 0;
}
}
| 2,438 | 51 | jart/cosmopolitan | false |
cosmopolitan/libc/str/wcstombs.c | /*-*- 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 â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/str.h"
size_t wcstombs(char *s, const wchar_t *ws, size_t n) {
return wcsrtombs(s, &(const wchar_t *){ws}, n, 0);
}
| 1,974 | 24 | jart/cosmopolitan | false |
cosmopolitan/libc/str/c32rtomb.c | /*-*- 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 â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/str.h"
size_t c32rtomb(char *s, char32_t c, mbstate_t *t) {
return wcrtomb(s, c, t);
}
| 1,945 | 24 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strcasecmp16.c | /*-*- 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/str/str.h"
/**
* Compares NUL-terminated UCS-2 strings case-insensitively.
*
* @param a is first non-null NUL-terminated char16 string pointer
* @param b is second non-null NUL-terminated char16 string pointer
* @return is <0, 0, or >0 based on uint16_t comparison
* @asyncsignalsafe
*/
int strcasecmp16(const char16_t *l, const char16_t *r) {
int x, y;
size_t i = 0;
while ((x = towlower(l[i])) == (y = towlower(r[i])) && r[i]) ++i;
return x - y;
}
| 2,317 | 35 | jart/cosmopolitan | false |
cosmopolitan/libc/str/mbtowc.c | /*-*- 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â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â â
â Musl Libc â
â Copyright © 2005-2014 Rich Felker, et al. â
â â
â Permission is hereby granted, free of charge, to any person obtaining â
â a copy of this software and associated documentation files (the â
â "Software"), to deal in the Software without restriction, including â
â without limitation the rights to use, copy, modify, merge, publish, â
â distribute, sublicense, and/or sell copies of the Software, and to â
â permit persons to whom the Software is furnished to do so, subject to â
â the following conditions: â
â â
â The above copyright notice and this permission notice shall be â
â included in all copies or substantial portions of the Software. â
â â
â THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, â
â EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF â
â MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. â
â IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY â
â CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, â
â TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE â
â SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. â
â â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/errno.h"
#include "libc/limits.h"
#include "libc/str/mb.internal.h"
#include "libc/str/str.h"
asm(".ident\t\"\\n\\n\
Musl libc (MIT License)\\n\
Copyright 2005-2014 Rich Felker, et. al.\"");
asm(".include \"libc/disclaimer.inc\"");
int mbtowc(wchar_t *restrict wc, const char *restrict src, size_t n) {
unsigned c;
const unsigned char *s = (const void *)src;
wchar_t dummy;
if (!s) return 0;
if (!n) goto ilseq;
if (!wc) wc = &dummy;
if (*s < 0x80) return !!(*wc = *s);
if (MB_CUR_MAX == 1) return (*wc = CODEUNIT(*s)), 1;
if (*s - SA > SB - SA) goto ilseq;
c = kMbBittab[*s++ - SA];
/* Avoid excessive checks against n: If shifting the state n-1
* times does not clear the high bit, then the value of n is
* insufficient to read a character */
if (n < 4 && ((c << (6 * n - 6)) & (1U << 31))) goto ilseq;
if (OOB(c, *s)) goto ilseq;
c = c << 6 | *s++ - 0x80;
if (!(c & (1U << 31))) {
*wc = c;
return 2;
}
if (*s - 0x80u >= 0x40) goto ilseq;
c = c << 6 | *s++ - 0x80;
if (!(c & (1U << 31))) {
*wc = c;
return 3;
}
if (*s - 0x80u >= 0x40) goto ilseq;
*wc = c << 6 | *s++ - 0x80;
return 4;
ilseq:
errno = EILSEQ;
return -1;
}
| 3,814 | 72 | jart/cosmopolitan | false |
cosmopolitan/libc/str/mbrtoc32.c | /*-*- 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â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â â
â Musl Libc â
â Copyright © 2005-2014 Rich Felker, et al. â
â â
â Permission is hereby granted, free of charge, to any person obtaining â
â a copy of this software and associated documentation files (the â
â "Software"), to deal in the Software without restriction, including â
â without limitation the rights to use, copy, modify, merge, publish, â
â distribute, sublicense, and/or sell copies of the Software, and to â
â permit persons to whom the Software is furnished to do so, subject to â
â the following conditions: â
â â
â The above copyright notice and this permission notice shall be â
â included in all copies or substantial portions of the Software. â
â â
â THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, â
â EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF â
â MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. â
â IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY â
â CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, â
â TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE â
â SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. â
â â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/errno.h"
#include "libc/limits.h"
#include "libc/macros.internal.h"
#include "libc/str/str.h"
asm(".ident\t\"\\n\\n\
Musl libc (MIT License)\\n\
Copyright 2005-2014 Rich Felker, et. al.\"");
asm(".include \"libc/disclaimer.inc\"");
size_t mbrtoc32(char32_t *pc32, const char *s, size_t n, mbstate_t *ps) {
static unsigned internal_state;
if (!ps) ps = (void *)&internal_state;
if (!s) return mbrtoc32(0, "", 1, ps);
wchar_t wc;
size_t ret = mbrtowc(&wc, s, n, ps);
if (ret <= 4 && pc32) *pc32 = wc;
return ret;
}
| 3,146 | 47 | jart/cosmopolitan | false |
cosmopolitan/libc/str/timingsafe_bcmp.c | /*-*- 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 â
â â
â 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/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/likely.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/str/str.h"
typedef uint64_t xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
noasan static unsigned timingsafe_bcmp_sse(const char *p, const char *q,
size_t n) {
uint64_t w;
xmm_t a = {0};
while (n > 16 + 16) {
a |= *(const xmm_t *)p ^ *(const xmm_t *)q;
p += 16;
q += 16;
n -= 16;
}
a |= *(const xmm_t *)p ^ *(const xmm_t *)q;
a |= *(const xmm_t *)(p + n - 16) ^ *(const xmm_t *)(q + n - 16);
w = a[0] | a[1];
return w | w >> 32;
}
#ifdef __x86_64__
noasan static microarchitecture("avx") int timingsafe_bcmp_avx(const char *p,
const char *q,
size_t n) {
uint64_t w;
xmm_t a = {0};
if (n > 32) {
if (n >= 16 + 64) {
xmm_t b = {0};
xmm_t c = {0};
xmm_t d = {0};
do {
a |= ((const xmm_t *)p)[0] ^ ((const xmm_t *)q)[0];
b |= ((const xmm_t *)p)[1] ^ ((const xmm_t *)q)[1];
c |= ((const xmm_t *)p)[2] ^ ((const xmm_t *)q)[2];
d |= ((const xmm_t *)p)[3] ^ ((const xmm_t *)q)[3];
p += 64;
q += 64;
n -= 64;
} while (n >= 16 + 64);
a = a | b | c | d;
}
while (n > 32) {
a |= *(const xmm_t *)p ^ *(const xmm_t *)q;
p += 16;
q += 16;
n -= 16;
}
}
a |= *(const xmm_t *)p ^ *(const xmm_t *)q;
a |= *(const xmm_t *)(p + n - 16) ^ *(const xmm_t *)(q + n - 16);
w = a[0] | a[1];
return w | w >> 32;
}
#endif
/**
* Tests inequality of first ð bytes of ð and ð.
*
* The following expression:
*
* !!timingsafe_bcmp(p, q, n)
*
* Is functionally equivalent to:
*
* !!memcmp(p, q, n)
*
* This function is faster than memcmp() and bcmp() when byte sequences
* are assumed to always be the same; that makes it best for assertions
* or hash table lookups, assuming ð is variable (since no gcc builtin)
*
* timingsafe_bcmp n=0 992 picoseconds
* timingsafe_bcmp n=1 1 ns/byte 738 mb/s
* timingsafe_bcmp n=2 826 ps/byte 1,181 mb/s
* timingsafe_bcmp n=3 661 ps/byte 1,476 mb/s
* timingsafe_bcmp n=4 330 ps/byte 2,952 mb/s
* timingsafe_bcmp n=5 264 ps/byte 3,690 mb/s
* timingsafe_bcmp n=6 220 ps/byte 4,428 mb/s
* timingsafe_bcmp n=7 189 ps/byte 5,166 mb/s
* timingsafe_bcmp n=8 124 ps/byte 7,873 mb/s
* timingsafe_bcmp n=9 147 ps/byte 6,643 mb/s
* timingsafe_bcmp n=15 88 ps/byte 11,072 mb/s
* timingsafe_bcmp n=16 62 ps/byte 15,746 mb/s
* timingsafe_bcmp n=17 136 ps/byte 7,170 mb/s
* timingsafe_bcmp n=31 74 ps/byte 13,075 mb/s
* timingsafe_bcmp n=32 72 ps/byte 13,497 mb/s
* timingsafe_bcmp n=33 80 ps/byte 12,179 mb/s
* timingsafe_bcmp n=80 57 ps/byte 16,871 mb/s
* timingsafe_bcmp n=128 49 ps/byte 19,890 mb/s
* timingsafe_bcmp n=256 31 ps/byte 31,493 mb/s
* timingsafe_bcmp n=16384 14 ps/byte 67,941 mb/s
* timingsafe_bcmp n=32768 29 ps/byte 33,121 mb/s
* timingsafe_bcmp n=131072 29 ps/byte 32,949 mb/s
*
* Running time is independent of the byte sequences compared, making
* this safe to use for comparing secret values such as cryptographic
* MACs. In contrast, memcmp() may short-circuit after finding the first
* differing byte.
*
* @return nonzero if unequal, otherwise zero
* @see timingsafe_memcmp()
* @asyncsignalsafe
*/
int timingsafe_bcmp(const void *a, const void *b, size_t n) {
const char *p = a, *q = b;
uint32_t u, u0, u1, u2, u3;
uint64_t w, w0, w1, w2, w3;
if (!IsTiny()) {
if (n >= 8) {
if (n <= 16) {
__builtin_memcpy(&w0, p, 8);
__builtin_memcpy(&w1, q, 8);
__builtin_memcpy(&w2, p + n - 8, 8);
__builtin_memcpy(&w3, q + n - 8, 8);
w = (w0 ^ w1) | (w2 ^ w3);
return w | w >> 32;
} else {
if (IsAsan()) {
__asan_verify(a, n);
__asan_verify(b, n);
}
#ifdef __x86_64__
if (X86_HAVE(AVX)) {
return timingsafe_bcmp_avx(p, q, n);
}
#endif
return timingsafe_bcmp_sse(p, q, n);
}
} else if (n >= 4) {
__builtin_memcpy(&u0, p, 4);
__builtin_memcpy(&u1, q, 4);
__builtin_memcpy(&u2, p + n - 4, 4);
__builtin_memcpy(&u3, q + n - 4, 4);
return (u0 ^ u1) | (u2 ^ u3);
}
}
for (u = 0; n--;) {
u |= p[n] ^ q[n];
}
return u;
}
| 6,911 | 164 | jart/cosmopolitan | false |
cosmopolitan/libc/str/djbsort.c | /*-*- 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/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/runtime.h"
void djbsort_avx2(int32_t *, long);
/**
* D.J. Bernstein's outrageously fast integer sorting algorithm.
*/
void djbsort(int32_t *a, size_t n) {
size_t m;
if (IsAsan()) {
if (__builtin_mul_overflow(n, 4, &m)) m = -1;
__asan_verify(a, m);
}
if (n > 1) {
#ifdef __x86_64__
if (X86_HAVE(AVX2)) {
djbsort_avx2(a, n);
} else {
_intsort(a, n);
}
#else
_intsort(a, n);
#endif /* __x86_64__ */
}
}
| 2,409 | 47 | jart/cosmopolitan | false |
cosmopolitan/libc/str/wcwidth.c | /*-*- 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/intrin/likely.h"
#include "libc/str/str.h"
#include "libc/str/unicode.h"
#include "libc/str/wcwidth_osx.internal.h"
extern const uint8_t kEastAsianWidth[];
extern const uint32_t kEastAsianWidthBits;
extern const uint8_t kCombiningChars[];
extern const uint32_t kCombiningCharsBits;
/**
* Returns cell width of monospace character.
*/
int wcwidth(wchar_t c) {
#ifdef __x86_64__
if (LIKELY(32 <= c && c < 127)) {
return 1;
} else if (!c) {
return 0;
} else if ((uint32_t)c > 0x10FFFD || //
(0 < c && c < 32) || //
(0x7f <= c && c < 0xA0)) {
return -1;
} else if ((0 <= c && c < kCombiningCharsBits) &&
!!(kCombiningChars[c >> 3] & (1 << (c & 7)))) {
return 0;
} else if (0 <= c && c < kEastAsianWidthBits) {
return 1 + !!(kEastAsianWidth[c >> 3] & (1 << (c & 7)));
} else {
return 1;
}
#else
int res;
if (LIKELY(32 <= c && c < 127)) return 1;
if (VERY_UNLIKELY((uint32_t)c >= 0x100000)) {
if ((uint32_t)c <= 0x10FFFD) return 1;
return -1;
}
res = _wcwidth_osx(c);
if (VERY_UNLIKELY(!res)) {
if (!c) return 0;
if (iswcntrl(c)) return -1;
}
return res;
#endif
}
| 3,029 | 65 | jart/cosmopolitan | false |
cosmopolitan/libc/str/getzipcdircomment.c | /*-*- 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 â
â â
â 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/zip.h"
/**
* Returns comment of zip central directory.
*/
void *GetZipCdirComment(const uint8_t *eocd) {
if (READ32LE(eocd) == kZipCdir64HdrMagic && ZIP_CDIR64_COMMENTSIZE(eocd)) {
return ZIP_CDIR64_COMMENT(eocd);
} else {
return ZIP_CDIR_COMMENT(eocd);
}
}
| 2,126 | 31 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strwidth.c | /*-*- 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/str/strwidth.h"
/**
* Returns monospace display width of UTF-8 string.
*
* - Control codes are discounted
* - ANSI escape sequences are discounted
* - East asian glyphs, emoji, etc. count as two
*
* @param s is NUL-terminated string
* @param o is string offset for computing tab widths
* @return monospace display width
*/
int strwidth(const char *s, size_t o) {
return strnwidth(s, -1, 0);
}
| 2,257 | 35 | jart/cosmopolitan | false |
cosmopolitan/libc/str/unicode.h | #ifndef COSMOPOLITAN_LIBC_STR_UNICODE_H_
#define COSMOPOLITAN_LIBC_STR_UNICODE_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct lconv {
char *decimal_point;
char *thousands_sep;
char *grouping;
char *int_curr_symbol;
char *currency_symbol;
char *mon_decimal_point;
char *mon_thousands_sep;
char *mon_grouping;
char *positive_sign;
char *negative_sign;
char int_frac_digits;
char frac_digits;
char p_cs_precedes;
char p_sep_by_space;
char n_cs_precedes;
char n_sep_by_space;
char p_sign_posn;
char n_sign_posn;
char int_p_cs_precedes;
char int_n_cs_precedes;
char int_p_sep_by_space;
char int_n_sep_by_space;
char int_p_sign_posn;
char int_n_sign_posn;
};
int wcwidth(wchar_t) pureconst;
int wcswidth(const wchar_t *, size_t) strlenesque;
int wcsnwidth(const wchar_t *, size_t, int) strlenesque;
struct lconv *localeconv(void);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_STR_UNICODE_H_ */
| 1,012 | 41 | jart/cosmopolitan | false |
cosmopolitan/libc/str/wcsnlen.c | /*-*- 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.
*
* @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;
}
}
| 2,217 | 37 | jart/cosmopolitan | false |
cosmopolitan/libc/str/iswxdigit_l.c | /*-*- 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. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/locale.h"
#include "libc/str/str.h"
int iswxdigit_l(wint_t c, locale_t l) {
return iswxdigit(c);
}
| 1,957 | 25 | jart/cosmopolitan | false |
cosmopolitan/libc/str/iswprint.c | /*-*- 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/str/str.h"
/**
* Returns nonzero if c is printable.
*/
int iswprint(wint_t c) {
return !((0x00 <= c && c <= 0x1F) || (0x7F <= c && c <= 0x9F) ||
(0xFFF9 <= c && c <= 0xFFFB) || c == 0x2028 || c == 0x2029);
}
| 2,075 | 28 | jart/cosmopolitan | false |
cosmopolitan/libc/str/path.h | #ifndef COSMOPOLITAN_LIBC_STR_PATH_H_
#define COSMOPOLITAN_LIBC_STR_PATH_H_
#define _kPathAbs 1
#define _kPathDev 2
#define _kPathRoot 4
#define _kPathDos 8
#define _kPathWin 16
#define _kPathNt 32
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int _classifypath(const char *) libcesque nosideeffect;
bool _isabspath(const char *) libcesque strlenesque;
bool _isdirsep(int) libcesque pureconst;
char *_joinpaths(char *, size_t, const char *, const char *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_STR_PATH_H_ */
| 590 | 22 | jart/cosmopolitan | false |
cosmopolitan/libc/str/memchr16.c | /*-*- 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 pointer to first instance of character in range.
*/
void *memchr16(const void *s, int c, size_t n) {
size_t i;
const char *p = (const char *)s;
for (i = 0; i < n; ++i) {
if ((p[i] & 65535) == (c & 65535)) {
return (void *)(p + i);
}
}
return 0;
}
| 2,150 | 34 | jart/cosmopolitan | false |
cosmopolitan/libc/str/kcombiningchars.S | /*-*- 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 "libc/dce.h"
#include "libc/macros.internal.h"
#include "libc/sysv/consts/nr.h"
#include "libc/sysv/consts/madv.h"
.rodata.cst4
kCombiningCharsBits:
.long 114752 * 8
.endobj kCombiningCharsBits,globl,hidden
.previous
.initbss 400,_init_kCombiningChars
kCombiningChars:
.zero 114752
.endobj kCombiningChars,globl,hidden
.previous
.init.start 400,_init_kCombiningChars
push %rsi
mov $1203,%edx
call lz4cpy
mov %rax,%rdi
pop %rsi
add $1208,%rsi
.init.end 400,_init_kCombiningChars
// o/tool/build/lz4toasm.com
// -o o/libc/str/CombiningChars.s
// -s kCombiningChars
// o/libc/str/CombiningChars.bin.lz4
.initro 400,_init_kCombiningChars
kCombiningCharsLz4:
.byte 0x1f,0x00,0x01,0x00,0x4c,0x19,0xff,0x01 #â¼Â âºÂ Lâλâº
.byte 0x00,0x0f,0x30,0x00,0x0f,0x2f,0xf8,0x03 # â¼0 â¼/°â¥
.byte 0x22,0x00,0x0d,0x10,0xfe,0x49,0x00,0x23 #. âªâºâ I .
.byte 0xbf,0xb6,0x0e,0x00,0x42,0x3f,0x00,0xff #ââ¢â«Â Bâ λ
.byte 0x17,0x39,0x00,0x00,0x5e,0x00,0x17,0x01 #â¨9  ^ â¨âº
.byte 0x28,0x00,0x92,0xc0,0xbf,0x9f,0x3d,0x00 #( ÃââÆ=Â
.byte 0x00,0x00,0x80,0x02,0x86,0x00,0x17,0x07 #  Ãâ»Ã¥Â â¨â¢
.byte 0x1a,0x00,0x13,0xff,0x28,0x00,0x91,0xf8 #â â¼Î»( æ°
.byte 0x0f,0x20,0x00,0x00,0xc0,0xfb,0xef,0x3e #â¼ Â Â âââ©>
.byte 0x0e,0x00,0x1b,0x0e,0x8a,0x00,0x26,0xff #â«Â ââ«Ã¨Â &λ
.byte 0xff,0x37,0x00,0xa2,0x14,0xfe,0x21,0xfe #λ7 ó¶â !â
.byte 0x00,0x0c,0x00,0x00,0x00,0x02,0x10,0x00 # â   â»âºÂ
.byte 0x40,0x10,0x1e,0x20,0x00,0x10,0x00,0x23 #@âºâ²  âºÂ .
.byte 0x40,0x06,0x10,0x00,0x20,0x86,0x39,0x1a #@â âºÂ Ã¥9â
.byte 0x00,0x24,0x23,0x00,0x10,0x00,0x21,0xbe # $. âºÂ !â
.byte 0x21,0x20,0x00,0x13,0xfc,0x30,0x00,0x41 #!  â¼â¿0 A
.byte 0x90,0x1e,0x20,0x40,0x40,0x00,0x13,0x04 #Ãâ² @@ â¼â¦
.byte 0x5e,0x00,0x22,0x01,0x20,0x08,0x00,0x13 #^ .⺠â â¼
.byte 0x11,0x93,0x00,0x38,0xc1,0x3d,0x60,0x60 #âô 8â´=``
.byte 0x00,0x31,0x90,0x40,0x30,0x40,0x00,0x13 #Â 1Ã@0@Â â¼
.byte 0x00,0x0f,0x01,0x13,0x18,0x70,0x00,0x06 # â¼âºâ¼âp â
.byte 0x9f,0x00,0x27,0x04,0x5c,0x0d,0x00,0x48 #ÆÂ ââ¦\âªÂ H
.byte 0xf2,0x07,0x80,0x7f,0x1d,0x00,0x45,0xf2 #â¥â¢Ãââ Eâ¥
.byte 0x1f,0x00,0x3f,0x0d,0x00,0x43,0x03,0x00 #â¼Â ââªÂ Câ¥Â
.byte 0x00,0xa0,0x57,0x00,0x50,0xfe,0x7f,0xdf # áW Pâ ââ
.byte 0xe0,0xff,0x41,0x01,0x28,0x1f,0x40,0x2f #αλAâº(â¼@/
.byte 0x00,0xff,0x00,0xe0,0xfd,0x66,0x00,0x00 # λ α²f Â
.byte 0x00,0xc3,0x01,0x00,0x1e,0x00,0x64,0x20 # ââºÂ â²Â d
.byte 0x00,0x20,0xcc,0x01,0x0b,0x0f,0xd2,0x01 # â âºââ¼â¥âº
.byte 0x1d,0x06,0x66,0x00,0x1f,0x00,0x01,0x00 #ââ f â¼Â âºÂ
.byte 0x62,0x13,0x1c,0x04,0x00,0x26,0x0c,0x00 #bâ¼ââ¦Â &âÂ
.byte 0x42,0x01,0x52,0xb0,0x3f,0x40,0xfe,0x0f #BâºRââ@â â¼
.byte 0xe8,0x00,0x1a,0x78,0x2e,0x00,0x26,0x60 #Φ âx. &`
.byte 0x00,0x85,0x01,0x04,0x14,0x00,0x4f,0x87 # à âºâ¦Â¶Â Oç
.byte 0x01,0x04,0x0e,0x60,0x00,0x07,0x22,0x80 #âºâ¦â«` â¢.Ã
.byte 0x09,0x08,0x00,0x63,0x40,0x7f,0xe5,0x1f #ââ c@âÏâ¼
.byte 0xf8,0x9f,0x2a,0x01,0x05,0x8e,0x01,0x11 #°Æ*âºâ£Ãâºâ
.byte 0x0f,0x06,0x00,0x32,0xd0,0x17,0x04,0x70 #â¼â  2â¨â¨â¦p
.byte 0x02,0x01,0xd0,0x01,0x23,0x3c,0x3b,0x32 #â»âºâ¨âº.<;2
.byte 0x00,0x13,0xa3,0xde,0x01,0x2f,0xf0,0xcf # â¼Ãºââº/â¡â§
.byte 0x58,0x00,0x00,0x6f,0xf7,0xff,0xfd,0x21 #X  oâλ²!
.byte 0x10,0x03,0x8c,0x01,0x0c,0x1f,0xfb,0x1f #âºâ¥Ã®âºââ¼ââ¼
.byte 0x01,0x2e,0x52,0xf8,0x00,0x00,0x00,0x7c #âº.R°   |
.byte 0x0b,0x00,0x2c,0xdf,0xff,0x62,0x00,0x2f #â ,âλb /
.byte 0x01,0x00,0x01,0x00,0xff,0x6b,0x1d,0x80 #âºÂ âºÂ λkâÃ
.byte 0xff,0x01,0x1c,0x80,0xa2,0x01,0x0f,0x68 #λâºâÃóâºâ¼h
.byte 0x00,0x32,0x19,0x3c,0x0e,0x00,0x2f,0x06 # 2â<â«Â /â
.byte 0x00,0x01,0x00,0xff,0xff,0xff,0xff,0xff # âºÂ λλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xb3,0x20,0x80,0xf7,0xf6,0x12,0x28 #λâ Ãâ÷â(
.byte 0xc0,0x00,0xfb,0x12,0x0f,0x33,0x00,0x0c #â âââ¼3 â
.byte 0x23,0x44,0x08,0xf4,0x11,0x0b,0x18,0x00 #.Dââ âââÂ
.byte 0x11,0x30,0x60,0x0f,0x11,0x03,0x70,0x0f #â0`â¼ââ¥pâ¼
.byte 0x62,0xc0,0x3f,0x00,0x00,0x80,0xff,0x4c #bââ  ÃλL
.byte 0x00,0x02,0x10,0x14,0x20,0xc8,0x33,0x06 # â»âºÂ¶ â3â
.byte 0x00,0x05,0x29,0x13,0x52,0x7e,0x66,0x00 # â£)â¼R~fÂ
.byte 0x08,0x10,0xf8,0x13,0x02,0x11,0x00,0x21 #ââºÂ°â¼â»â !
.byte 0x9d,0xc1,0x43,0x12,0x2f,0x30,0x40,0x7c #Â¥â´Câ/0@|
.byte 0x00,0x0a,0x2f,0x20,0x21,0x96,0x0a,0xff # â/ !ûâλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xdb,0x1f,0x40,0x60,0x1f,0x4b,0x2f,0x00 #ââ¼@`â¼K/Â
.byte 0x00,0x06,0x1a,0x08,0x1f,0x80,0x3f,0x00 # â âââ¼ÃâÂ
.byte 0x0c,0x1f,0x0e,0x7f,0x00,0x2c,0x1f,0x20 #ââ¼â«â ,â¼
.byte 0x1d,0x00,0x09,0x0e,0x3e,0x1c,0x2f,0xc0 #â ââ«>â/â
.byte 0x07,0xdd,0x01,0xbd,0x22,0x6e,0xf0,0x23 #â¢ââºâ.nâ¡.
.byte 0x1e,0x0f,0x1c,0x00,0x01,0x1f,0x60,0x64 #â²â¼â âºâ¼`d
.byte 0x00,0x34,0x1f,0xf0,0x44,0x00,0x30,0x05 # 4â¼â¡D 0â£
.byte 0xf4,0x20,0x0b,0x18,0x00,0x1a,0x02,0xb1 #â ââ ââ»â
.byte 0x1e,0x03,0x72,0x1c,0x24,0x78,0x26,0xda #â²â¥râ$x&â
.byte 0x01,0x00,0xf0,0x0c,0x33,0x80,0xef,0x1f #âºÂ â¡â3Ãâ©â¼
.byte 0x2e,0x00,0x13,0x08,0x52,0x0d,0x48,0xc0 #. â¼âRâªHâ
.byte 0x7f,0x00,0x1e,0x66,0x02,0x1f,0xd3,0xe4 #â â²fâ»â¼âΣ
.byte 0x02,0x01,0x36,0x80,0xf8,0x07,0xc0,0x20 #â»âº6ðâ¢â
.byte 0x00,0x7e,0x00,0x3f,0xc0,0x1f,0x1f,0xc7 # ~ âââ¼â¼â
.byte 0x02,0x06,0x19,0x5c,0x28,0x03,0x3f,0xf8 #â»â â\(â¥â°
.byte 0x85,0x0d,0xb1,0x1c,0x0b,0x22,0xb0,0x01 #à âªâââ.ââº
.byte 0xa3,0x0d,0x04,0x30,0x00,0x19,0xa7,0xde #úâªâ¦0 âºâ
.byte 0x00,0x29,0x28,0xbf,0x78,0x20,0x2f,0xbc #Â )(âx /â
.byte 0x0f,0x38,0x0e,0x0d,0x1f,0xff,0xf4,0x1c #â¼8â«âªâ¼Î»â â
.byte 0x20,0x20,0xf0,0x0c,0x74,0x00,0x11,0xfe # â¡ât ââ
.byte 0xd2,0x02,0x52,0xf8,0x79,0x80,0x00,0x7e #â¥â»R°yà~
.byte 0x4c,0x03,0x3f,0xfc,0x7f,0x03,0x4c,0x00 #Lâ¥ââ¿ââ¥LÂ
.byte 0x1f,0x17,0x7f,0xb1,0x00,0x5b,0xfc,0xff #â¼â¨ââ [â¿Î»
.byte 0xff,0xfc,0x6d,0x20,0x00,0x26,0x7e,0xb4 #λâ¿m  &~â¤
.byte 0x21,0x00,0x1f,0xa3,0x58,0x00,0x18,0x1f #! â¼ÃºX ââ¼
.byte 0x18,0x23,0x07,0xff,0xff,0x96,0x2f,0xff #â.â¢Î»Î»Ã»/λ
.byte 0x01,0xfb,0x0d,0xff,0xff,0xff,0xff,0xff #âºââªÎ»Î»Î»Î»Î»
.byte 0xff,0xc9,0x04,0xf0,0x0a,0x1f,0x7f,0x1c #λââ¦â¡ââ¼ââ
.byte 0x19,0x70,0x04,0x08,0x00,0x1f,0x07,0x30 #âpâ¦â â¼â¢0
.byte 0x18,0xff,0xff,0xff,0xff,0xff,0xff,0xff #âλλλλλλλ
.byte 0xff,0xff,0x96,0x2f,0x60,0x0f,0x5f,0x25 #λλû/`â¼_%
.byte 0xff,0xff,0x87,0x5d,0x03,0xf8,0xff,0xe7 #λλç]â¥Â°Î»Ï
.byte 0x0f,0x30,0x34,0x05,0x66,0x37,0x0f,0xba #â¼04â£f7â¼â
.byte 0x14,0xe2,0x01,0x01,0x00,0x12,0x7f,0x2d #¶ÎâºâºÂ ââ-
.byte 0x3a,0x20,0x1f,0x20,0x01,0x26,0x3f,0xf8 #: â¼ âº&â°
.byte 0xfe,0xff,0xc0,0x00,0x97,0x5f,0x7f,0xff #â λâ ù_âλ
.byte 0xff,0xf9,0xdb,0x13,0x0e,0x0e,0x1f,0x7f #λâââ¼â«â«â¼â
.byte 0xb9,0x1a,0x24,0x0f,0xda,0x01,0xa9,0x0a #â£â$â¼ââºââ
.byte 0xf4,0x00,0x3f,0xf0,0x07,0x00,0x01,0x00 #â  ââ¡â¢Â âºÂ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0x46,0x57,0x02,0x00 #λλλλFWâ»Â
.byte 0x00,0x00,0xff,0x01,0x00,0x0c,0x20,0x00 #  λâºÂ â Â
.byte 0x1f,0xff,0x01,0x00,0x07,0x50,0xff,0xff #â¼Î»âºÂ â¢Pλλ
.byte 0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00
.endobj kCombiningCharsLz4,globl,hidden
.previous
| 12,525 | 204 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strncat16.c | /*-*- 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 â
â â
â 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"
/**
* Appends at most ð shorts from ð to ð.
*
* @param ð is both a NUL-terminated string and a buffer, needing
* an ARRAYLEN() of at least strlen16(ð)+strnlen16(ð ,ð)+1
* @param ð is character array which needn't be NUL-terminated
* @param ð is maximum number of characters from s to copy
* @return ð
* @note ð and ð can't overlap
* @asyncsignaslenafe
*/
char16_t *strncat16(char16_t *d, const char16_t *s, size_t n) {
size_t i;
char16_t *r = d;
d += strlen16(d);
for (i = 0; i < n && s[i]; ++i) d[i] = s[i];
d[i] = 0;
return r;
}
| 2,455 | 40 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strncasecmp_l.c | /*-*- 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. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/locale.h"
#include "libc/str/str.h"
int strncasecmp_l(const char *a, const char *b, size_t n, locale_t l) {
return strncasecmp(a, b, n);
}
| 1,997 | 25 | jart/cosmopolitan | false |
cosmopolitan/libc/str/isupper_l.c | /*-*- 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. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/locale.h"
#include "libc/str/str.h"
int isupper_l(int c, locale_t l) {
return isupper(c);
}
| 1,950 | 25 | jart/cosmopolitan | false |
cosmopolitan/libc/str/thompike.h | #ifndef COSMOPOLITAN_LIBC_STR_THOMPIKE_H_
#define COSMOPOLITAN_LIBC_STR_THOMPIKE_H_
#include "libc/intrin/bsr.h"
#define ThomPikeCont(x) (0200 == (0300 & (x)))
#define ThomPikeByte(x) ((x) & (((1 << ThomPikeMsb(x)) - 1) | 3))
#define ThomPikeLen(x) (7 - ThomPikeMsb(x))
#define ThomPikeMsb(x) ((255 & (x)) < 252 ? _bsr(255 & ~(x)) : 1)
#define ThomPikeMerge(x, y) ((x) << 6 | 077 & (y))
#endif /* COSMOPOLITAN_LIBC_STR_THOMPIKE_H_ */
| 454 | 12 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strncmp16.c | /*-*- 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/str/str.h"
/**
* Compares NUL-terminated UCS-2 strings w/ limit.
*
* @param a is first non-null NUL-terminated char16 string pointer
* @param b is second non-null NUL-terminated char16 string pointer
* @return is <0, 0, or >0 based on uint8_t comparison
* @asyncsignalsafe
*/
int strncmp16(const char16_t *a, const char16_t *b, size_t n) {
size_t i = 0;
if (!n-- || a == b) return 0;
while (i < n && a[i] == b[i] && b[i]) ++i;
return a[i] - b[i];
}
| 2,316 | 35 | jart/cosmopolitan | false |
cosmopolitan/libc/str/rawmemchr16.c | /*-*- 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 pointer to first instance of character in range.
*/
void *rawmemchr16(const void *s, int c) {
const char *p = (const char *)s;
for (;; ++p) {
if ((*p & 65535) == (c & 65535)) {
return (void *)p;
}
}
}
| 2,100 | 32 | jart/cosmopolitan | false |
cosmopolitan/libc/str/strcasecmp_l.c | /*-*- 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. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/locale.h"
#include "libc/str/str.h"
int strcasecmp_l(const char *a, const char *b, locale_t l) {
return strcasecmp(a, b);
}
| 1,982 | 25 | jart/cosmopolitan | false |
cosmopolitan/libc/str/mb.c | /*-*- 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â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â â
â Musl Libc â
â Copyright © 2005-2014 Rich Felker, et al. â
â â
â Permission is hereby granted, free of charge, to any person obtaining â
â a copy of this software and associated documentation files (the â
â "Software"), to deal in the Software without restriction, including â
â without limitation the rights to use, copy, modify, merge, publish, â
â distribute, sublicense, and/or sell copies of the Software, and to â
â permit persons to whom the Software is furnished to do so, subject to â
â the following conditions: â
â â
â The above copyright notice and this permission notice shall be â
â included in all copies or substantial portions of the Software. â
â â
â THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, â
â EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF â
â MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. â
â IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY â
â CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, â
â TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE â
â SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. â
â â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/str/mb.internal.h"
asm(".ident\t\"\\n\\n\
Musl libc (MIT License)\\n\
Copyright 2005-2014 Rich Felker, et. al.\"");
asm(".include \"libc/disclaimer.inc\"");
#define C(x) (x < 2 ? -1 : (R(0x80, 0xc0) | x))
#define D(x) C((x + 16))
#define E(x) \
((x == 0 ? R(0xa0, 0xc0) \
: x == 0xd ? R(0x80, 0xa0) \
: R(0x80, 0xc0)) | \
(R(0x80, 0xc0) >> 6) | x)
#define F(x) \
((x >= 5 ? 0 \
: x == 0 ? R(0x90, 0xc0) \
: x == 4 ? R(0x80, 0x90) \
: R(0x80, 0xc0)) | \
(R(0x80, 0xc0) >> 6) | (R(0x80, 0xc0) >> 12) | x)
const uint32_t kMbBittab[51 /* ?! */] = {
C(0x2), C(0x3), C(0x4), C(0x5), C(0x6), C(0x7), C(0x8), C(0x9), C(0xa),
C(0xb), C(0xc), C(0xd), C(0xe), C(0xf), D(0x0), D(0x1), D(0x2), D(0x3),
D(0x4), D(0x5), D(0x6), D(0x7), D(0x8), D(0x9), D(0xa), D(0xb), D(0xc),
D(0xd), D(0xe), D(0xf), E(0x0), E(0x1), E(0x2), E(0x3), E(0x4), E(0x5),
E(0x6), E(0x7), E(0x8), E(0x9), E(0xa), E(0xb), E(0xc), E(0xd), E(0xe),
E(0xf), F(0x0), F(0x1), F(0x2), F(0x3), F(0x4),
};
| 3,723 | 57 | jart/cosmopolitan | false |
cosmopolitan/libc/str/wctob.c | /*-*- 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â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â â
â Musl Libc â
â Copyright © 2005-2014 Rich Felker, et al. â
â â
â Permission is hereby granted, free of charge, to any person obtaining â
â a copy of this software and associated documentation files (the â
â "Software"), to deal in the Software without restriction, including â
â without limitation the rights to use, copy, modify, merge, publish, â
â distribute, sublicense, and/or sell copies of the Software, and to â
â permit persons to whom the Software is furnished to do so, subject to â
â the following conditions: â
â â
â The above copyright notice and this permission notice shall be â
â included in all copies or substantial portions of the Software. â
â â
â THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, â
â EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF â
â MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. â
â IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY â
â CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, â
â TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE â
â SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. â
â â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/calls/calls.h"
#include "libc/limits.h"
#include "libc/str/mb.internal.h"
#include "libc/str/str.h"
asm(".ident\t\"\\n\\n\
Musl libc (MIT License)\\n\
Copyright 2005-2014 Rich Felker, et. al.\"");
asm(".include \"libc/disclaimer.inc\"");
int wctob(wint_t c) {
if (c < 128U) return c;
if (MB_CUR_MAX == 1 && IS_CODEUNIT(c)) return (unsigned char)c;
return EOF;
}
| 2,987 | 43 | jart/cosmopolitan | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.