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:
Justine Tunney 2022-10-10 17:52:41 -07:00
parent 467a332e38
commit e557058ac8
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
189 changed files with 5091 additions and 884 deletions

View file

@ -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 */
}