mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-10 05:02:06 +00:00
Improve cosmo's conformance to libc-test
This change addresses various open source compatibility issues, so that we pass 313/411 of the tests in https://github.com/jart/libc-test where earlier today we were passing about 30/411 of them, due to header toil. Please note that Glibc only passes 341/411 so 313 today is pretty good! - Make the conformance of libc/isystem/ headers nearly perfect - Import more of the remaining math library routines from Musl - Fix inconsistencies with type signatures of calls like umask - Write tests for getpriority/setpriority which work great now - conform to `struct sockaddr *` on remaining socket functions - Import a bunch of uninteresting stdlib functions e.g. rand48 - Introduce readdir_r, scandir, pthread_kill, sigsetjmp, etc.. Follow the instructions in our `tool/scripts/cosmocc` toolchain to run these tests yourself. You use `make CC=cosmocc` on the test repository
This commit is contained in:
parent
467a332e38
commit
e557058ac8
189 changed files with 5091 additions and 884 deletions
|
@ -76,6 +76,8 @@ 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);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -21,6 +21,7 @@ int isgraph(int);
|
|||
int tolower(int);
|
||||
int ispunct(int);
|
||||
int toupper(int);
|
||||
int toascii(int);
|
||||
int hextoint(int);
|
||||
int _cescapec(int);
|
||||
|
||||
|
|
24
libc/str/strcasecmp_l.c
Normal file
24
libc/str/strcasecmp_l.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*-*- 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,7 +1,7 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
/*-*- 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 2020 Justine Alexandra Roberts Tunney │
|
||||
│ Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org> │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
|
@ -16,25 +16,48 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
// clang-format off
|
||||
// $OpenBSD: strlcat.c,v 1.19 2019/01/25 00:19:25 millert Exp $
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
strlcat (ISC)\\n\
|
||||
Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
/**
|
||||
* Appends string SRC to DEST, the BSD way.
|
||||
*
|
||||
* @param dest is a buffer holding a NUL-terminated string
|
||||
* @param src is a NUL-terminated string
|
||||
* @param size is byte capacity of dest
|
||||
* @return strlen(dest) + strlen(src)
|
||||
* @note dest and src can't overlap
|
||||
* @see strncat()
|
||||
* Appends string, the BSD way.
|
||||
*
|
||||
* Appends `src` to string `dst` of size `dsize` (unlike strncat,
|
||||
* `dsize` is the full size of `dst`, not space left). At most `dsize-1`
|
||||
* characters will be copied. Always NUL terminates (unless `dsize <=
|
||||
* strlen(dst)`). Returns `strlen(src) + MIN(dsize, strlen(initial
|
||||
* dst))`. If `retval >= dsize`, truncation occurred.
|
||||
*/
|
||||
size_t strlcat(char *dest, const char *src, size_t size) {
|
||||
size_t destlen = strnlen(dest, size);
|
||||
size_t srclen = strlen(src);
|
||||
if (size) {
|
||||
memcpy(&dest[destlen], src, min(srclen, size - destlen));
|
||||
dest[min(destlen + srclen, size - 1)] = '\0';
|
||||
}
|
||||
return destlen + srclen;
|
||||
size_t
|
||||
strlcat(char *dst, const char *src, size_t dsize)
|
||||
{
|
||||
const char *odst = dst;
|
||||
const char *osrc = src;
|
||||
size_t n = dsize;
|
||||
size_t dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end. */
|
||||
while (n-- != 0 && *dst != '\0')
|
||||
dst++;
|
||||
dlen = dst - odst;
|
||||
n = dsize - dlen;
|
||||
|
||||
if (n-- == 0)
|
||||
return(dlen + strlen(src));
|
||||
while (*src != '\0') {
|
||||
if (n != 0) {
|
||||
*dst++ = *src;
|
||||
n--;
|
||||
}
|
||||
src++;
|
||||
}
|
||||
*dst = '\0';
|
||||
|
||||
return(dlen + (src - osrc)); /* count does not include NUL */
|
||||
}
|
||||
|
|
24
libc/str/strncasecmp_l.c
Normal file
24
libc/str/strncasecmp_l.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*-*- 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);
|
||||
}
|
23
libc/str/toascii.c
Normal file
23
libc/str/toascii.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*-*- 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"
|
||||
|
||||
int toascii(int c) {
|
||||
return c & 127;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue