mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-07 03:38:31 +00:00
Add more missing C / C++ headers
This commit is contained in:
parent
b9dc74b672
commit
8dd4ec68d0
152 changed files with 30711 additions and 6267 deletions
|
@ -1,38 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/nexgen32e/nexgen32e.h"
|
||||
|
||||
/**
|
||||
* Sorts array of signed 32-bit integers.
|
||||
* @see djbsort()
|
||||
*/
|
||||
textreal void insertionsort(int32_t *a, size_t n) {
|
||||
int t;
|
||||
unsigned i, j;
|
||||
for (i = 1; i < n; ++i) {
|
||||
j = i;
|
||||
t = a[i];
|
||||
while (j > 0 && t < a[j - 1]) {
|
||||
a[j] = a[j - 1];
|
||||
--j;
|
||||
}
|
||||
a[j] = t;
|
||||
}
|
||||
}
|
|
@ -106,7 +106,7 @@ 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 *, int) strlenesque;
|
||||
void *wmemrchr(const void *, wchar_t, size_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;
|
||||
|
|
|
@ -49,6 +49,8 @@ o/$(MODE)/libc/str/memmem.o: private \
|
|||
OVERRIDE_CPPFLAGS += \
|
||||
-DSTACK_FRAME_UNLIMITED
|
||||
|
||||
o/$(MODE)/libc/str/wmemset.o \
|
||||
o/$(MODE)/libc/str/memset16.o \
|
||||
o/$(MODE)/libc/str/dosdatetimetounix.o: private \
|
||||
OVERRIDE_CFLAGS += \
|
||||
-O3
|
||||
|
|
|
@ -1,40 +1,38 @@
|
|||
/*-*- 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. │
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ 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.
|
||||
* Compares arrays of 32-bit signed integers.
|
||||
*
|
||||
* @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
|
||||
* @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) {
|
||||
return wcsncmp(a, b, n);
|
||||
size_t i;
|
||||
for (i = 0; i < n; ++i) {
|
||||
if (a[i] != b[i]) {
|
||||
return a[i] - b[i];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -19,5 +19,7 @@
|
|||
#include "libc/str/str.h"
|
||||
|
||||
wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t count) {
|
||||
return memcpy(dest, src, count * sizeof(wchar_t));
|
||||
size_t bytes;
|
||||
if (__builtin_mul_overflow(count, sizeof(wchar_t), &bytes)) bytes = -1;
|
||||
return memcpy(dest, src, bytes);
|
||||
}
|
||||
|
|
|
@ -19,5 +19,7 @@
|
|||
#include "libc/str/str.h"
|
||||
|
||||
wchar_t *wmemmove(wchar_t *dest, const wchar_t *src, size_t count) {
|
||||
return memmove(dest, src, count * sizeof(wchar_t));
|
||||
size_t bytes;
|
||||
if (__builtin_mul_overflow(count, sizeof(wchar_t), &bytes)) bytes = -1;
|
||||
return memmove(dest, src, bytes);
|
||||
}
|
||||
|
|
|
@ -19,5 +19,7 @@
|
|||
#include "libc/str/str.h"
|
||||
|
||||
wchar_t *wmempcpy(wchar_t *dest, const wchar_t *src, size_t count) {
|
||||
return mempcpy(dest, src, count * sizeof(wchar_t));
|
||||
size_t bytes;
|
||||
if (__builtin_mul_overflow(count, sizeof(wchar_t), &bytes)) bytes = -1;
|
||||
return mempcpy(dest, src, bytes);
|
||||
}
|
||||
|
|
|
@ -64,10 +64,14 @@ noasan static inline const wchar_t *wmemrchr_sse(const wchar_t *s, wchar_t c,
|
|||
* @return is pointer to first instance of c or NULL if not found
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
void *wmemrchr(const void *s, wchar_t c, size_t n) {
|
||||
void *wmemrchr(const wchar_t *s, wchar_t c, size_t n) {
|
||||
size_t bytes;
|
||||
const void *r;
|
||||
if (!IsTiny() && X86_HAVE(SSE)) {
|
||||
if (IsAsan()) __asan_verify(s, n * 4);
|
||||
if (IsAsan()) {
|
||||
if (__builtin_mul_overflow(n, sizeof(wchar_t), &bytes)) bytes = -1;
|
||||
__asan_verify(s, bytes);
|
||||
}
|
||||
r = wmemrchr_sse(s, c, n);
|
||||
} else {
|
||||
r = wmemrchr_pure(s, c, n);
|
||||
|
|
|
@ -23,15 +23,9 @@
|
|||
* @asyncsignalsafe
|
||||
*/
|
||||
wchar_t *wmemset(wchar_t *p, wchar_t c, size_t n) {
|
||||
size_t i = 0;
|
||||
if (n >= 4) {
|
||||
wchar_t v __attribute__((__vector_size__(16))) = {c, c, c, c};
|
||||
do {
|
||||
__builtin_memcpy(p + i, &v, 16);
|
||||
} while ((i += 4) + 4 <= n);
|
||||
}
|
||||
while (i < n) {
|
||||
p[i++] = c;
|
||||
size_t i;
|
||||
for (i = 0; i < n; ++i) {
|
||||
p[i] = c;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue