mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
Make some foss compatibility improvements
This commit is contained in:
parent
8111462789
commit
5af19b7eed
34 changed files with 319 additions and 48 deletions
30
ape/sections.internal.h
Normal file
30
ape/sections.internal.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
#ifndef COSMOPOLITAN_APE_SECTIONS_INTERNAL_H_
|
||||
#define COSMOPOLITAN_APE_SECTIONS_INTERNAL_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
extern unsigned char _base[];
|
||||
extern unsigned char _ehead[];
|
||||
extern unsigned char _etext[];
|
||||
extern unsigned char _edata[];
|
||||
extern unsigned char _ezip[];
|
||||
extern unsigned char _end[];
|
||||
extern unsigned char _ereal[];
|
||||
extern unsigned char __privileged_start[];
|
||||
extern unsigned char __privileged_addr[];
|
||||
extern unsigned char __privileged_size[];
|
||||
extern unsigned char __privileged_end[];
|
||||
extern unsigned char __test_start[];
|
||||
extern unsigned char __ro[];
|
||||
extern unsigned char *__relo_start[];
|
||||
extern unsigned char *__relo_end[];
|
||||
extern uint8_t __zip_start[];
|
||||
extern uint8_t __zip_end[];
|
||||
extern uint8_t __data_start[];
|
||||
extern uint8_t __data_end[];
|
||||
extern uint8_t __bss_start[];
|
||||
extern uint8_t __bss_end[];
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_APE_SECTIONS_INTERNAL_H_ */
|
|
@ -7,6 +7,7 @@
|
|||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/errno.h"
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/sig.internal.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/metalfile.internal.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/pledge.internal.h"
|
||||
#include "libc/calls/struct/bpf.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/state.internal.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/state.internal.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/state.internal.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/state.internal.h"
|
||||
|
|
|
@ -11,11 +11,10 @@
|
|||
#define st_mtime_nsec st_mtim.tv_nsec
|
||||
#define st_ctime_nsec st_ctim.tv_nsec
|
||||
|
||||
#define st_atimensec st_atim.tv_nsec
|
||||
#define st_mtimensec st_mtim.tv_nsec
|
||||
#define st_ctimensec st_ctim.tv_nsec
|
||||
#define st_birthtime st_birthtim.tv_sec
|
||||
#define st_birthtimensec st_birthtim.tv_nsec
|
||||
#define st_atimensec st_atim.tv_nsec
|
||||
#define st_mtimensec st_mtim.tv_nsec
|
||||
#define st_ctimensec st_ctim.tv_nsec
|
||||
#define st_birthtime st_birthtim.tv_sec
|
||||
|
||||
#define st_file_attributes st_flags
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@
|
|||
#define CHAR_BIT 8 /* b/c von neumann */
|
||||
#define ARG_MAX 0xfffe /* for argv and envp; see CreateProcess (32767*2) */
|
||||
#define PATH_MAX 1024 /* b/c _XOPEN_PATH_MAX */
|
||||
#define NAME_MAX 63 /* b/c dns */
|
||||
#define NAME_MAX 255 /* 511 on netbsd */
|
||||
#define CHILD_MAX 16 /* only if malloc isn't linked */
|
||||
#define OPEN_MAX 16 /* only if malloc isn't linked */
|
||||
#define ATEXIT_MAX 32 /* only if malloc isn't linked */
|
||||
|
|
11
libc/isystem/linux/limits.h
Normal file
11
libc/isystem/linux/limits.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_LINUX_LIMITS_H_
|
||||
#define COSMOPOLITAN_LIBC_ISYSTEM_LINUX_LIMITS_H_
|
||||
#include "libc/sysv/consts/limits.h"
|
||||
|
||||
#define NR_OPEN 1024
|
||||
#define XATTR_NAME_MAX 255
|
||||
#define XATTR_SIZE_MAX 65536
|
||||
#define XATTR_LIST_MAX 65536
|
||||
#define RTSIG_MAX 32
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_LINUX_LIMITS_H_ */
|
25
libc/isystem/linux/types.h
Normal file
25
libc/isystem/linux/types.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_LINUX_TYPES_H_
|
||||
#define COSMOPOLITAN_LIBC_ISYSTEM_LINUX_TYPES_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
typedef uint16_t __u16;
|
||||
typedef uint32_t __u32;
|
||||
typedef uint64_t __u64;
|
||||
|
||||
typedef __u16 __le16;
|
||||
typedef __u16 __be16;
|
||||
typedef __u32 __le32;
|
||||
typedef __u32 __be32;
|
||||
typedef __u64 __le64;
|
||||
typedef __u64 __be64;
|
||||
typedef __u16 __sum16;
|
||||
typedef __u32 __wsum;
|
||||
|
||||
#define __aligned_u64 __u64 __attribute__((__aligned__(8)))
|
||||
#define __aligned_be64 __be64 __attribute__((__aligned__(8)))
|
||||
#define __aligned_le64 __le64 __attribute__((__aligned__(8)))
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_LINUX_TYPES_H_ */
|
4
libc/isystem/mntent.h
Normal file
4
libc/isystem/mntent.h
Normal file
|
@ -0,0 +1,4 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_MNTENT_H_
|
||||
#define COSMOPOLITAN_LIBC_ISYSTEM_MNTENT_H_
|
||||
#include "third_party/musl/mntent.h"
|
||||
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_MNTENT_H_ */
|
|
@ -16,8 +16,9 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nt/efi.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_RUNTIME_MEMTRACK_H_
|
||||
#define COSMOPOLITAN_LIBC_RUNTIME_MEMTRACK_H_
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/nopl.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#define ShouldUseMsabiAttribute() 1
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/dce.h"
|
||||
|
|
|
@ -25,27 +25,6 @@ extern uint64_t kStartTsc; /* RII */
|
|||
extern char kTmpPath[]; /* RII */
|
||||
extern const char kNtSystemDirectory[]; /* RII */
|
||||
extern const char kNtWindowsDirectory[]; /* RII */
|
||||
extern unsigned char _base[]; /* αpε */
|
||||
extern unsigned char _ehead[]; /* αpε */
|
||||
extern unsigned char _etext[]; /* αpε */
|
||||
extern unsigned char _edata[]; /* αpε */
|
||||
extern unsigned char _ezip[]; /* αpε */
|
||||
extern unsigned char _end[]; /* αpε */
|
||||
extern unsigned char _ereal[]; /* αpε */
|
||||
extern unsigned char __privileged_start[]; /* αpε */
|
||||
extern unsigned char __privileged_addr[]; /* αpε */
|
||||
extern unsigned char __privileged_size[]; /* αpε */
|
||||
extern unsigned char __privileged_end[]; /* αpε */
|
||||
extern unsigned char __test_start[]; /* αpε */
|
||||
extern unsigned char __ro[]; /* αpε */
|
||||
extern unsigned char *__relo_start[]; /* αpε */
|
||||
extern unsigned char *__relo_end[]; /* αpε */
|
||||
extern uint8_t __zip_start[]; /* αpε */
|
||||
extern uint8_t __zip_end[]; /* αpε */
|
||||
extern uint8_t __data_start[]; /* αpε */
|
||||
extern uint8_t __data_end[]; /* αpε */
|
||||
extern uint8_t __bss_start[]; /* αpε */
|
||||
extern uint8_t __bss_end[]; /* αpε */
|
||||
extern size_t __virtualmax;
|
||||
extern bool __isworker;
|
||||
|
||||
|
|
24
libc/stdio/__fseterr.c
Normal file
24
libc/stdio/__fseterr.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/errno.h"
|
||||
#include "libc/stdio/stdio_ext.h"
|
||||
|
||||
void __fseterr(FILE *f) {
|
||||
f->state |= EIO;
|
||||
}
|
|
@ -19,6 +19,7 @@ int __fwriting(FILE *);
|
|||
int __fsetlocking(FILE *, int);
|
||||
void _flushlbf(void);
|
||||
void __fpurge(FILE *);
|
||||
void __fseterr(FILE *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -1228,6 +1228,9 @@ 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 LINK_MAX 127 32767 32767 32767 32767 64 # freebsd/windows are educated guesses
|
||||
syscon limits MAX_CANON 255 1024 255 255 255 255 # windows is guessed
|
||||
syscon limits MAX_INPUT 255 1024 255 255 255 255 # windows is guessed
|
||||
syscon limits SOMAXCONN 4096 128 128 128 128 2147483647 # maximum backlog for listen()
|
||||
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?
|
||||
|
|
|
@ -11,6 +11,9 @@ extern const int _ARG_MAX;
|
|||
extern const int _NAME_MAX;
|
||||
extern const int _NSIG;
|
||||
extern const int _PATH_MAX;
|
||||
extern const int LINK_MAX;
|
||||
extern const int MAX_CANON;
|
||||
extern const int MAX_INPUT;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
@ -22,5 +25,8 @@ COSMOPOLITAN_C_END_
|
|||
#define _NAME_MAX SYMBOLIC(_NAME_MAX)
|
||||
#define _NSIG SYMBOLIC(_NSIG)
|
||||
#define _PATH_MAX SYMBOLIC(_PATH_MAX)
|
||||
#define LINK_MAX SYMBOLIC(LINK_MAX)
|
||||
#define MAX_CANON SYMBOLIC(MAX_CANON)
|
||||
#define MAX_INPUT SYMBOLIC(MAX_INPUT)
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_LIMITS_H_ */
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/kntprioritycombos.internal.h"
|
||||
#include "libc/errno.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/path.h"
|
||||
#include "libc/str/str.h"
|
||||
|
@ -23,12 +24,14 @@
|
|||
#include "libc/thread/thread.h"
|
||||
|
||||
const char *__sem_name(const char *name, char path[hasatleast PATH_MAX]) {
|
||||
const char *res;
|
||||
if (_isabspath(name)) {
|
||||
return name;
|
||||
res = name;
|
||||
} else {
|
||||
strlcpy(path, kTmpPath, PATH_MAX);
|
||||
strlcat(path, ".sem-", PATH_MAX);
|
||||
strlcat(path, name, PATH_MAX);
|
||||
return path;
|
||||
res = path;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,12 @@ sem_t *sem_open(const char *name, int oflag, ...) {
|
|||
}
|
||||
|
||||
sem = mmap(0, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (sem != MAP_FAILED) sem->sem_pshared = true;
|
||||
if (sem != MAP_FAILED) {
|
||||
sem->sem_pshared = true;
|
||||
} else {
|
||||
sem = SEM_FAILED;
|
||||
}
|
||||
|
||||
_npassert(!close(fd));
|
||||
return sem;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/calls/struct/rlimit.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/sections.internal.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/log/check.h"
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/mem/gc.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
@ -31,10 +32,10 @@ pthread_barrier_t barrier;
|
|||
char testlib_enable_tmp_setup_teardown;
|
||||
|
||||
void *Worker(void *arg) {
|
||||
sem_t *s[2];
|
||||
sem_t *a, *b;
|
||||
struct timespec ts;
|
||||
ASSERT_NE(SEM_FAILED, (s[0] = sem_open("fooz", O_CREAT, 0644)));
|
||||
ASSERT_NE(SEM_FAILED, (s[1] = sem_open("barz", O_CREAT, 0644)));
|
||||
ASSERT_NE(SEM_FAILED, (a = sem_open("fooz", O_CREAT, 0644)));
|
||||
ASSERT_NE(SEM_FAILED, (b = sem_open("barz", O_CREAT, 0644)));
|
||||
if (pthread_barrier_wait(&barrier) == PTHREAD_BARRIER_SERIAL_THREAD) {
|
||||
if (!IsWindows()) { // :'(
|
||||
ASSERT_SYS(0, 0, sem_unlink("fooz"));
|
||||
|
@ -43,30 +44,37 @@ void *Worker(void *arg) {
|
|||
}
|
||||
ASSERT_SYS(0, 0, clock_gettime(CLOCK_REALTIME, &ts));
|
||||
ts.tv_sec += 1;
|
||||
ASSERT_SYS(0, 0, sem_post(s[0]));
|
||||
ASSERT_SYS(0, 0, sem_timedwait(s[1], &ts));
|
||||
ASSERT_SYS(0, 0, sem_close(s[1]));
|
||||
ASSERT_SYS(0, 0, sem_close(s[0]));
|
||||
ASSERT_SYS(0, 0, sem_post(a));
|
||||
ASSERT_SYS(0, 0, sem_timedwait(b, &ts));
|
||||
ASSERT_SYS(0, 0, sem_close(b));
|
||||
ASSERT_SYS(0, 0, sem_close(a));
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST(sem_open, test) {
|
||||
if (IsWindows()) return; // TODO(jart): fix me
|
||||
sem_t *s[2];
|
||||
if (IsLinux()) return; // TODO(jart): Fix shocking GitHub Actions error.
|
||||
sem_t *a, *b;
|
||||
int i, r, n = 4;
|
||||
pthread_t *t = _gc(malloc(sizeof(pthread_t) * n));
|
||||
sem_unlink("barz");
|
||||
sem_unlink("fooz");
|
||||
errno = 0;
|
||||
ASSERT_EQ(0, pthread_barrier_init(&barrier, 0, n));
|
||||
ASSERT_NE(SEM_FAILED, (s[0] = sem_open("fooz", O_CREAT, 0644)));
|
||||
ASSERT_NE(SEM_FAILED, (s[1] = sem_open("barz", O_CREAT, 0644)));
|
||||
ASSERT_NE(SEM_FAILED, (a = sem_open("fooz", O_CREAT, 0644)));
|
||||
ASSERT_NE(SEM_FAILED, (b = sem_open("barz", O_CREAT, 0644)));
|
||||
ASSERT_SYS(0, 0, sem_getvalue(a, &r));
|
||||
ASSERT_EQ(0, r);
|
||||
ASSERT_SYS(0, 0, sem_getvalue(b, &r));
|
||||
ASSERT_EQ(0, r);
|
||||
for (i = 0; i < n; ++i) ASSERT_EQ(0, pthread_create(t + i, 0, Worker, 0));
|
||||
for (i = 0; i < n; ++i) ASSERT_SYS(0, 0, sem_wait(s[0]));
|
||||
ASSERT_SYS(0, 0, sem_getvalue(s[0], &r));
|
||||
for (i = 0; i < n; ++i) ASSERT_SYS(0, 0, sem_wait(a));
|
||||
ASSERT_SYS(0, 0, sem_getvalue(a, &r));
|
||||
ASSERT_EQ(0, r);
|
||||
for (i = 0; i < n; ++i) ASSERT_SYS(0, 0, sem_post(s[1]));
|
||||
for (i = 0; i < n; ++i) ASSERT_SYS(0, 0, sem_post(b));
|
||||
for (i = 0; i < n; ++i) ASSERT_EQ(0, pthread_join(t[i], 0));
|
||||
ASSERT_SYS(0, 0, sem_getvalue(s[1], &r));
|
||||
ASSERT_SYS(0, 0, sem_getvalue(b, &r));
|
||||
ASSERT_EQ(0, r);
|
||||
ASSERT_SYS(0, 0, sem_close(s[1]));
|
||||
ASSERT_SYS(0, 0, sem_close(s[0]));
|
||||
ASSERT_SYS(0, 0, sem_close(b));
|
||||
ASSERT_SYS(0, 0, sem_close(a));
|
||||
ASSERT_EQ(0, pthread_barrier_destroy(&barrier));
|
||||
}
|
||||
|
|
118
third_party/musl/mntent.c
vendored
Normal file
118
third_party/musl/mntent.c
vendored
Normal file
|
@ -0,0 +1,118 @@
|
|||
/*-*- 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│
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ 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/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/musl/mntent.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
// clang-format off
|
||||
|
||||
static char *internal_buf;
|
||||
static size_t internal_bufsize;
|
||||
|
||||
#define SENTINEL (char *)&internal_buf
|
||||
|
||||
FILE *setmntent(const char *name, const char *mode)
|
||||
{
|
||||
return fopen(name, mode);
|
||||
}
|
||||
|
||||
int endmntent(FILE *f)
|
||||
{
|
||||
if (f) fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen)
|
||||
{
|
||||
int n[8], use_internal = (linebuf == SENTINEL);
|
||||
size_t len, i;
|
||||
|
||||
mnt->mnt_freq = 0;
|
||||
mnt->mnt_passno = 0;
|
||||
|
||||
do {
|
||||
if (use_internal) {
|
||||
getline(&internal_buf, &internal_bufsize, f);
|
||||
linebuf = internal_buf;
|
||||
} else {
|
||||
fgets(linebuf, buflen, f);
|
||||
}
|
||||
if (feof(f) || ferror(f)) return 0;
|
||||
if (!strchr(linebuf, '\n')) {
|
||||
fscanf(f, "%*[^\n]%*[\n]");
|
||||
errno = ERANGE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = strlen(linebuf);
|
||||
if (len > INT_MAX) continue;
|
||||
for (i = 0; i < sizeof n / sizeof *n; i++) n[i] = len;
|
||||
sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d",
|
||||
n, n+1, n+2, n+3, n+4, n+5, n+6, n+7,
|
||||
&mnt->mnt_freq, &mnt->mnt_passno);
|
||||
} while (linebuf[n[0]] == '#' || n[1]==len);
|
||||
|
||||
linebuf[n[1]] = 0;
|
||||
linebuf[n[3]] = 0;
|
||||
linebuf[n[5]] = 0;
|
||||
linebuf[n[7]] = 0;
|
||||
|
||||
mnt->mnt_fsname = linebuf+n[0];
|
||||
mnt->mnt_dir = linebuf+n[2];
|
||||
mnt->mnt_type = linebuf+n[4];
|
||||
mnt->mnt_opts = linebuf+n[6];
|
||||
|
||||
return mnt;
|
||||
}
|
||||
|
||||
struct mntent *getmntent(FILE *f)
|
||||
{
|
||||
static struct mntent mnt;
|
||||
return getmntent_r(f, &mnt, SENTINEL, 0);
|
||||
}
|
||||
|
||||
int addmntent(FILE *f, const struct mntent *mnt)
|
||||
{
|
||||
if (fseek(f, 0, SEEK_END)) return 1;
|
||||
return fprintf(f, "%s\t%s\t%s\t%s\t%d\t%d\n",
|
||||
mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, mnt->mnt_opts,
|
||||
mnt->mnt_freq, mnt->mnt_passno) < 0;
|
||||
}
|
||||
|
||||
char *hasmntopt(const struct mntent *mnt, const char *opt)
|
||||
{
|
||||
return strstr(mnt->mnt_opts, opt);
|
||||
}
|
37
third_party/musl/mntent.h
vendored
Normal file
37
third_party/musl/mntent.h
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
#ifndef COSMOPOLITAN_THIRD_PARTY_MUSL_MNTENT_H_
|
||||
#define COSMOPOLITAN_THIRD_PARTY_MUSL_MNTENT_H_
|
||||
#include "libc/stdio/stdio.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define MOUNTED "/etc/mtab"
|
||||
|
||||
#define MNTTYPE_IGNORE "ignore"
|
||||
#define MNTTYPE_NFS "nfs"
|
||||
#define MNTTYPE_SWAP "swap"
|
||||
#define MNTOPT_DEFAULTS "defaults"
|
||||
#define MNTOPT_RO "ro"
|
||||
#define MNTOPT_RW "rw"
|
||||
#define MNTOPT_SUID "suid"
|
||||
#define MNTOPT_NOSUID "nosuid"
|
||||
#define MNTOPT_NOAUTO "noauto"
|
||||
|
||||
struct mntent {
|
||||
char *mnt_fsname;
|
||||
char *mnt_dir;
|
||||
char *mnt_type;
|
||||
char *mnt_opts;
|
||||
int mnt_freq;
|
||||
int mnt_passno;
|
||||
};
|
||||
|
||||
FILE *setmntent(const char *, const char *);
|
||||
int endmntent(FILE *);
|
||||
struct mntent *getmntent(FILE *);
|
||||
struct mntent *getmntent_r(FILE *, struct mntent *, char *, int);
|
||||
int addmntent(FILE *, const struct mntent *);
|
||||
char *hasmntopt(const struct mntent *, const char *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_THIRD_PARTY_MUSL_MNTENT_H_ */
|
Loading…
Reference in a new issue