mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 13:52:28 +00:00
Fix some static analysis issues
This commit is contained in:
parent
fb54604b31
commit
f147d3dde9
30 changed files with 375 additions and 266 deletions
|
@ -69,48 +69,49 @@ COSMOPOLITAN_C_START_
|
||||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||||
│ cosmopolitan § system calls ─╬─│┼
|
│ cosmopolitan § system calls ─╬─│┼
|
||||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||||
|
/* clang-format off */
|
||||||
|
|
||||||
typedef int sig_atomic_t;
|
typedef int sig_atomic_t;
|
||||||
|
|
||||||
bool32 isatty(int) libcesque;
|
bool32 isatty(int) libcesque;
|
||||||
char *getcwd(char *, size_t) dontthrow;
|
char *getcwd(char *, size_t) dontthrow __write_only(1, 2);
|
||||||
char *realpath(const char *, char *) libcesque __wur;
|
char *realpath(const char *, char *) libcesque __wur __read_only(1) __write_only(2);
|
||||||
char *ttyname(int) libcesque;
|
char *ttyname(int) libcesque;
|
||||||
int access(const char *, int) libcesque;
|
int access(const char *, int) libcesque __read_only(1);
|
||||||
int chdir(const char *) libcesque;
|
int chdir(const char *) libcesque __read_only(1);
|
||||||
int chmod(const char *, unsigned) libcesque;
|
int chmod(const char *, unsigned) libcesque __read_only(1);
|
||||||
int chown(const char *, unsigned, unsigned) libcesque;
|
int chown(const char *, unsigned, unsigned) libcesque __read_only(1);
|
||||||
int chroot(const char *) libcesque;
|
int chroot(const char *) libcesque __read_only(1);
|
||||||
int close(int) libcesque;
|
int close(int) libcesque;
|
||||||
int close_range(unsigned, unsigned, unsigned) libcesque;
|
int close_range(unsigned, unsigned, unsigned) libcesque;
|
||||||
int closefrom(int) libcesque;
|
int closefrom(int) libcesque;
|
||||||
int creat(const char *, unsigned) libcesque;
|
int creat(const char *, unsigned) libcesque __read_only(1);
|
||||||
int dup(int) libcesque;
|
int dup(int) libcesque;
|
||||||
int dup2(int, int) libcesque;
|
int dup2(int, int) libcesque;
|
||||||
int dup3(int, int, int) libcesque;
|
int dup3(int, int, int) libcesque;
|
||||||
int execl(const char *, const char *, ...) nullterminated() libcesque;
|
int execl(const char *, const char *, ...) nullterminated() libcesque __read_only(1) __read_only(2);
|
||||||
int execle(const char *, const char *, ...) nullterminated((1)) libcesque;
|
int execle(const char *, const char *, ...) nullterminated((1)) libcesque __read_only(1) __read_only(2);
|
||||||
int execlp(const char *, const char *, ...) nullterminated() libcesque;
|
int execlp(const char *, const char *, ...) nullterminated() libcesque __read_only(1) __read_only(2);
|
||||||
int execv(const char *, char *const[]) libcesque;
|
int execv(const char *, char *const[]) libcesque __read_only(1) __read_only(2);
|
||||||
int execve(const char *, char *const[], char *const[]) libcesque;
|
int execve(const char *, char *const[], char *const[]) libcesque __read_only(1) __read_only(2) __read_only(3);
|
||||||
int execvp(const char *, char *const[]) libcesque;
|
int execvp(const char *, char *const[]) libcesque __read_only(1) __read_only(2);
|
||||||
int faccessat(int, const char *, int, int) libcesque;
|
int faccessat(int, const char *, int, int) libcesque __read_only(2);
|
||||||
int fchdir(int) libcesque;
|
int fchdir(int) libcesque;
|
||||||
int fchmod(int, unsigned) libcesque;
|
int fchmod(int, unsigned) libcesque;
|
||||||
int fchmodat(int, const char *, unsigned, int) libcesque;
|
int fchmodat(int, const char *, unsigned, int) libcesque __read_only(2);
|
||||||
int fchown(int, unsigned, unsigned) libcesque;
|
int fchown(int, unsigned, unsigned) libcesque;
|
||||||
int fchownat(int, const char *, unsigned, unsigned, int) libcesque;
|
int fchownat(int, const char *, unsigned, unsigned, int) libcesque __read_only(2);
|
||||||
int fcntl(int, int, ...) libcesque;
|
int fcntl(int, int, ...) libcesque;
|
||||||
int fdatasync(int) libcesque;
|
int fdatasync(int) libcesque;
|
||||||
int fexecve(int, char *const[], char *const[]) libcesque;
|
int fexecve(int, char *const[], char *const[]) libcesque __read_only(2) __read_only(3);
|
||||||
int flock(int, int) libcesque;
|
int flock(int, int) libcesque;
|
||||||
int fork(void) libcesque;
|
int fork(void) libcesque;
|
||||||
int fsync(int) libcesque;
|
int fsync(int) libcesque;
|
||||||
int ftruncate(int, int64_t) libcesque;
|
int ftruncate(int, int64_t) libcesque;
|
||||||
int getdomainname(char *, size_t) libcesque;
|
int getdomainname(char *, size_t) libcesque __write_only(1, 2);
|
||||||
int getgroups(int, unsigned[]) libcesque;
|
int getgroups(int, unsigned[]) libcesque __write_only(2, 1);
|
||||||
int gethostname(char *, size_t) libcesque;
|
int gethostname(char *, size_t) libcesque __write_only(1, 2);
|
||||||
int getloadavg(double *, int) libcesque;
|
int getloadavg(double *, int) libcesque __write_only(1, 2);
|
||||||
int getpgid(int) libcesque;
|
int getpgid(int) libcesque;
|
||||||
int getpgrp(void) libcesque nosideeffect;
|
int getpgrp(void) libcesque nosideeffect;
|
||||||
int getpid(void) libcesque nosideeffect;
|
int getpid(void) libcesque nosideeffect;
|
||||||
|
@ -121,35 +122,35 @@ int ioctl(int, unsigned long, ...) libcesque;
|
||||||
int issetugid(void) libcesque;
|
int issetugid(void) libcesque;
|
||||||
int kill(int, int) libcesque;
|
int kill(int, int) libcesque;
|
||||||
int killpg(int, int) libcesque;
|
int killpg(int, int) libcesque;
|
||||||
int lchmod(const char *, unsigned) libcesque;
|
int lchmod(const char *, unsigned) libcesque __read_only(1);
|
||||||
int lchown(const char *, unsigned, unsigned) libcesque;
|
int lchown(const char *, unsigned, unsigned) libcesque __read_only(1);
|
||||||
int link(const char *, const char *) libcesque;
|
int link(const char *, const char *) libcesque __read_only(1) __read_only(2);
|
||||||
int linkat(int, const char *, int, const char *, int) libcesque;
|
int linkat(int, const char *, int, const char *, int) libcesque __read_only(2) __read_only(4);
|
||||||
int mincore(void *, size_t, unsigned char *) libcesque;
|
int mincore(void *, size_t, unsigned char *) libcesque __read_only(1) __write_only(3);
|
||||||
int mkdir(const char *, unsigned) libcesque;
|
int mkdir(const char *, unsigned) libcesque __read_only(1);
|
||||||
int mkdirat(int, const char *, unsigned) libcesque;
|
int mkdirat(int, const char *, unsigned) libcesque __read_only(2);
|
||||||
int mknod(const char *, unsigned, uint64_t) libcesque;
|
int mknod(const char *, unsigned, uint64_t) libcesque __read_only(1);
|
||||||
int nice(int) libcesque;
|
int nice(int) libcesque;
|
||||||
int open(const char *, int, ...) libcesque;
|
int open(const char *, int, ...) libcesque __read_only(1);
|
||||||
int openat(int, const char *, int, ...) libcesque;
|
int openat(int, const char *, int, ...) libcesque __read_only(2);
|
||||||
int pause(void) libcesque;
|
int pause(void) libcesque;
|
||||||
int pipe(int[2]) libcesque;
|
int pipe(int[2]) libcesque __write_only(1);
|
||||||
int pipe2(int[2], int) libcesque;
|
int pipe2(int[2], int) libcesque __write_only(1);
|
||||||
int posix_fadvise(int, int64_t, int64_t, int) libcesque;
|
int posix_fadvise(int, int64_t, int64_t, int) libcesque;
|
||||||
int posix_madvise(void *, uint64_t, int) libcesque;
|
int posix_madvise(void *, uint64_t, int) libcesque __read_write(1);
|
||||||
int raise(int) libcesque;
|
int raise(int) libcesque;
|
||||||
int reboot(int) libcesque;
|
int reboot(int) libcesque;
|
||||||
int remove(const char *) libcesque;
|
int remove(const char *) libcesque __read_only(1);
|
||||||
int rename(const char *, const char *) libcesque;
|
int rename(const char *, const char *) libcesque __read_only(1) __read_only(2);
|
||||||
int renameat(int, const char *, int, const char *) libcesque;
|
int renameat(int, const char *, int, const char *) libcesque __read_only(2) __read_only(4);
|
||||||
int rmdir(const char *) libcesque;
|
int rmdir(const char *) libcesque __read_only(1);
|
||||||
int sched_yield(void) libcesque;
|
int sched_yield(void) libcesque;
|
||||||
int setegid(unsigned) libcesque;
|
int setegid(unsigned) libcesque;
|
||||||
int seteuid(unsigned) libcesque;
|
int seteuid(unsigned) libcesque;
|
||||||
int setfsgid(unsigned) libcesque;
|
int setfsgid(unsigned) libcesque;
|
||||||
int setfsuid(unsigned) libcesque;
|
int setfsuid(unsigned) libcesque;
|
||||||
int setgid(unsigned) libcesque;
|
int setgid(unsigned) libcesque;
|
||||||
int setgroups(size_t, const unsigned[]) libcesque;
|
int setgroups(size_t, const unsigned[]) libcesque __read_only(2);
|
||||||
int setpgid(int, int) libcesque;
|
int setpgid(int, int) libcesque;
|
||||||
int setpgrp(void) libcesque;
|
int setpgrp(void) libcesque;
|
||||||
int setpriority(int, unsigned, int) libcesque;
|
int setpriority(int, unsigned, int) libcesque;
|
||||||
|
@ -157,32 +158,32 @@ int setregid(unsigned, unsigned) libcesque;
|
||||||
int setreuid(unsigned, unsigned) libcesque;
|
int setreuid(unsigned, unsigned) libcesque;
|
||||||
int setsid(void) libcesque;
|
int setsid(void) libcesque;
|
||||||
int setuid(unsigned) libcesque;
|
int setuid(unsigned) libcesque;
|
||||||
int shm_open(const char *, int, unsigned) libcesque;
|
int shm_open(const char *, int, unsigned) libcesque __read_only(1);
|
||||||
int shm_unlink(const char *) libcesque;
|
int shm_unlink(const char *) libcesque __read_only(1);
|
||||||
int sigignore(int) libcesque;
|
int sigignore(int) libcesque;
|
||||||
int siginterrupt(int, int) libcesque;
|
int siginterrupt(int, int) libcesque;
|
||||||
int symlink(const char *, const char *) libcesque;
|
int symlink(const char *, const char *) libcesque __read_only(1) __read_only(2);
|
||||||
int symlinkat(const char *, int, const char *) libcesque;
|
int symlinkat(const char *, int, const char *) libcesque __read_only(1) __read_only(3);
|
||||||
int tcgetpgrp(int) libcesque;
|
int tcgetpgrp(int) libcesque;
|
||||||
int tcsetpgrp(int, int) libcesque;
|
int tcsetpgrp(int, int) libcesque;
|
||||||
int truncate(const char *, int64_t) libcesque;
|
int truncate(const char *, int64_t) libcesque __read_only(1);
|
||||||
int ttyname_r(int, char *, size_t) libcesque;
|
int ttyname_r(int, char *, size_t) libcesque __write_only(2, 3);
|
||||||
int unlink(const char *) libcesque;
|
int unlink(const char *) libcesque __read_only(1);
|
||||||
int unlinkat(int, const char *, int) libcesque;
|
int unlinkat(int, const char *, int) libcesque __read_only(2);
|
||||||
int usleep(uint64_t) libcesque;
|
int usleep(uint64_t) libcesque;
|
||||||
int vfork(void) libcesque returnstwice;
|
int vfork(void) libcesque returnstwice;
|
||||||
int wait(int *) libcesque;
|
int wait(int *) libcesque __write_only(1);
|
||||||
int waitpid(int, int *, int) libcesque;
|
int waitpid(int, int *, int) libcesque __write_only(2);
|
||||||
int64_t clock(void) libcesque;
|
int64_t clock(void) libcesque;
|
||||||
int64_t time(int64_t *) libcesque;
|
int64_t time(int64_t *) libcesque __write_only(1);
|
||||||
ssize_t copy_file_range(int, long *, int, long *, size_t, unsigned) libcesque;
|
ssize_t copy_file_range(int, long *, int, long *, size_t, unsigned) libcesque __read_write(2) __read_write(4);
|
||||||
ssize_t lseek(int, int64_t, int) libcesque;
|
ssize_t lseek(int, int64_t, int) libcesque;
|
||||||
ssize_t pread(int, void *, size_t, int64_t) libcesque;
|
ssize_t pread(int, void *, size_t, int64_t) libcesque __write_only(2, 3);
|
||||||
ssize_t pwrite(int, const void *, size_t, int64_t) libcesque;
|
ssize_t pwrite(int, const void *, size_t, int64_t) libcesque __read_only(2);
|
||||||
ssize_t read(int, void *, size_t) libcesque;
|
ssize_t read(int, void *, size_t) libcesque __write_only(2, 3);
|
||||||
ssize_t readlink(const char *, char *, size_t) libcesque;
|
ssize_t readlink(const char *, char *, size_t) libcesque __read_only(1) __write_only(2, 3);
|
||||||
ssize_t readlinkat(int, const char *, char *, size_t) libcesque;
|
ssize_t readlinkat(int, const char *, char *, size_t) libcesque __read_only(2) __write_only(3, 4);
|
||||||
ssize_t write(int, const void *, size_t) libcesque;
|
ssize_t write(int, const void *, size_t) libcesque __read_only(2);
|
||||||
unsigned alarm(unsigned) libcesque;
|
unsigned alarm(unsigned) libcesque;
|
||||||
unsigned getegid(void) libcesque nosideeffect;
|
unsigned getegid(void) libcesque nosideeffect;
|
||||||
unsigned geteuid(void) libcesque nosideeffect;
|
unsigned geteuid(void) libcesque nosideeffect;
|
||||||
|
@ -199,50 +200,50 @@ int prctl(int, ...) libcesque;
|
||||||
int gettid(void) libcesque;
|
int gettid(void) libcesque;
|
||||||
int setresgid(unsigned, unsigned, unsigned) libcesque;
|
int setresgid(unsigned, unsigned, unsigned) libcesque;
|
||||||
int setresuid(unsigned, unsigned, unsigned) libcesque;
|
int setresuid(unsigned, unsigned, unsigned) libcesque;
|
||||||
int getresgid(unsigned *, unsigned *, unsigned *) libcesque;
|
int getresgid(unsigned *, unsigned *, unsigned *) libcesque __write_only(1) __write_only(2) __write_only(3);
|
||||||
int getresuid(unsigned *, unsigned *, unsigned *) libcesque;
|
int getresuid(unsigned *, unsigned *, unsigned *) libcesque __write_only(1) __write_only(2) __write_only(3);
|
||||||
char *get_current_dir_name(void) libcesque __wur;
|
char *get_current_dir_name(void) libcesque __wur;
|
||||||
ssize_t splice(int, int64_t *, int, int64_t *, size_t, unsigned) libcesque;
|
ssize_t splice(int, int64_t *, int, int64_t *, size_t, unsigned) libcesque __read_write(2) __read_write(4);
|
||||||
int memfd_create(const char *, unsigned int) libcesque;
|
int memfd_create(const char *, unsigned int) libcesque __read_only(1);
|
||||||
int execvpe(const char *, char *const[], char *const[]) libcesque;
|
int execvpe(const char *, char *const[], char *const[]) libcesque __read_only(1) __read_only(2) __read_only(3);
|
||||||
int euidaccess(const char *, int) libcesque;
|
int euidaccess(const char *, int) libcesque __read_only(1);
|
||||||
int eaccess(const char *, int) libcesque;
|
int eaccess(const char *, int) libcesque __read_only(1);
|
||||||
int madvise(void *, uint64_t, int) libcesque;
|
int madvise(void *, uint64_t, int) libcesque __read_write(1);
|
||||||
int getcpu(unsigned *, unsigned *) libcesque;
|
int getcpu(unsigned *, unsigned *) libcesque __write_only(1) __write_only(2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _COSMO_SOURCE
|
#ifdef _COSMO_SOURCE
|
||||||
bool32 fdexists(int) libcesque;
|
bool32 fdexists(int) libcesque;
|
||||||
bool32 fileexists(const char *) libcesque;
|
bool32 fileexists(const char *) libcesque __read_only(1);
|
||||||
bool32 ischardev(int) libcesque;
|
bool32 ischardev(int) libcesque;
|
||||||
bool32 isdirectory(const char *) libcesque;
|
bool32 isdirectory(const char *) libcesque __read_only(1);
|
||||||
bool32 isexecutable(const char *) libcesque;
|
bool32 isexecutable(const char *) libcesque __read_only(1);
|
||||||
bool32 isregularfile(const char *) libcesque;
|
bool32 isregularfile(const char *) libcesque __read_only(1);
|
||||||
bool32 issymlink(const char *) libcesque;
|
bool32 issymlink(const char *) libcesque __read_only(1);
|
||||||
char *commandv(const char *, char *, size_t) libcesque;
|
char *commandv(const char *, char *, size_t) libcesque __read_only(1) __write_only(2, 3);
|
||||||
int __getcwd(char *, size_t) libcesque;
|
int __getcwd(char *, size_t) libcesque __write_only(1, 2);
|
||||||
int clone(void *, void *, size_t, int, void *, void *, void *, void *);
|
int clone(void *, void *, size_t, int, void *, void *, void *, void *);
|
||||||
int fadvise(int, uint64_t, uint64_t, int) libcesque;
|
int fadvise(int, uint64_t, uint64_t, int) libcesque;
|
||||||
int makedirs(const char *, unsigned) libcesque;
|
int makedirs(const char *, unsigned) libcesque __read_only(1);
|
||||||
int pivot_root(const char *, const char *) libcesque;
|
int pivot_root(const char *, const char *) libcesque __read_only(1) __read_only(2);
|
||||||
int pledge(const char *, const char *) libcesque;
|
int pledge(const char *, const char *) libcesque __read_only(1) __read_only(2);
|
||||||
int seccomp(unsigned, unsigned, void *) libcesque;
|
int seccomp(unsigned, unsigned, void *) libcesque __read_only(3);
|
||||||
int sys_iopl(int) libcesque;
|
int sys_iopl(int) libcesque;
|
||||||
int sys_ioprio_get(int, int) libcesque;
|
int sys_ioprio_get(int, int) libcesque;
|
||||||
int sys_ioprio_set(int, int, int) libcesque;
|
int sys_ioprio_set(int, int, int) libcesque;
|
||||||
int sys_mlock(const void *, size_t) libcesque;
|
int sys_mlock(const void *, size_t) libcesque __read_only(1);
|
||||||
int sys_mlock2(const void *, size_t, int) libcesque;
|
int sys_mlock2(const void *, size_t, int) libcesque __read_only(1);
|
||||||
int sys_mlockall(int) libcesque;
|
int sys_mlockall(int) libcesque;
|
||||||
int sys_munlock(const void *, size_t) libcesque;
|
int sys_munlock(const void *, size_t) libcesque __read_only(1);
|
||||||
int sys_munlockall(void) libcesque;
|
int sys_munlockall(void) libcesque;
|
||||||
int sys_personality(uint64_t) libcesque;
|
int sys_personality(uint64_t) libcesque;
|
||||||
int sys_ptrace(int, ...) libcesque;
|
int sys_ptrace(int, ...) libcesque;
|
||||||
int sysctl(int *, unsigned, void *, size_t *, void *, size_t) libcesque;
|
int sysctl(int *, unsigned, void *, size_t *, void *, size_t) libcesque __read_write(1) __read_write(4) __read_write(5);
|
||||||
int sysctlbyname(const char *, void *, size_t *, void *, size_t) libcesque;
|
int sysctlbyname(const char *, void *, size_t *, void *, size_t) libcesque __read_only(1) __write_only(2) __read_write(3) __read_only(4);
|
||||||
int sysctlnametomib(const char *, int *, size_t *) libcesque;
|
int sysctlnametomib(const char *, int *, size_t *) libcesque __read_only(1) __write_only(2) __read_write(3);
|
||||||
int tmpfd(void) libcesque;
|
int tmpfd(void) libcesque;
|
||||||
int touch(const char *, unsigned) libcesque;
|
int touch(const char *, unsigned) libcesque __read_only(1);
|
||||||
int unveil(const char *, const char *) libcesque;
|
int unveil(const char *, const char *) libcesque __read_only(1);
|
||||||
long ptrace(int, ...) libcesque;
|
long ptrace(int, ...) libcesque;
|
||||||
ssize_t copyfd(int, int, size_t) libcesque;
|
ssize_t copyfd(int, int, size_t) libcesque;
|
||||||
ssize_t readansi(int, char *, size_t) libcesque;
|
ssize_t readansi(int, char *, size_t) libcesque;
|
||||||
|
|
|
@ -18,13 +18,13 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/assert.h"
|
#include "libc/assert.h"
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/intrin/fds.h"
|
|
||||||
#include "libc/calls/syscall-sysv.internal.h"
|
#include "libc/calls/syscall-sysv.internal.h"
|
||||||
#include "libc/calls/syscall_support-nt.internal.h"
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
#include "libc/calls/termios.h"
|
#include "libc/calls/termios.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/errno.h"
|
#include "libc/errno.h"
|
||||||
#include "libc/intrin/cmpxchg.h"
|
#include "libc/intrin/cmpxchg.h"
|
||||||
|
#include "libc/intrin/fds.h"
|
||||||
#include "libc/intrin/strace.h"
|
#include "libc/intrin/strace.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
|
@ -258,7 +258,10 @@ static textwindows struct HostAdapterInfoNode *appendHostInfo(
|
||||||
node->flags = flags;
|
node->flags = flags;
|
||||||
} else {
|
} else {
|
||||||
/* Copy from previous node */
|
/* Copy from previous node */
|
||||||
node->flags = parentInfoNode->flags;
|
if (parentInfoNode)
|
||||||
|
node->flags = parentInfoNode->flags;
|
||||||
|
else
|
||||||
|
node->flags = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ip = ntohl(
|
ip = ntohl(
|
||||||
|
@ -508,6 +511,7 @@ static int ioctl_siocgifconf_sysv(int fd, struct ifconf *ifc) {
|
||||||
}
|
}
|
||||||
#pragma GCC push_options
|
#pragma GCC push_options
|
||||||
#pragma GCC diagnostic ignored "-Walloca-larger-than="
|
#pragma GCC diagnostic ignored "-Walloca-larger-than="
|
||||||
|
#pragma GCC diagnostic ignored "-Wanalyzer-out-of-bounds"
|
||||||
bufMax = 15000; /* conservative guesstimate */
|
bufMax = 15000; /* conservative guesstimate */
|
||||||
b = alloca(bufMax);
|
b = alloca(bufMax);
|
||||||
CheckLargeStackAllocation(b, bufMax);
|
CheckLargeStackAllocation(b, bufMax);
|
||||||
|
|
|
@ -144,6 +144,7 @@ textwindows int mkntenvblock(char16_t envblock[32767], char *const envp[],
|
||||||
n = (CountStrings(envp) + CountStrings(extravars) + 1) * sizeof(char *);
|
n = (CountStrings(envp) + CountStrings(extravars) + 1) * sizeof(char *);
|
||||||
#pragma GCC push_options
|
#pragma GCC push_options
|
||||||
#pragma GCC diagnostic ignored "-Walloca-larger-than="
|
#pragma GCC diagnostic ignored "-Walloca-larger-than="
|
||||||
|
#pragma GCC diagnostic ignored "-Wanalyzer-out-of-bounds"
|
||||||
env.var = alloca(n);
|
env.var = alloca(n);
|
||||||
CheckLargeStackAllocation(env.var, n);
|
CheckLargeStackAllocation(env.var, n);
|
||||||
#pragma GCC pop_options
|
#pragma GCC pop_options
|
||||||
|
|
|
@ -60,6 +60,7 @@ static ssize_t Preadv(int fd, struct iovec *iov, int iovlen, int64_t off) {
|
||||||
struct iovec *iov2;
|
struct iovec *iov2;
|
||||||
#pragma GCC push_options
|
#pragma GCC push_options
|
||||||
#pragma GCC diagnostic ignored "-Walloca-larger-than="
|
#pragma GCC diagnostic ignored "-Walloca-larger-than="
|
||||||
|
#pragma GCC diagnostic ignored "-Wanalyzer-out-of-bounds"
|
||||||
iov2 = alloca(iovlen * sizeof(struct iovec));
|
iov2 = alloca(iovlen * sizeof(struct iovec));
|
||||||
CheckLargeStackAllocation(iov2, iovlen * sizeof(struct iovec));
|
CheckLargeStackAllocation(iov2, iovlen * sizeof(struct iovec));
|
||||||
#pragma GCC pop_options
|
#pragma GCC pop_options
|
||||||
|
|
|
@ -62,6 +62,7 @@ static ssize_t Pwritev(int fd, const struct iovec *iov, int iovlen,
|
||||||
struct iovec *iov2;
|
struct iovec *iov2;
|
||||||
#pragma GCC push_options
|
#pragma GCC push_options
|
||||||
#pragma GCC diagnostic ignored "-Walloca-larger-than="
|
#pragma GCC diagnostic ignored "-Walloca-larger-than="
|
||||||
|
#pragma GCC diagnostic ignored "-Wanalyzer-out-of-bounds"
|
||||||
iov2 = alloca(iovlen * sizeof(struct iovec));
|
iov2 = alloca(iovlen * sizeof(struct iovec));
|
||||||
CheckLargeStackAllocation(iov2, iovlen * sizeof(struct iovec));
|
CheckLargeStackAllocation(iov2, iovlen * sizeof(struct iovec));
|
||||||
#pragma GCC pop_options
|
#pragma GCC pop_options
|
||||||
|
|
|
@ -52,6 +52,7 @@ static textwindows ssize_t sys_readlinkat_nt_impl(int dirfd, const char *path,
|
||||||
ssize_t rc;
|
ssize_t rc;
|
||||||
#pragma GCC push_options
|
#pragma GCC push_options
|
||||||
#pragma GCC diagnostic ignored "-Walloca-larger-than="
|
#pragma GCC diagnostic ignored "-Walloca-larger-than="
|
||||||
|
#pragma GCC diagnostic ignored "-Wanalyzer-out-of-bounds"
|
||||||
uint32_t mem = 6000;
|
uint32_t mem = 6000;
|
||||||
volatile char *memory = alloca(mem);
|
volatile char *memory = alloca(mem);
|
||||||
CheckLargeStackAllocation((char *)memory, mem);
|
CheckLargeStackAllocation((char *)memory, mem);
|
||||||
|
|
|
@ -57,6 +57,7 @@ static ssize_t readv_impl(int fd, const struct iovec *iov, int iovlen) {
|
||||||
struct iovec *iov2;
|
struct iovec *iov2;
|
||||||
#pragma GCC push_options
|
#pragma GCC push_options
|
||||||
#pragma GCC diagnostic ignored "-Walloca-larger-than="
|
#pragma GCC diagnostic ignored "-Walloca-larger-than="
|
||||||
|
#pragma GCC diagnostic ignored "-Wanalyzer-out-of-bounds"
|
||||||
iov2 = alloca(iovlen * sizeof(struct iovec));
|
iov2 = alloca(iovlen * sizeof(struct iovec));
|
||||||
CheckLargeStackAllocation(iov2, iovlen * sizeof(struct iovec));
|
CheckLargeStackAllocation(iov2, iovlen * sizeof(struct iovec));
|
||||||
#pragma GCC pop_options
|
#pragma GCC pop_options
|
||||||
|
|
|
@ -62,6 +62,7 @@ ssize_t tinyprint(int fd, const char *s, ...) {
|
||||||
buf[n++] = c;
|
buf[n++] = c;
|
||||||
if (n == sizeof(buf)) {
|
if (n == sizeof(buf)) {
|
||||||
if (tinyflush(fd, buf, n, &toto)) {
|
if (tinyflush(fd, buf, n, &toto)) {
|
||||||
|
va_end(va);
|
||||||
return toto;
|
return toto;
|
||||||
}
|
}
|
||||||
n = 0;
|
n = 0;
|
||||||
|
|
|
@ -168,8 +168,8 @@ struct ucontext {
|
||||||
|
|
||||||
typedef struct ucontext ucontext_t;
|
typedef struct ucontext ucontext_t;
|
||||||
|
|
||||||
int getcontext(ucontext_t *) dontthrow;
|
int getcontext(ucontext_t *) dontthrow __read_write(1);
|
||||||
int setcontext(const ucontext_t *) dontthrow;
|
int setcontext(const ucontext_t *) dontthrow __read_only(1);
|
||||||
int swapcontext(ucontext_t *, const ucontext_t *) dontthrow returnstwice;
|
int swapcontext(ucontext_t *, const ucontext_t *) dontthrow returnstwice;
|
||||||
void makecontext(ucontext_t *, void *, int, ...) dontthrow dontcallback;
|
void makecontext(ucontext_t *, void *, int, ...) dontthrow dontcallback;
|
||||||
void __sig_restore(const ucontext_t *) wontreturn;
|
void __sig_restore(const ucontext_t *) wontreturn;
|
||||||
|
|
|
@ -57,6 +57,7 @@ static ssize_t writev_impl(int fd, const struct iovec *iov, int iovlen) {
|
||||||
struct iovec *iov2;
|
struct iovec *iov2;
|
||||||
#pragma GCC push_options
|
#pragma GCC push_options
|
||||||
#pragma GCC diagnostic ignored "-Walloca-larger-than="
|
#pragma GCC diagnostic ignored "-Walloca-larger-than="
|
||||||
|
#pragma GCC diagnostic ignored "-Wanalyzer-out-of-bounds"
|
||||||
iov2 = alloca(iovlen * sizeof(struct iovec));
|
iov2 = alloca(iovlen * sizeof(struct iovec));
|
||||||
CheckLargeStackAllocation(iov2, iovlen * sizeof(struct iovec));
|
CheckLargeStackAllocation(iov2, iovlen * sizeof(struct iovec));
|
||||||
#pragma GCC pop_options
|
#pragma GCC pop_options
|
||||||
|
|
|
@ -367,6 +367,24 @@ typedef struct {
|
||||||
|
|
||||||
#define offsetof(type, member) __builtin_offsetof(type, member)
|
#define offsetof(type, member) __builtin_offsetof(type, member)
|
||||||
|
|
||||||
|
#if defined(__GNUC__) && __GNUC__ >= 10
|
||||||
|
#define __read_only(...) __attribute__((__access__(__read_only__, __VA_ARGS__)))
|
||||||
|
#define __write_only(...) \
|
||||||
|
__attribute__((__access__(__write_only__, __VA_ARGS__)))
|
||||||
|
#define __read_write(...) \
|
||||||
|
__attribute__((__access__(__read_write__, __VA_ARGS__)))
|
||||||
|
#else
|
||||||
|
#define __read_only(...)
|
||||||
|
#define __write_only(...)
|
||||||
|
#define __read_write(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__GNUC__) && __GNUC__ >= 13
|
||||||
|
#define __fd_arg(N) __attribute__((__fd_arg__(N)))
|
||||||
|
#else
|
||||||
|
#define __fd_arg(N)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _COSMO_SOURCE
|
#ifdef _COSMO_SOURCE
|
||||||
|
|
||||||
#ifndef dontinstrument
|
#ifndef dontinstrument
|
||||||
|
|
|
@ -29,6 +29,10 @@
|
||||||
#define TINYMALLOC_MAX_ALIGN sizeof(max_align_t)
|
#define TINYMALLOC_MAX_ALIGN sizeof(max_align_t)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#pragma GCC push_options
|
||||||
|
#pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak"
|
||||||
|
#pragma GCC diagnostic ignored "-Wanalyzer-use-after-free"
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
alignas(max_align_t) char bits[TINYMALLOC_MAX_BYTES];
|
alignas(max_align_t) char bits[TINYMALLOC_MAX_BYTES];
|
||||||
char *memory;
|
char *memory;
|
||||||
|
@ -178,3 +182,5 @@ OutOfMemory:
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma GCC pop_options
|
||||||
|
|
|
@ -4,6 +4,7 @@ COSMOPOLITAN_C_START_
|
||||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||||
│ cosmopolitan § runtime ─╬─│┼
|
│ cosmopolitan § runtime ─╬─│┼
|
||||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||||
|
/* clang-format off */
|
||||||
|
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
typedef long jmp_buf[8];
|
typedef long jmp_buf[8];
|
||||||
|
@ -22,11 +23,9 @@ typedef unsigned long jmp_buf[26];
|
||||||
void mcount(void) libcesque;
|
void mcount(void) libcesque;
|
||||||
int daemon(int, int) libcesque;
|
int daemon(int, int) libcesque;
|
||||||
unsigned long getauxval(unsigned long) libcesque;
|
unsigned long getauxval(unsigned long) libcesque;
|
||||||
int setjmp(jmp_buf)
|
int setjmp(jmp_buf) libcesque returnstwice paramsnonnull();
|
||||||
libcesque returnstwice paramsnonnull();
|
|
||||||
void longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
|
void longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
|
||||||
int _setjmp(jmp_buf)
|
int _setjmp(jmp_buf) libcesque returnstwice paramsnonnull();
|
||||||
libcesque returnstwice paramsnonnull();
|
|
||||||
int sigsetjmp(sigjmp_buf, int) libcesque returnstwice paramsnonnull();
|
int sigsetjmp(sigjmp_buf, int) libcesque returnstwice paramsnonnull();
|
||||||
void siglongjmp(sigjmp_buf, int) libcesque wontreturn paramsnonnull();
|
void siglongjmp(sigjmp_buf, int) libcesque wontreturn paramsnonnull();
|
||||||
void _longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
|
void _longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
|
||||||
|
@ -37,7 +36,7 @@ void quick_exit(int) wontreturn;
|
||||||
void abort(void) wontreturn;
|
void abort(void) wontreturn;
|
||||||
int atexit(void (*)(void)) paramsnonnull() libcesque;
|
int atexit(void (*)(void)) paramsnonnull() libcesque;
|
||||||
char *getenv(const char *) paramsnonnull() __wur nosideeffect libcesque;
|
char *getenv(const char *) paramsnonnull() __wur nosideeffect libcesque;
|
||||||
int putenv(char *) libcesque;
|
int putenv(char *) libcesque __read_write(1);
|
||||||
int setenv(const char *, const char *, int) libcesque;
|
int setenv(const char *, const char *, int) libcesque;
|
||||||
int unsetenv(const char *) libcesque;
|
int unsetenv(const char *) libcesque;
|
||||||
int clearenv(void) libcesque;
|
int clearenv(void) libcesque;
|
||||||
|
@ -52,8 +51,8 @@ int munlock(const void *, size_t) libcesque;
|
||||||
long gethostid(void) libcesque;
|
long gethostid(void) libcesque;
|
||||||
int sethostid(long) libcesque;
|
int sethostid(long) libcesque;
|
||||||
char *getlogin(void) libcesque;
|
char *getlogin(void) libcesque;
|
||||||
int getlogin_r(char *, size_t) libcesque;
|
int getlogin_r(char *, size_t) libcesque __write_only(1, 2);
|
||||||
int login_tty(int) libcesque;
|
int login_tty(int) libcesque __fd_arg(1);
|
||||||
int getpagesize(void) pureconst libcesque;
|
int getpagesize(void) pureconst libcesque;
|
||||||
int getgransize(void) pureconst libcesque;
|
int getgransize(void) pureconst libcesque;
|
||||||
int syncfs(int) dontthrow libcesque;
|
int syncfs(int) dontthrow libcesque;
|
||||||
|
@ -88,8 +87,8 @@ extern size_t __virtualsize;
|
||||||
extern size_t __stackmax;
|
extern size_t __stackmax;
|
||||||
extern bool32 __isworker;
|
extern bool32 __isworker;
|
||||||
/* utilities */
|
/* utilities */
|
||||||
void _intsort(int *, size_t) libcesque;
|
void _intsort(int *, size_t) libcesque __read_write(1, 2);
|
||||||
void _longsort(long *, size_t) libcesque;
|
void _longsort(long *, size_t) libcesque __read_write(1, 2);
|
||||||
/* diagnostics */
|
/* diagnostics */
|
||||||
void ShowCrashReports(void) libcesque;
|
void ShowCrashReports(void) libcesque;
|
||||||
int ftrace_install(void) libcesque;
|
int ftrace_install(void) libcesque;
|
||||||
|
@ -107,8 +106,8 @@ int __open_executable(void) libcesque;
|
||||||
int verynice(void) libcesque;
|
int verynice(void) libcesque;
|
||||||
void __warn_if_powersave(void) libcesque;
|
void __warn_if_powersave(void) libcesque;
|
||||||
void _Exit1(int) libcesque wontreturn libcesque;
|
void _Exit1(int) libcesque wontreturn libcesque;
|
||||||
void __paginate(int, const char *) libcesque;
|
void __paginate(int, const char *) libcesque __fd_arg(1);
|
||||||
void __paginate_file(int, const char *) libcesque;
|
void __paginate_file(int, const char *) libcesque __fd_arg(1);
|
||||||
/* memory management */
|
/* memory management */
|
||||||
void _weakfree(void *) libcesque;
|
void _weakfree(void *) libcesque;
|
||||||
void *_mapanon(size_t) attributeallocsize((1)) mallocesque libcesque;
|
void *_mapanon(size_t) attributeallocsize((1)) mallocesque libcesque;
|
||||||
|
|
|
@ -17,21 +17,22 @@ libcesque uint32_t ntohl(uint32_t) pureconst;
|
||||||
#define ntohl(x) __builtin_bswap32(x)
|
#define ntohl(x) __builtin_bswap32(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* clang-format off */
|
||||||
const char *inet_ntop(int, const void *, char *, uint32_t) libcesque;
|
const char *inet_ntop(int, const void *, char *, uint32_t) libcesque;
|
||||||
int inet_pton(int, const char *, void *) libcesque;
|
int inet_pton(int, const char *, void *) libcesque;
|
||||||
uint32_t inet_addr(const char *) libcesque;
|
uint32_t inet_addr(const char *) libcesque;
|
||||||
libcesque uint32_t *GetHostIps(void) __wur;
|
libcesque uint32_t *GetHostIps(void) __wur;
|
||||||
|
|
||||||
int socket(int, int, int) libcesque;
|
int socket(int, int, int) libcesque;
|
||||||
int listen(int, int) libcesque;
|
int listen(int, int) libcesque __fd_arg(1);
|
||||||
int shutdown(int, int) libcesque;
|
int shutdown(int, int) libcesque __fd_arg(1);
|
||||||
ssize_t send(int, const void *, size_t, int) libcesque;
|
ssize_t send(int, const void *, size_t, int) libcesque __fd_arg(1) __read_only(2, 3);
|
||||||
ssize_t recv(int, void *, size_t, int) libcesque;
|
ssize_t recv(int, void *, size_t, int) libcesque __fd_arg(1) __write_only(2, 3);
|
||||||
ssize_t sendfile(int, int, int64_t *, size_t) libcesque;
|
ssize_t sendfile(int, int, int64_t *, size_t) libcesque __fd_arg(1) __fd_arg(2) __read_write(3);
|
||||||
int getsockopt(int, int, int, void *, uint32_t *) libcesque;
|
int getsockopt(int, int, int, void *, uint32_t *) libcesque __fd_arg(1);
|
||||||
int setsockopt(int, int, int, const void *, uint32_t) libcesque;
|
int setsockopt(int, int, int, const void *, uint32_t) libcesque __fd_arg(1);
|
||||||
int socketpair(int, int, int, int[2]) libcesque;
|
int socketpair(int, int, int, int[2]) libcesque;
|
||||||
int sockatmark(int) libcesque;
|
int sockatmark(int) libcesque __fd_arg(1);
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
#endif /* COSMOPOLITAN_LIBC_SOCK_SOCK_H_ */
|
#endif /* COSMOPOLITAN_LIBC_SOCK_SOCK_H_ */
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "libc/assert.h"
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/stdio/internal.h"
|
#include "libc/stdio/internal.h"
|
||||||
#include "libc/stdio/stdio.h"
|
#include "libc/stdio/stdio.h"
|
||||||
|
@ -37,8 +38,8 @@
|
||||||
* @return stream object if successful, or NULL w/ errno
|
* @return stream object if successful, or NULL w/ errno
|
||||||
*/
|
*/
|
||||||
FILE *freopen(const char *pathname, const char *mode, FILE *stream) {
|
FILE *freopen(const char *pathname, const char *mode, FILE *stream) {
|
||||||
int fd;
|
|
||||||
FILE *res;
|
FILE *res;
|
||||||
|
int fd, fd2;
|
||||||
unsigned flags;
|
unsigned flags;
|
||||||
flags = fopenflags(mode);
|
flags = fopenflags(mode);
|
||||||
flockfile(stream);
|
flockfile(stream);
|
||||||
|
@ -46,19 +47,30 @@ FILE *freopen(const char *pathname, const char *mode, FILE *stream) {
|
||||||
if (pathname) {
|
if (pathname) {
|
||||||
/* open new stream, overwriting existing alloc */
|
/* open new stream, overwriting existing alloc */
|
||||||
if ((fd = open(pathname, flags, 0666)) != -1) {
|
if ((fd = open(pathname, flags, 0666)) != -1) {
|
||||||
dup3(fd, stream->fd, flags & O_CLOEXEC);
|
fd2 = dup3(fd, stream->fd, flags & O_CLOEXEC);
|
||||||
close(fd);
|
close(fd);
|
||||||
stream->iomode = flags;
|
if (fd2 != -1) {
|
||||||
stream->beg = 0;
|
stream->fd = fd2;
|
||||||
stream->end = 0;
|
stream->iomode = flags;
|
||||||
res = stream;
|
stream->beg = 0;
|
||||||
|
stream->end = 0;
|
||||||
|
res = stream;
|
||||||
|
} else {
|
||||||
|
res = NULL;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
res = NULL;
|
res = NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fcntl(stream->fd, F_SETFD, !!(flags & O_CLOEXEC));
|
#pragma GCC diagnostic push
|
||||||
fcntl(stream->fd, F_SETFL, flags & ~O_CLOEXEC);
|
#pragma GCC diagnostic ignored "-Wanalyzer-fd-use-without-check"
|
||||||
res = stream;
|
if (fcntl(stream->fd, F_SETFD, !!(flags & O_CLOEXEC)) != -1 &&
|
||||||
|
fcntl(stream->fd, F_SETFL, flags & ~O_CLOEXEC) != -1) {
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
res = stream;
|
||||||
|
} else {
|
||||||
|
res = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
funlockfile(stream);
|
funlockfile(stream);
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||||
│ vi: set noet ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||||
│ │
|
│ │
|
||||||
│ Musl Libc │
|
│ Musl Libc │
|
||||||
|
@ -334,6 +334,8 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
|
||||||
case UCS2:
|
case UCS2:
|
||||||
case UTF_16:
|
case UTF_16:
|
||||||
l = 0;
|
l = 0;
|
||||||
|
if (!scd)
|
||||||
|
goto starved;
|
||||||
if (!scd->state) {
|
if (!scd->state) {
|
||||||
if (*inb < 2) goto starved;
|
if (*inb < 2) goto starved;
|
||||||
c = get_16((void *)*in, 0);
|
c = get_16((void *)*in, 0);
|
||||||
|
@ -347,6 +349,8 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
|
||||||
continue;
|
continue;
|
||||||
case UTF_32:
|
case UTF_32:
|
||||||
l = 0;
|
l = 0;
|
||||||
|
if (!scd)
|
||||||
|
goto starved;
|
||||||
if (!scd->state) {
|
if (!scd->state) {
|
||||||
if (*inb < 4) goto starved;
|
if (*inb < 4) goto starved;
|
||||||
c = get_32((void *)*in, 0);
|
c = get_32((void *)*in, 0);
|
||||||
|
@ -398,6 +402,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
|
||||||
if (!c) goto ilseq;
|
if (!c) goto ilseq;
|
||||||
break;
|
break;
|
||||||
case ISO2022_JP:
|
case ISO2022_JP:
|
||||||
|
if (!scd) goto starved;
|
||||||
if (c >= 128) goto ilseq;
|
if (c >= 128) goto ilseq;
|
||||||
if (c == '\033') {
|
if (c == '\033') {
|
||||||
l = 3;
|
l = 3;
|
||||||
|
|
|
@ -102,15 +102,24 @@ static int do_nftw(char *path,
|
||||||
dfd = open(path, O_RDONLY | O_DIRECTORY);
|
dfd = open(path, O_RDONLY | O_DIRECTORY);
|
||||||
err = errno;
|
err = errno;
|
||||||
if (dfd < 0 && err == EACCES) type = FTW_DNR;
|
if (dfd < 0 && err == EACCES) type = FTW_DNR;
|
||||||
if (!fd_limit) close(dfd);
|
if (!fd_limit) {
|
||||||
|
close(dfd);
|
||||||
|
dfd = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev)))
|
if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) {
|
||||||
|
if (dfd != -1)
|
||||||
|
close(dfd);
|
||||||
return r;
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
for (; h; h = h->chain)
|
for (; h; h = h->chain)
|
||||||
if (h->dev == st.st_dev && h->ino == st.st_ino)
|
if (h->dev == st.st_dev && h->ino == st.st_ino) {
|
||||||
|
if (dfd != -1)
|
||||||
|
close(dfd);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ((type == FTW_D || type == FTW_DP) && fd_limit) {
|
if ((type == FTW_D || type == FTW_DP) && fd_limit) {
|
||||||
if (dfd < 0) {
|
if (dfd < 0) {
|
||||||
|
|
|
@ -75,7 +75,10 @@ FILE *popen(const char *cmdline, const char *mode) {
|
||||||
if ((f = fdopen(pipefds[dir], mode))) {
|
if ((f = fdopen(pipefds[dir], mode))) {
|
||||||
switch ((pid = fork())) {
|
switch ((pid = fork())) {
|
||||||
case 0:
|
case 0:
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wanalyzer-fd-leak"
|
||||||
unassert(dup2(pipefds[!dir], !dir) == !dir);
|
unassert(dup2(pipefds[!dir], !dir) == !dir);
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
// we can't rely on cloexec because cocmd builtins don't execve
|
// we can't rely on cloexec because cocmd builtins don't execve
|
||||||
if (pipefds[0] != !dir)
|
if (pipefds[0] != !dir)
|
||||||
unassert(!close(pipefds[0]));
|
unassert(!close(pipefds[0]));
|
||||||
|
|
|
@ -69,7 +69,9 @@ int scandir(const char *path, struct dirent ***res,
|
||||||
}
|
}
|
||||||
errno = old_errno;
|
errno = old_errno;
|
||||||
|
|
||||||
if (cmp) qsort(names, cnt, sizeof *names, (int (*)(const void *, const void *))cmp);
|
if (cmp && names) {
|
||||||
|
qsort(names, cnt, sizeof *names, (int (*)(const void *, const void *))cmp);
|
||||||
|
}
|
||||||
*res = names;
|
*res = names;
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ COSMOPOLITAN_C_START_
|
||||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||||
│ cosmopolitan § standard i/o ─╬─│┼
|
│ cosmopolitan § standard i/o ─╬─│┼
|
||||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||||
|
/* clang-format off */
|
||||||
|
|
||||||
struct FILE;
|
struct FILE;
|
||||||
typedef struct FILE FILE;
|
typedef struct FILE FILE;
|
||||||
|
@ -27,147 +28,146 @@ extern FILE *stdin;
|
||||||
extern FILE *stdout;
|
extern FILE *stdout;
|
||||||
extern FILE *stderr;
|
extern FILE *stderr;
|
||||||
|
|
||||||
errno_t ferror(FILE *) libcesque paramsnonnull();
|
errno_t ferror(FILE *) libcesque paramsnonnull() __read_write(1);
|
||||||
void clearerr(FILE *) libcesque paramsnonnull();
|
void clearerr(FILE *) libcesque paramsnonnull() __read_write(1);
|
||||||
int feof(FILE *) libcesque paramsnonnull();
|
int feof(FILE *) libcesque paramsnonnull() __read_write(1);
|
||||||
int getc(FILE *) libcesque paramsnonnull();
|
int getc(FILE *) libcesque paramsnonnull() __read_write(1);
|
||||||
int putc(int, FILE *) libcesque paramsnonnull();
|
int putc(int, FILE *) libcesque paramsnonnull() __read_write(2);
|
||||||
int fflush(FILE *) libcesque;
|
int fflush(FILE *) libcesque __read_write(1);
|
||||||
int fpurge(FILE *) libcesque;
|
int fpurge(FILE *) libcesque __read_write(1);
|
||||||
int fgetc(FILE *) libcesque paramsnonnull();
|
int fgetc(FILE *) libcesque paramsnonnull() __read_write(1);
|
||||||
char *fgetln(FILE *, size_t *) libcesque paramsnonnull((1));
|
char *fgetln(FILE *, size_t *) libcesque paramsnonnull((1)) __read_write(1) __write_only(2);
|
||||||
int ungetc(int, FILE *) libcesque paramsnonnull();
|
int ungetc(int, FILE *) libcesque paramsnonnull() __write_only(2);
|
||||||
int fileno(FILE *) libcesque paramsnonnull() nosideeffect;
|
int fileno(FILE *) libcesque paramsnonnull() nosideeffect __write_only(1);
|
||||||
int fputc(int, FILE *) libcesque paramsnonnull();
|
int fputc(int, FILE *) libcesque paramsnonnull() __write_only(2);
|
||||||
int fputs(const char *, FILE *) libcesque paramsnonnull();
|
int fputs(const char *, FILE *) libcesque paramsnonnull() __write_only(2);
|
||||||
int fputws(const wchar_t *, FILE *) libcesque paramsnonnull();
|
int fputws(const wchar_t *, FILE *) libcesque paramsnonnull() __write_only(2);
|
||||||
void flockfile(FILE *) libcesque;
|
void flockfile(FILE *) libcesque __write_only(1);
|
||||||
void funlockfile(FILE *) libcesque paramsnonnull();
|
void funlockfile(FILE *) libcesque paramsnonnull() __write_only(1);
|
||||||
int ftrylockfile(FILE *) libcesque paramsnonnull();
|
int ftrylockfile(FILE *) libcesque paramsnonnull() __write_only(1);
|
||||||
char *fgets(char *, int, FILE *) libcesque paramsnonnull();
|
char *fgets(char *, int, FILE *) libcesque paramsnonnull() __write_only(1, 2) __read_write(3);
|
||||||
wchar_t *fgetws(wchar_t *, int, FILE *) libcesque paramsnonnull();
|
wchar_t *fgetws(wchar_t *, int, FILE *) libcesque paramsnonnull() __write_only(1, 2) __read_write(3);
|
||||||
wint_t putwc(wchar_t, FILE *) libcesque paramsnonnull();
|
wint_t putwc(wchar_t, FILE *) libcesque paramsnonnull() __write_only(2);
|
||||||
wint_t fputwc(wchar_t, FILE *) libcesque paramsnonnull();
|
wint_t fputwc(wchar_t, FILE *) libcesque paramsnonnull() __write_only(2);
|
||||||
wint_t putwchar(wchar_t) libcesque;
|
wint_t putwchar(wchar_t) libcesque;
|
||||||
wint_t getwchar(void) libcesque;
|
wint_t getwchar(void) libcesque;
|
||||||
wint_t getwc(FILE *) libcesque paramsnonnull();
|
wint_t getwc(FILE *) libcesque paramsnonnull() __write_only(1);
|
||||||
wint_t fgetwc(FILE *) libcesque paramsnonnull();
|
wint_t fgetwc(FILE *) libcesque paramsnonnull() __write_only(1);
|
||||||
wint_t ungetwc(wint_t, FILE *) libcesque paramsnonnull();
|
wint_t ungetwc(wint_t, FILE *) libcesque paramsnonnull() __write_only(2);
|
||||||
int getchar(void) libcesque;
|
int getchar(void) libcesque;
|
||||||
int putchar(int) libcesque;
|
int putchar(int) libcesque;
|
||||||
int puts(const char *) libcesque;
|
int puts(const char *) libcesque __read_only(1);
|
||||||
ssize_t getline(char **, size_t *, FILE *) libcesque paramsnonnull();
|
|
||||||
ssize_t getdelim(char **, size_t *, int, FILE *) libcesque paramsnonnull();
|
ssize_t getline(char **, size_t *, FILE *) libcesque paramsnonnull() __read_write(1) __read_write(2) __read_write(3);
|
||||||
FILE *fopen(const char *, const char *) libcesque paramsnonnull((2)) __wur;
|
ssize_t getdelim(char **, size_t *, int, FILE *) libcesque paramsnonnull() __read_write(1) __read_write(2) __read_write(4);
|
||||||
FILE *fdopen(int, const char *) libcesque paramsnonnull() __wur;
|
FILE *fopen(const char *, const char *) libcesque paramsnonnull((2)) __read_only(1) __read_only(2) __wur;
|
||||||
FILE *fmemopen(void *, size_t, const char *) libcesque paramsnonnull((3)) __wur;
|
FILE *fdopen(int, const char *) libcesque paramsnonnull() __read_only(2) __wur;
|
||||||
FILE *freopen(const char *, const char *, FILE *) paramsnonnull((2, 3));
|
FILE *fmemopen(void *, size_t, const char *) libcesque paramsnonnull((3)) __read_write(1) __read_only(3) __wur;
|
||||||
size_t fread(void *, size_t, size_t, FILE *) libcesque paramsnonnull((4));
|
FILE *freopen(const char *, const char *, FILE *) paramsnonnull((2, 3)) __read_only(1) __read_only(2) __read_write(3);
|
||||||
size_t fwrite(const void *, size_t, size_t, FILE *) paramsnonnull((4));
|
size_t fread(void *, size_t, size_t, FILE *) libcesque paramsnonnull((4)) __write_only(1) __read_write(4);
|
||||||
int fclose(FILE *) libcesque;
|
size_t fwrite(const void *, size_t, size_t, FILE *) paramsnonnull((4)) __read_only(1) __read_write(4);
|
||||||
int fseek(FILE *, long, int) libcesque paramsnonnull();
|
int fclose(FILE *) libcesque __read_write(1);
|
||||||
long ftell(FILE *) libcesque paramsnonnull();
|
int fseek(FILE *, long, int) libcesque paramsnonnull() __read_write(1);
|
||||||
int fseeko(FILE *, int64_t, int) libcesque paramsnonnull();
|
long ftell(FILE *) libcesque paramsnonnull() __read_write(1);
|
||||||
int64_t ftello(FILE *) libcesque paramsnonnull();
|
int fseeko(FILE *, int64_t, int) libcesque paramsnonnull() __read_write(1);
|
||||||
void rewind(FILE *) libcesque paramsnonnull();
|
int64_t ftello(FILE *) libcesque paramsnonnull() __read_write(1);
|
||||||
int fopenflags(const char *) libcesque paramsnonnull();
|
void rewind(FILE *) libcesque paramsnonnull() __read_write(1);
|
||||||
void setlinebuf(FILE *) libcesque;
|
int fopenflags(const char *) libcesque paramsnonnull() __read_only(1);
|
||||||
void setbuf(FILE *, char *) libcesque;
|
void setlinebuf(FILE *) libcesque __read_write(1);
|
||||||
void setbuffer(FILE *, char *, size_t) libcesque;
|
void setbuf(FILE *, char *) libcesque __read_write(1) __write_only(2);
|
||||||
int setvbuf(FILE *, char *, int, size_t) libcesque;
|
void setbuffer(FILE *, char *, size_t) libcesque __read_write(1) __write_only(2);
|
||||||
int pclose(FILE *) libcesque;
|
int setvbuf(FILE *, char *, int, size_t) libcesque __read_write(1);
|
||||||
char *ctermid(char *) libcesque;
|
int pclose(FILE *) libcesque __read_write(1);
|
||||||
void perror(const char *) libcesque relegated;
|
char *ctermid(char *) libcesque __write_only(1);
|
||||||
|
void perror(const char *) libcesque relegated __read_only(1);
|
||||||
|
|
||||||
typedef uint64_t fpos_t;
|
typedef uint64_t fpos_t;
|
||||||
char *gets(char *) libcesque paramsnonnull();
|
char *gets(char *) libcesque paramsnonnull() __write_only(1);
|
||||||
int fgetpos(FILE *, fpos_t *) libcesque paramsnonnull();
|
int fgetpos(FILE *, fpos_t *) libcesque paramsnonnull() __read_write(1) __write_only(2);
|
||||||
int fsetpos(FILE *, const fpos_t *) libcesque paramsnonnull();
|
int fsetpos(FILE *, const fpos_t *) libcesque paramsnonnull() __read_write(1) __read_only(2);
|
||||||
|
|
||||||
FILE *tmpfile(void) libcesque __wur;
|
FILE *tmpfile(void) libcesque __wur;
|
||||||
char *tmpnam(char *) libcesque __wur;
|
char *tmpnam(char *) libcesque __write_only(1) __wur;
|
||||||
char *tmpnam_r(char *) libcesque __wur;
|
char *tmpnam_r(char *) libcesque __write_only(1) __wur;
|
||||||
|
|
||||||
FILE *popen(const char *, const char *) libcesque;
|
FILE *popen(const char *, const char *) libcesque __read_only(1) __read_only(2);
|
||||||
|
|
||||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||||
│ cosmopolitan § standard i/o » formatting ─╬─│┼
|
│ cosmopolitan § standard i/o » formatting ─╬─│┼
|
||||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||||
|
|
||||||
int printf(const char *, ...) printfesque(1) paramsnonnull((1)) libcesque;
|
int printf(const char *, ...) printfesque(1) paramsnonnull((1)) libcesque __read_only(1);
|
||||||
int vprintf(const char *, va_list) paramsnonnull() libcesque;
|
int vprintf(const char *, va_list) paramsnonnull() libcesque __read_only(1);
|
||||||
int fprintf(FILE *, const char *, ...) printfesque(2)
|
int fprintf(FILE *, const char *, ...) printfesque(2) paramsnonnull((1, 2)) libcesque __read_write(1) __read_only(2);
|
||||||
paramsnonnull((1, 2)) libcesque;
|
int vfprintf(FILE *, const char *, va_list) paramsnonnull() libcesque __read_write(1) __read_only(2);
|
||||||
int vfprintf(FILE *, const char *, va_list) paramsnonnull() libcesque;
|
int scanf(const char *, ...) libcesque scanfesque(1) __read_only(1);
|
||||||
int scanf(const char *, ...) libcesque scanfesque(1);
|
int vscanf(const char *, va_list) libcesque __read_only(1);
|
||||||
int vscanf(const char *, va_list) libcesque;
|
int fscanf(FILE *, const char *, ...) libcesque scanfesque(2) __read_write(1) __read_only(2);
|
||||||
int fscanf(FILE *, const char *, ...) libcesque scanfesque(2);
|
int vfscanf(FILE *, const char *, va_list) libcesque __read_write(1) __read_only(2);
|
||||||
int vfscanf(FILE *, const char *, va_list) libcesque;
|
|
||||||
|
|
||||||
int snprintf(char *, size_t, const char *, ...) printfesque(3) libcesque;
|
int snprintf(char *, size_t, const char *, ...) printfesque(3) libcesque __write_only(1) __read_only(3);
|
||||||
int vsnprintf(char *, size_t, const char *, va_list) libcesque;
|
int vsnprintf(char *, size_t, const char *, va_list) libcesque __write_only(1) __read_only(3);
|
||||||
int sprintf(char *, const char *, ...) libcesque;
|
int sprintf(char *, const char *, ...) libcesque __write_only(1) __read_only(2);
|
||||||
int vsprintf(char *, const char *, va_list) libcesque;
|
int vsprintf(char *, const char *, va_list) libcesque __write_only(1) __read_only(2);
|
||||||
|
|
||||||
int fwprintf(FILE *, const wchar_t *, ...) libcesque;
|
int fwprintf(FILE *, const wchar_t *, ...) libcesque __read_write(1) __read_only(2);
|
||||||
int fwscanf(FILE *, const wchar_t *, ...) libcesque;
|
int fwscanf(FILE *, const wchar_t *, ...) libcesque __read_write(1) __read_only(2);
|
||||||
int swprintf(wchar_t *, size_t, const wchar_t *, ...) libcesque;
|
int swprintf(wchar_t *, size_t, const wchar_t *, ...) libcesque __write_only(1) __read_only(3);
|
||||||
int swscanf(const wchar_t *, const wchar_t *, ...) libcesque;
|
int swscanf(const wchar_t *, const wchar_t *, ...) libcesque __read_only(1) __read_only(2);
|
||||||
int vfwprintf(FILE *, const wchar_t *, va_list) libcesque;
|
int vfwprintf(FILE *, const wchar_t *, va_list) libcesque __read_write(1) __read_only(2);
|
||||||
int vfwscanf(FILE *, const wchar_t *, va_list) libcesque;
|
int vfwscanf(FILE *, const wchar_t *, va_list) libcesque __read_write(1) __read_only(2);
|
||||||
int vswprintf(wchar_t *, size_t, const wchar_t *, va_list) libcesque;
|
int vswprintf(wchar_t *, size_t, const wchar_t *, va_list) libcesque __write_only(1) __read_only(3);
|
||||||
int vswscanf(const wchar_t *, const wchar_t *, va_list) libcesque;
|
int vswscanf(const wchar_t *, const wchar_t *, va_list) libcesque __read_only(1) __read_only(2);
|
||||||
int vwprintf(const wchar_t *, va_list) libcesque;
|
int vwprintf(const wchar_t *, va_list) libcesque __read_only(1);
|
||||||
int vwscanf(const wchar_t *, va_list) libcesque;
|
int vwscanf(const wchar_t *, va_list) libcesque __read_only(1);
|
||||||
int wprintf(const wchar_t *, ...) libcesque;
|
int wprintf(const wchar_t *, ...) libcesque __read_only(1);
|
||||||
int wscanf(const wchar_t *, ...) libcesque;
|
int wscanf(const wchar_t *, ...) libcesque __read_only(1);
|
||||||
int fwide(FILE *, int) libcesque;
|
int fwide(FILE *, int) libcesque __read_write(1);
|
||||||
|
|
||||||
int sscanf(const char *, const char *, ...) libcesque scanfesque(2);
|
int sscanf(const char *, const char *, ...) libcesque scanfesque(2) __read_only(1) __read_only(2);
|
||||||
int vsscanf(const char *, const char *, va_list) libcesque;
|
int vsscanf(const char *, const char *, va_list) libcesque __read_only(1) __read_only(2);
|
||||||
|
|
||||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||||
│ cosmopolitan § standard i/o » allocating ─╬─│┼
|
│ cosmopolitan § standard i/o » allocating ─╬─│┼
|
||||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||||
|
|
||||||
int asprintf(char **, const char *, ...) printfesque(2)
|
int asprintf(char **, const char *, ...) printfesque(2) paramsnonnull((1, 2)) libcesque __write_only(1);
|
||||||
paramsnonnull((1, 2)) libcesque;
|
int vasprintf(char **, const char *, va_list) paramsnonnull() libcesque __write_only(1);
|
||||||
int vasprintf(char **, const char *, va_list) paramsnonnull() libcesque;
|
|
||||||
|
|
||||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||||
│ cosmopolitan § standard i/o » without mutexes ─╬─│┼
|
│ cosmopolitan § standard i/o » without mutexes ─╬─│┼
|
||||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||||
|
|
||||||
int getc_unlocked(FILE *) libcesque paramsnonnull();
|
int getc_unlocked(FILE *) libcesque paramsnonnull() __read_write(1);
|
||||||
int puts_unlocked(const char *) libcesque;
|
int puts_unlocked(const char *) libcesque __read_only(1);
|
||||||
int getchar_unlocked(void) libcesque;
|
int getchar_unlocked(void) libcesque;
|
||||||
int putc_unlocked(int, FILE *) libcesque paramsnonnull();
|
int putc_unlocked(int, FILE *) libcesque paramsnonnull() __read_write(2);
|
||||||
int putchar_unlocked(int) libcesque;
|
int putchar_unlocked(int) libcesque;
|
||||||
void clearerr_unlocked(FILE *) libcesque;
|
void clearerr_unlocked(FILE *) libcesque __write_only(1);
|
||||||
int feof_unlocked(FILE *) libcesque;
|
int feof_unlocked(FILE *) libcesque __read_only(1);
|
||||||
int ferror_unlocked(FILE *) libcesque;
|
int ferror_unlocked(FILE *) libcesque __read_only(1);
|
||||||
int fileno_unlocked(FILE *) libcesque;
|
int fileno_unlocked(FILE *) libcesque __read_only(1);
|
||||||
int fflush_unlocked(FILE *) libcesque;
|
int fflush_unlocked(FILE *) libcesque __read_write(1);
|
||||||
int fgetc_unlocked(FILE *) libcesque;
|
int fgetc_unlocked(FILE *) libcesque __read_write(1);
|
||||||
int fputc_unlocked(int, FILE *) libcesque;
|
int fputc_unlocked(int, FILE *) libcesque __read_write(2);
|
||||||
size_t fread_unlocked(void *, size_t, size_t, FILE *) libcesque;
|
size_t fread_unlocked(void *, size_t, size_t, FILE *) libcesque __write_only(1) __read_write(4);
|
||||||
size_t fwrite_unlocked(const void *, size_t, size_t, FILE *) libcesque;
|
size_t fwrite_unlocked(const void *, size_t, size_t, FILE *) libcesque __read_only(1) __read_write(4);
|
||||||
char *fgets_unlocked(char *, int, FILE *) libcesque;
|
char *fgets_unlocked(char *, int, FILE *) libcesque __write_only(1) __read_write(3);
|
||||||
int fputs_unlocked(const char *, FILE *) libcesque;
|
int fputs_unlocked(const char *, FILE *) libcesque __read_only(1) __read_write(2);
|
||||||
wint_t getwc_unlocked(FILE *) libcesque;
|
wint_t getwc_unlocked(FILE *) libcesque __read_write(1);
|
||||||
wint_t getwchar_unlocked(void) libcesque;
|
wint_t getwchar_unlocked(void) libcesque;
|
||||||
wint_t fgetwc_unlocked(FILE *) libcesque;
|
wint_t fgetwc_unlocked(FILE *) libcesque __read_write(1);
|
||||||
wint_t fputwc_unlocked(wchar_t, FILE *) libcesque;
|
wint_t fputwc_unlocked(wchar_t, FILE *) libcesque __read_write(2);
|
||||||
wint_t putwc_unlocked(wchar_t, FILE *) libcesque;
|
wint_t putwc_unlocked(wchar_t, FILE *) libcesque __read_write(2);
|
||||||
wint_t putwchar_unlocked(wchar_t) libcesque;
|
wint_t putwchar_unlocked(wchar_t) libcesque;
|
||||||
wchar_t *fgetws_unlocked(wchar_t *, int, FILE *) libcesque;
|
wchar_t *fgetws_unlocked(wchar_t *, int, FILE *) libcesque __write_only(1, 2) __read_write(3);
|
||||||
int fputws_unlocked(const wchar_t *, FILE *) libcesque;
|
int fputws_unlocked(const wchar_t *, FILE *) libcesque __read_only(1) __read_write(2);
|
||||||
wint_t ungetwc_unlocked(wint_t, FILE *) libcesque paramsnonnull();
|
wint_t ungetwc_unlocked(wint_t, FILE *) libcesque paramsnonnull() __read_write(2);
|
||||||
int ungetc_unlocked(int, FILE *) libcesque paramsnonnull();
|
int ungetc_unlocked(int, FILE *) libcesque paramsnonnull() __read_write(2);
|
||||||
int fseek_unlocked(FILE *, int64_t, int) libcesque paramsnonnull();
|
int fseek_unlocked(FILE *, int64_t, int) libcesque paramsnonnull() __read_write(1);
|
||||||
ssize_t getdelim_unlocked(char **, size_t *, int, FILE *) paramsnonnull();
|
ssize_t getdelim_unlocked(char **, size_t *, int, FILE *) paramsnonnull() __read_write(1) __read_write(2) __read_write(4);
|
||||||
int fprintf_unlocked(FILE *, const char *, ...) printfesque(2) libcesque;
|
int fprintf_unlocked(FILE *, const char *, ...) printfesque(2) libcesque __read_write(1) __read_only(2);
|
||||||
int vfprintf_unlocked(FILE *, const char *, va_list) paramsnonnull() libcesque;
|
int vfprintf_unlocked(FILE *, const char *, va_list) paramsnonnull() libcesque __read_write(1) __read_only(2);
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
#endif /* COSMOPOLITAN_LIBC_STDIO_H_ */
|
#endif /* COSMOPOLITAN_LIBC_STDIO_H_ */
|
||||||
|
|
|
@ -52,6 +52,7 @@ int vasprintf(char **strp, const char *fmt, va_list va) {
|
||||||
*strp = p;
|
*strp = p;
|
||||||
return rc;
|
return rc;
|
||||||
} else {
|
} else {
|
||||||
|
free(p);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,11 +254,15 @@ int __vcscanf(int callback(void *), //
|
||||||
c = READ;
|
c = READ;
|
||||||
}
|
}
|
||||||
fpbufsize = FP_BUFFER_GROW;
|
fpbufsize = FP_BUFFER_GROW;
|
||||||
fpbuf = malloc(fpbufsize);
|
if ((fpbuf = malloc(fpbufsize))) {
|
||||||
fpbufcur = 0;
|
fpbufcur = 0;
|
||||||
fpbuf[fpbufcur++] = c;
|
fpbuf[fpbufcur++] = c;
|
||||||
fpbuf[fpbufcur] = '\0';
|
fpbuf[fpbufcur] = '\0';
|
||||||
goto ConsumeFloatingPointNumber;
|
goto ConsumeFloatingPointNumber;
|
||||||
|
} else {
|
||||||
|
items = -1;
|
||||||
|
goto Done;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
items = einval();
|
items = einval();
|
||||||
goto Done;
|
goto Done;
|
||||||
|
@ -513,12 +517,16 @@ int __vcscanf(int callback(void *), //
|
||||||
if (discard) {
|
if (discard) {
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
} else if (ismalloc) {
|
} else if (ismalloc) {
|
||||||
buf = malloc(bufsize * charbytes);
|
if ((buf = malloc(bufsize * charbytes))) {
|
||||||
struct FreeMe *entry;
|
struct FreeMe *entry;
|
||||||
if (buf && (entry = calloc(1, sizeof(struct FreeMe)))) {
|
if (buf && (entry = calloc(1, sizeof(struct FreeMe)))) {
|
||||||
entry->ptr = buf;
|
entry->ptr = buf;
|
||||||
entry->next = freeme;
|
entry->next = freeme;
|
||||||
freeme = entry;
|
freeme = entry;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
items = -1;
|
||||||
|
goto Done;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buf = va_arg(va, void *);
|
buf = va_arg(va, void *);
|
||||||
|
|
2
third_party/libcxx/string
vendored
2
third_party/libcxx/string
vendored
|
@ -10,6 +10,8 @@
|
||||||
#ifndef _LIBCPP_STRING
|
#ifndef _LIBCPP_STRING
|
||||||
#define _LIBCPP_STRING
|
#define _LIBCPP_STRING
|
||||||
|
|
||||||
|
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
3
third_party/libcxxabi/cxa_guard_impl.h
vendored
3
third_party/libcxxabi/cxa_guard_impl.h
vendored
|
@ -338,7 +338,10 @@ public:
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (has_thread_id_support)
|
if (has_thread_id_support)
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||||
*thread_id_address = current_thread_id.get();
|
*thread_id_address = current_thread_id.get();
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
*init_byte_address = PENDING_BIT;
|
*init_byte_address = PENDING_BIT;
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -48,8 +48,10 @@ void Multiply%dx%d(uint64_t C[%d], const uint64_t A[%d], const uint64_t B[%d]) {
|
||||||
uint64_t z,h,l;\n\
|
uint64_t z,h,l;\n\
|
||||||
uint64_t ",
|
uint64_t ",
|
||||||
(n + m) * 64, n * 64, m * 64, n + m, n, m, n, m, n + m, n, m);
|
(n + m) * 64, n * 64, m * 64, n + m, n, m, n, m, n + m, n, m);
|
||||||
Rs = gc(calloc(sizeof(*Rs), n + m + 1));
|
if (!(Rs = calloc(sizeof(*Rs), n + m + 1)))
|
||||||
Ra = gc(calloc(sizeof(*Ra), n + m + 1));
|
__builtin_trap();
|
||||||
|
if (!(Ra = calloc(sizeof(*Ra), n + m + 1)))
|
||||||
|
__builtin_trap();
|
||||||
for (j = 0; j < n; ++j) {
|
for (j = 0; j < n; ++j) {
|
||||||
if (j)
|
if (j)
|
||||||
printf(", ");
|
printf(", ");
|
||||||
|
@ -172,6 +174,8 @@ void Multiply%dx%d(uint64_t C[%d], const uint64_t A[%d], const uint64_t B[%d]) {
|
||||||
}
|
}
|
||||||
printf("}\n");
|
printf("}\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
free(Ra);
|
||||||
|
free(Rs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/fmt/conv.h"
|
#include "libc/fmt/conv.h"
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
|
#include "libc/mem/gc.h"
|
||||||
|
#include "libc/mem/mem.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/stdio/stdio.h"
|
#include "libc/stdio/stdio.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
@ -44,8 +46,8 @@ int main(int argc, char *argv[]) {
|
||||||
long count = LONG_MAX;
|
long count = LONG_MAX;
|
||||||
long blocksize = 1;
|
long blocksize = 1;
|
||||||
int oflags = O_WRONLY | O_TRUNC | O_CREAT;
|
int oflags = O_WRONLY | O_TRUNC | O_CREAT;
|
||||||
const char *infile = "/dev/stdin";
|
char *infile = gc(strdup("/dev/stdin"));
|
||||||
const char *oufile = "/dev/stdout";
|
char *oufile = gc(strdup("/dev/stdout"));
|
||||||
|
|
||||||
prog = argv[0];
|
prog = argv[0];
|
||||||
if (!prog)
|
if (!prog)
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include "libc/sysv/consts/prot.h"
|
#include "libc/sysv/consts/prot.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
open(argv[1], O_RDWR);
|
int fd = open(argv[1], O_RDWR);
|
||||||
Elf64_Ehdr *e = mmap(0, 64, PROT_READ | PROT_WRITE, MAP_SHARED, 3, 0);
|
Elf64_Ehdr *e = mmap(0, 64, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
e->e_ident[EI_OSABI] = ELFOSABI_SYSV;
|
e->e_ident[EI_OSABI] = ELFOSABI_SYSV;
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,6 +139,7 @@ void Compress(const char *inpath) {
|
||||||
FILE *input;
|
FILE *input;
|
||||||
gzFile output;
|
gzFile output;
|
||||||
int rc, errnum;
|
int rc, errnum;
|
||||||
|
FILE *closeme = 0;
|
||||||
const char *outpath;
|
const char *outpath;
|
||||||
char *p, openflags[5];
|
char *p, openflags[5];
|
||||||
if ((!inpath || opt_usestdout) && (!isatty(1) || opt_force)) {
|
if ((!inpath || opt_usestdout) && (!isatty(1) || opt_force)) {
|
||||||
|
@ -151,7 +152,7 @@ void Compress(const char *inpath) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (inpath) {
|
if (inpath) {
|
||||||
input = fopen(inpath, "rb");
|
input = closeme = fopen(inpath, "rb");
|
||||||
} else {
|
} else {
|
||||||
inpath = "/dev/stdin";
|
inpath = "/dev/stdin";
|
||||||
input = stdin;
|
input = stdin;
|
||||||
|
@ -178,8 +179,9 @@ void Compress(const char *inpath) {
|
||||||
}
|
}
|
||||||
if (!output) {
|
if (!output) {
|
||||||
fputs(outpath, stderr);
|
fputs(outpath, stderr);
|
||||||
fputs(": gzopen() failed\n", stderr);
|
fputs(": gzopen() failed: ", stderr);
|
||||||
fputs(_strerdoc(errno), stderr);
|
const char *s = _strerdoc(errno);
|
||||||
|
fputs(s ? s : "EUNKNOWN", stderr);
|
||||||
fputs("\n", stderr);
|
fputs("\n", stderr);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -189,7 +191,8 @@ void Compress(const char *inpath) {
|
||||||
errnum = 0;
|
errnum = 0;
|
||||||
fputs(inpath, stderr);
|
fputs(inpath, stderr);
|
||||||
fputs(": read failed: ", stderr);
|
fputs(": read failed: ", stderr);
|
||||||
fputs(_strerdoc(ferror(input)), stderr);
|
const char *s = _strerdoc(ferror(input));
|
||||||
|
fputs(s ? s : "EUNKNOWN", stderr);
|
||||||
fputs("\n", stderr);
|
fputs("\n", stderr);
|
||||||
_Exit(1);
|
_Exit(1);
|
||||||
}
|
}
|
||||||
|
@ -201,8 +204,8 @@ void Compress(const char *inpath) {
|
||||||
_Exit(1);
|
_Exit(1);
|
||||||
}
|
}
|
||||||
} while (rc == sizeof(databuf));
|
} while (rc == sizeof(databuf));
|
||||||
if (input != stdin) {
|
if (closeme) {
|
||||||
if (fclose(input)) {
|
if (fclose(closeme)) {
|
||||||
fputs(inpath, stderr);
|
fputs(inpath, stderr);
|
||||||
fputs(": close failed\n", stderr);
|
fputs(": close failed\n", stderr);
|
||||||
_Exit(1);
|
_Exit(1);
|
||||||
|
@ -221,6 +224,7 @@ void Compress(const char *inpath) {
|
||||||
void Decompress(const char *inpath) {
|
void Decompress(const char *inpath) {
|
||||||
FILE *output;
|
FILE *output;
|
||||||
gzFile input;
|
gzFile input;
|
||||||
|
FILE *closeme = 0;
|
||||||
int rc, n, errnum;
|
int rc, n, errnum;
|
||||||
const char *outpath;
|
const char *outpath;
|
||||||
outpath = 0;
|
outpath = 0;
|
||||||
|
@ -233,8 +237,9 @@ void Decompress(const char *inpath) {
|
||||||
}
|
}
|
||||||
if (!input) {
|
if (!input) {
|
||||||
fputs(inpath, stderr);
|
fputs(inpath, stderr);
|
||||||
fputs(": gzopen() failed\n", stderr);
|
fputs(": gzopen() failed: ", stderr);
|
||||||
fputs(_strerdoc(errno), stderr);
|
const char *s = _strerdoc(errno);
|
||||||
|
fputs(s ? s : "EUNKNOWN", stderr);
|
||||||
fputs("\n", stderr);
|
fputs("\n", stderr);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -248,10 +253,11 @@ void Decompress(const char *inpath) {
|
||||||
memcpy(pathbuf, inpath, n - 3);
|
memcpy(pathbuf, inpath, n - 3);
|
||||||
pathbuf[n - 3] = 0;
|
pathbuf[n - 3] = 0;
|
||||||
outpath = pathbuf;
|
outpath = pathbuf;
|
||||||
if (!(output = fopen(outpath, opt_append ? "wa" : "wb"))) {
|
if (!(output = closeme = fopen(outpath, opt_append ? "wa" : "wb"))) {
|
||||||
fputs(outpath, stderr);
|
fputs(outpath, stderr);
|
||||||
fputs(": open failed: ", stderr);
|
fputs(": open failed: ", stderr);
|
||||||
fputs(_strerdoc(errno), stderr);
|
const char *s = _strerdoc(errno);
|
||||||
|
fputs(s ? s : "EUNKNOWN", stderr);
|
||||||
fputs("\n", stderr);
|
fputs("\n", stderr);
|
||||||
_Exit(1);
|
_Exit(1);
|
||||||
}
|
}
|
||||||
|
@ -273,7 +279,8 @@ void Decompress(const char *inpath) {
|
||||||
if (fwrite(databuf, rc, 1, output) != 1) {
|
if (fwrite(databuf, rc, 1, output) != 1) {
|
||||||
fputs(outpath, stderr);
|
fputs(outpath, stderr);
|
||||||
fputs(": write failed: ", stderr);
|
fputs(": write failed: ", stderr);
|
||||||
fputs(_strerdoc(ferror(output)), stderr);
|
const char *s = _strerdoc(ferror(output));
|
||||||
|
fputs(s ? s : "EUNKNOWN", stderr);
|
||||||
fputs("\n", stderr);
|
fputs("\n", stderr);
|
||||||
_Exit(1);
|
_Exit(1);
|
||||||
}
|
}
|
||||||
|
@ -283,8 +290,8 @@ void Decompress(const char *inpath) {
|
||||||
fputs(": gzclose failed\n", stderr);
|
fputs(": gzclose failed\n", stderr);
|
||||||
_Exit(1);
|
_Exit(1);
|
||||||
}
|
}
|
||||||
if (output != stdout) {
|
if (closeme) {
|
||||||
if (fclose(output)) {
|
if (fclose(closeme)) {
|
||||||
fputs(outpath, stderr);
|
fputs(outpath, stderr);
|
||||||
fputs(": close failed\n", stderr);
|
fputs(": close failed\n", stderr);
|
||||||
_Exit(1);
|
_Exit(1);
|
||||||
|
|
|
@ -204,7 +204,8 @@ bool Send(int tmpfd, const void *output, size_t outputsize) {
|
||||||
static bool once;
|
static bool once;
|
||||||
static z_stream zs;
|
static z_stream zs;
|
||||||
zsize = 32768;
|
zsize = 32768;
|
||||||
zbuf = gc(malloc(zsize));
|
if (!(zbuf = malloc(zsize)))
|
||||||
|
__builtin_trap();
|
||||||
if (!once) {
|
if (!once) {
|
||||||
CHECK_EQ(Z_OK, deflateInit2(&zs, 4, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
|
CHECK_EQ(Z_OK, deflateInit2(&zs, 4, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
|
||||||
Z_DEFAULT_STRATEGY));
|
Z_DEFAULT_STRATEGY));
|
||||||
|
@ -226,6 +227,7 @@ bool Send(int tmpfd, const void *output, size_t outputsize) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (!zs.avail_out);
|
} while (!zs.avail_out);
|
||||||
|
free(zbuf);
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -218,7 +218,20 @@
|
||||||
"__sysv_abi__"
|
"__sysv_abi__"
|
||||||
"__mode__"
|
"__mode__"
|
||||||
"__seg_fs"
|
"__seg_fs"
|
||||||
"__seg_gs"))
|
"__seg_gs"
|
||||||
|
"__access__"
|
||||||
|
"__read_only__"
|
||||||
|
"__write_only__"
|
||||||
|
"__read_write__"
|
||||||
|
"__read_only"
|
||||||
|
"__write_only"
|
||||||
|
"__read_write"
|
||||||
|
"__fd_arg__"
|
||||||
|
"__fd_arg"
|
||||||
|
"__copy__"
|
||||||
|
"__retain__"
|
||||||
|
"__tainted_args__"
|
||||||
|
"__zero_call_used_regs__"))
|
||||||
|
|
||||||
(clang
|
(clang
|
||||||
'("__optnone__"
|
'("__optnone__"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue