Make more compatibility improvements

This commit is contained in:
Justine Tunney 2022-09-06 11:22:08 -07:00
parent 11ec60d5fc
commit dbf12c30b0
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
32 changed files with 158 additions and 16 deletions

View file

@ -16,9 +16,10 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/safemacros.internal.h"
#include "libc/dce.h"
#include "libc/fmt/fmt.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
/**

View file

@ -18,7 +18,7 @@
*/
#include "libc/fmt/itoa.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/str/str.h"
#include "libc/str/errfun.h"
const char *(DescribeFutexResult)(char buf[12], int ax) {
const char *s;

View file

@ -3,7 +3,9 @@
#define PTHREAD_ONCE_INIT 0
#define PTHREAD_KEYS_MAX 64
#define PTHREAD_KEYS_MAX 64
#define PTHREAD_STACK_MIN 2048
#define PTHREAD_DESTRUCTOR_ITERATIONS 4
#define PTHREAD_BARRIER_SERIAL_THREAD 31337

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/magnumstrs.internal.h"
#include "libc/str/str.h"
#include "libc/str/errfun.h"
/**
* Converts errno value to symbolic name.

View file

@ -24,6 +24,7 @@
#include "libc/nt/enum/formatmessageflags.h"
#include "libc/nt/enum/lang.h"
#include "libc/nt/process.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
/**

View file

@ -1,5 +1,9 @@
#ifndef LIBC_ISYSTEM_LIMITS_H_
#define LIBC_ISYSTEM_LIMITS_H_
#include "libc/intrin/pthread.h"
#include "libc/limits.h"
#include "libc/sysv/consts/_posix.h"
#include "libc/sysv/consts/iov.h"
#include "libc/sysv/consts/limits.h"
#include "libc/sysv/consts/xopen.h"
#endif

View file

@ -2,6 +2,7 @@
#define LIBC_ISYSTEM_UNISTD_H_
#include "libc/calls/calls.h"
#include "libc/calls/weirdtypes.h"
#include "libc/runtime/pathconf.h"
#include "libc/runtime/sysconf.h"
#include "libc/sysv/consts/fileno.h"
#include "libc/sysv/consts/o.h"

View file

@ -36,6 +36,7 @@
#define INTMAX_MAX __INTMAX_MAX__
#define UINTMAX_MAX __UINTMAX_MAX__
extern int __got_long_min;
#define SCHAR_MIN (-SCHAR_MAX - 1)
#define SHRT_MIN (-SHRT_MAX - 1)
#define INT_MIN (-INT_MAX - 1)
@ -90,4 +91,21 @@
#define SIG_ATOMIC_MIN INT32_MIN
#define SIG_ATOMIC_MAX INT32_MAX
#define FILESIZEBITS 64
#define SYMLOOP_MAX 40
#define TTY_NAME_MAX 32
#define HOST_NAME_MAX 255
#define TZNAME_MAX 6
#define WORD_BIT 32
#define SEM_VALUE_MAX 0x7fffffff
#define SEM_NSEMS_MAX 256
#define DELAYTIMER_MAX 0x7fffffff
#define MQ_PRIO_MAX 32768
#define LOGIN_NAME_MAX 256
#define NL_ARGMAX 9
#define NL_MSGMAX 32767
#define NL_SETMAX 255
#define NL_TEXTMAX 2048
#endif /* COSMOPOLITAN_LIBC_LIMITS_H_ */

53
libc/runtime/fpathconf.c Normal file
View file

@ -0,0 +1,53 @@
/*-*- 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/errno.h"
#include "libc/limits.h"
#include "libc/runtime/pathconf.h"
#include "libc/sysv/consts/_posix.h"
#include "libc/sysv/consts/limits.h"
#include "libc/sysv/errfuns.h"
long fpathconf(int fd, int name) {
if (name == _PC_LINK_MAX) return _POSIX_LINK_MAX;
if (name == _PC_MAX_CANON) return _POSIX_MAX_CANON;
if (name == _PC_MAX_INPUT) return _POSIX_MAX_INPUT;
if (name == _PC_NAME_MAX) return NAME_MAX;
if (name == _PC_PATH_MAX) return PATH_MAX;
if (name == _PC_PIPE_BUF) return PIPE_BUF;
if (name == _PC_CHOWN_RESTRICTED) return 1;
if (name == _PC_NO_TRUNC) return 1;
if (name == _PC_VDISABLE) return 0;
if (name == _PC_SYNC_IO) return 1;
if (name == _PC_ASYNC_IO) return -1;
if (name == _PC_PRIO_IO) return -1;
if (name == _PC_SOCK_MAXBUF) return -1;
if (name == _PC_FILESIZEBITS) return FILESIZEBITS;
if (name == _PC_REC_INCR_XFER_SIZE) return 4096;
if (name == _PC_REC_MAX_XFER_SIZE) return 4096;
if (name == _PC_REC_MIN_XFER_SIZE) return 4096;
if (name == _PC_REC_XFER_ALIGN) return 4096;
if (name == _PC_ALLOC_SIZE_MIN) return 4096;
if (name == _PC_SYMLINK_MAX) return -1;
if (name == _PC_2_SYMLINKS) return 1;
return einval();
}
long pathconf(const char *path, int name) {
return fpathconf(-1, name);
}

34
libc/runtime/pathconf.h Normal file
View file

@ -0,0 +1,34 @@
#ifndef COSMOPOLITAN_LIBC_RUNTIME_PATHCONF_H_
#define COSMOPOLITAN_LIBC_RUNTIME_PATHCONF_H_
#define _PC_LINK_MAX 0
#define _PC_MAX_CANON 1
#define _PC_MAX_INPUT 2
#define _PC_NAME_MAX 3
#define _PC_PATH_MAX 4
#define _PC_PIPE_BUF 5
#define _PC_CHOWN_RESTRICTED 6
#define _PC_NO_TRUNC 7
#define _PC_VDISABLE 8
#define _PC_SYNC_IO 9
#define _PC_ASYNC_IO 10
#define _PC_PRIO_IO 11
#define _PC_SOCK_MAXBUF 12
#define _PC_FILESIZEBITS 13
#define _PC_REC_INCR_XFER_SIZE 14
#define _PC_REC_MAX_XFER_SIZE 15
#define _PC_REC_MIN_XFER_SIZE 16
#define _PC_REC_XFER_ALIGN 17
#define _PC_ALLOC_SIZE_MIN 18
#define _PC_SYMLINK_MAX 19
#define _PC_2_SYMLINKS 20
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
long fpathconf(int, int);
long pathconf(const char *, int);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_RUNTIME_PATHCONF_H_ */

View file

@ -82,8 +82,6 @@ int mprotect(void *, uint64_t, int) privileged;
int msync(void *, size_t, int);
void *sbrk(intptr_t);
int brk(void *);
long fpathconf(int, int);
long pathconf(const char *, int);
int getgroups(int, uint32_t[]);
long gethostid(void);
int sethostid(long);

11
libc/str/errfun.h Normal file
View file

@ -0,0 +1,11 @@
#ifndef COSMOPOLITAN_LIBC_STR_ERRFUN_H_
#define COSMOPOLITAN_LIBC_STR_ERRFUN_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
char *strerrno(int) nosideeffect libcesque;
char *strerdoc(int) nosideeffect libcesque;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_STR_ERRFUN_H_ */

View file

@ -211,8 +211,6 @@ wint_t towctrans(wint_t, wctrans_t);
char *strsignal(int) returnsnonnull libcesque;
char *strerror(int) returnsnonnull dontthrow nocallback;
char *strerrno(int) nosideeffect libcesque;
char *strerdoc(int) nosideeffect libcesque;
int strerror_r(int, char *, size_t) dontthrow nocallback;
int strerror_wr(int, uint32_t, char *, size_t) dontthrow nocallback;
int __xpg_strerror_r(int, char *, size_t) dontthrow nocallback;

View file

@ -1229,6 +1229,7 @@ syscon mount MNT_SNAPSHOT 0 0x40000000 0x01000000 0 0 0 # confusing
#
# group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology Commentary
syscon limits PIPE_BUF 4096 512 512 512 512 4096 # bsd consensus
syscon limits NGROUPS_MAX 65536 16 1023 16 16 0 #
syscon limits _ARG_MAX 128*1024 1024*1024 512*1024 512*1024 256*1024 32767*2 # bsd consensus
syscon limits _NAME_MAX 255 255 255 255 511 255 # probably higher on windows?
syscon limits _PATH_MAX 4096 1024 1024 1024 1024 512 # cosmopolitan libc imposes a lower 512 limit; nt theoretically goes up to 32767

View file

@ -0,0 +1,2 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon limits,NGROUPS_MAX,65536,16,1023,16,16,0

View file

@ -4,19 +4,21 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
extern const int NGROUPS_MAX;
extern const int PIPE_BUF;
extern const int _ARG_MAX;
extern const int _NAME_MAX;
extern const int _PATH_MAX;
extern const int _NSIG;
extern const int _PATH_MAX;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#define PIPE_BUF SYMBOLIC(PIPE_BUF)
#define _ARG_MAX SYMBOLIC(_ARG_MAX)
#define _NAME_MAX SYMBOLIC(_NAME_MAX)
#define _PATH_MAX SYMBOLIC(_PATH_MAX)
#define _NSIG SYMBOLIC(_NSIG)
#define NGROUPS_MAX SYMBOLIC(NGROUPS_MAX)
#define PIPE_BUF SYMBOLIC(PIPE_BUF)
#define _ARG_MAX SYMBOLIC(_ARG_MAX)
#define _NAME_MAX SYMBOLIC(_NAME_MAX)
#define _NSIG SYMBOLIC(_NSIG)
#define _PATH_MAX SYMBOLIC(_PATH_MAX)
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_LIMITS_H_ */

View file

@ -58,6 +58,7 @@
#include "libc/sock/syslog.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/path.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/af.h"

View file

@ -37,6 +37,7 @@
#include "libc/nt/runtime.h"
#include "libc/runtime/dlfcn.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/pathconf.h"
#include "libc/runtime/sysconf.h"
#include "libc/sock/sendfile.internal.h"
#include "libc/sock/sock.h"

View file

@ -22,6 +22,7 @@
#include "libc/fmt/conv.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"

View file

@ -23,6 +23,7 @@
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/o.h"

View file

@ -26,6 +26,7 @@
#include "libc/runtime/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/ex.h"

View file

@ -16,13 +16,14 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/limits.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/o.h"

View file

@ -30,6 +30,7 @@
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/runtime/runtime.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/msync.h"

View file

@ -21,6 +21,7 @@
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"

View file

@ -12,6 +12,7 @@
#include "libc/fmt/conv.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/x/x.h"

View file

@ -24,6 +24,7 @@
#include "libc/runtime/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/ex.h"

View file

@ -21,6 +21,7 @@
#include "libc/fmt/itoa.h"
#include "libc/mem/io.h"
#include "libc/runtime/runtime.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/o.h"

View file

@ -20,6 +20,7 @@
#include "libc/errno.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/intrin/bits.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/sigaction.h"
@ -29,6 +28,7 @@
#include "libc/errno.h"
#include "libc/fmt/fmt.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/kprintf.h"
#include "libc/intrin/nomultics.internal.h"
#include "libc/log/check.h"
@ -36,6 +36,7 @@
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/append.internal.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/nr.h"
#include "libc/sysv/consts/ptrace.h"

View file

@ -20,6 +20,7 @@
#include "libc/errno.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
/**

View file

@ -23,6 +23,7 @@
#include "libc/fmt/itoa.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/s.h"
#include "libc/x/x.h"

View file

@ -19,6 +19,7 @@
#include "libc/fmt/fmt.h"
#include "libc/intrin/dos2errno.internal.h"
#include "libc/intrin/kprintf.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
// note: these are supplementary errno magnum mappings