diff options
| author | Kacper <kacper@mail.openlinux.dev> | 2025-12-09 21:17:12 +0100 |
|---|---|---|
| committer | Kacper <kacper@mail.openlinux.dev> | 2025-12-09 21:17:12 +0100 |
| commit | b5cd18739a64c8d923a55b61c89ae3900faafd84 (patch) | |
| tree | d192f7b25257ae9a8a4760c68f5314dcbc0d9b91 | |
| parent | 119aed5bc787ccbf23d2f151759ec1f3a80977e1 (diff) | |
Fix include paths and formatting inconsistencies
343 files changed, 1406 insertions, 1029 deletions
@@ -1,2 +1,4 @@ obj-y += lib/ obj-y += bin/ + +bin/: lib/ @@ -1,12 +1,12 @@ mainmenu "Openlinux Configuration" menu "General Setup" - config CONFIG_WERROR + config WERROR bool "Compile the system with -Werror" help If you select this option, all compiler warnings will be treated as errors. - config CONFIG_DEBUG + config DEBUG bool "Enable Debugging Features" help Enable this option to include debugging symbols and additional debug information in the build. diff --git a/bin/gzip/gzip.c b/bin/gzip/gzip.c index ddafcade..bc7a4bf2 100644 --- a/bin/gzip/gzip.c +++ b/bin/gzip/gzip.c @@ -49,7 +49,6 @@ static char *license_msg[] = { static char rcsid[] = "$Id: gzip.c,v 1.3 2005/02/12 21:03:28 olh Exp $"; #endif -#include <ctype.h> #include <sys/types.h> #include <signal.h> #include <sys/stat.h> @@ -230,9 +229,7 @@ local void version() } /* ======================================================================== */ -int main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { int file_count; /* number of files to precess */ int optc; /* current option */ @@ -489,7 +486,7 @@ local void treat_stdin() /* ======================================================================== * Compress or decompress the given file */ -local void treat_file(iname) char *iname; +local void treat_file(char *iname) { /* Accept "-" as synonym for stdin */ if (strequ(iname, "-")) { @@ -692,9 +689,7 @@ local int create_outfile() * Use lstat if available, except for -c or -f. Use stat otherwise. * This allows links when not removing the original file. */ -local int do_stat(name, sbuf) -char *name; -struct stat *sbuf; +local int do_stat(char *name, struct stat *sbuf) { errno = 0; if (!to_stdout && !force) { @@ -715,8 +710,7 @@ struct stat *sbuf; * On systems allowing multiple versions of the same file (such as VMS), * this function removes any version suffix in the given name. */ -local char *get_suffix(name) -char *name; +local char *get_suffix(char *name) { int nlen, slen; char suffix[MAX_SUFFIX + 3]; /* last chars of name, forced to lower case @@ -754,9 +748,7 @@ char *name; * For MSDOS, we try only z_suffix and z. * Return OK or ERROR. */ -local int get_istat(iname, sbuf) -char *iname; -struct stat *sbuf; +local int get_istat(char *iname, struct stat *sbuf) { int ilen; /* strlen(ifname) */ static char *suffixes[] = { z_suffix, ".gz", ".z", "-z", ".Z", NULL }; @@ -1019,9 +1011,7 @@ local int get_method() /* ======================================================================== * Return true if the two stat structures correspond to the same file. */ -local int same_file(stat1, stat2) -struct stat *stat1; -struct stat *stat2; +local int same_file(struct stat *stat1, struct stat *stat2) { return stat1->st_ino == stat2->st_ino && stat1->st_dev == stat2->st_dev @@ -1042,9 +1032,7 @@ struct stat *stat2; * Return true if a file name is ambiguous because the operating system * truncates file names. */ -local int name_too_long(name, statb) -char *name; /* file name to check */ -struct stat *statb; /* stat buf for this file name */ +local int name_too_long(char *name, struct stat *statb) { int s = strlen(name); char c = name[s - 1]; @@ -1068,7 +1056,7 @@ struct stat *statb; /* stat buf for this file name */ * * IN assertion: for compression, the suffix of the given name is z_suffix. */ -local void shorten_name(name) char *name; +local void shorten_name(char *name) { int len; /* length of name without z_suffix */ char *trunc = NULL; /* character to be truncated */ @@ -1215,8 +1203,7 @@ local int check_ofname() /* ======================================================================== * Set the access and modification times from the given stat buffer. */ -local void reset_times(name, statb) char *name; -struct stat *statb; +local void reset_times(char *name, struct stat *statb) { struct utimbuf timep; @@ -1236,7 +1223,7 @@ struct stat *statb; * Copy modes, times, ownership from input file to output file. * IN assertion: to_stdout is false. */ -local void copy_stat(ifstat) struct stat *ifstat; +local void copy_stat(struct stat *ifstat) { if (decompress && time_stamp != 0 && ifstat->st_mtime != time_stamp) { ifstat->st_mtime = time_stamp; @@ -1268,7 +1255,7 @@ local void copy_stat(ifstat) struct stat *ifstat; /* ======================================================================== * Free all dynamically allocated variables and exit with the given code. */ -local void do_exit(exitcode) int exitcode; +local void do_exit(int exitcode) { static int in_exit = 0; diff --git a/bin/gzip/inflate.c b/bin/gzip/inflate.c index a2235515..bf9774f0 100644 --- a/bin/gzip/inflate.c +++ b/bin/gzip/inflate.c @@ -159,7 +159,7 @@ static ush cplens[] = { /* Copy lengths for literal codes 257..285 */ static ush cplext[] = { /* Extra bits for literal codes 257..285 */ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 -}; /* 99==invalid */ +}; /* 99==invalid */ static ush cpdist[] = { /* Copy offsets for distance codes 0..29 */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, @@ -268,19 +268,8 @@ int dbits = 6; /* bits in base distance lookup table */ unsigned hufts; /* track memory usage */ -int huft_build(b, n, s, d, e, t, m) -unsigned *b; /* code lengths in bits (all assumed <= BMAX) */ -unsigned n; /* number of codes (assumed <= N_MAX) */ -unsigned s; /* number of simple-valued codes (0..s-1) */ -ush *d; /* list of base values for non-simple codes */ -ush *e; /* list of extra bits for non-simple codes */ -struct huft **t; /* result: starting table */ -int *m; /* maximum lookup bits, returns actual */ -/* Given a list of code lengths and a maximum table size, make a set of - tables to decode that set of codes. Return zero on success, one if - the given code set is incomplete (the tables are still built in this - case), two if the input is invalid (all zero length codes or an - oversubscribed set of lengths), and three if not enough memory. */ +int huft_build(unsigned *b, unsigned n, unsigned s, ush *d, ush *e, + struct huft **t, int *m) { unsigned a; /* counter for codes of length k */ unsigned c[BMAX + 1]; /* bit length count table */ @@ -474,11 +463,7 @@ int *m; /* maximum lookup bits, returns actual */ return y != 0 && g != 1; } -int huft_free(t) -struct huft *t; /* table to free */ -/* Free the malloc'ed tables built by huft_build(), which makes a linked - list of the tables it made, with the links in a dummy first entry of - each table. */ +int huft_free(struct huft *t) { register struct huft *p, *q; @@ -492,11 +477,7 @@ struct huft *t; /* table to free */ return 0; } -int inflate_codes(tl, td, bl, bd) -struct huft *tl, *td; /* literal/length and distance decoder tables */ -int bl, bd; /* number of bits decoded by tl[] and td[] */ -/* inflate (decompress) the codes in a deflated (compressed) block. - Return an error code or zero if it all goes ok. */ +int inflate_codes(struct huft *tl, struct huft *td, int bl, int bd) { register unsigned e; /* table entry flag/number of extra bits */ unsigned n, d; /* length and index for copy */ @@ -837,9 +818,7 @@ int inflate_dynamic() return 0; } -int inflate_block(e) -int *e; /* last block flag */ -/* decompress an inflated block */ +int inflate_block(int *e) { unsigned t; /* block type */ register ulg b; /* bit buffer */ diff --git a/bin/gzip/unzip.c b/bin/gzip/unzip.c index 72855f8b..ba259afa 100644 --- a/bin/gzip/unzip.c +++ b/bin/gzip/unzip.c @@ -27,8 +27,7 @@ static char rcsid[] = "$Id: unzip.c,v 1.1 2002/08/18 00:59:21 hpa Exp $"; * the compressed data, from offsets inptr to insize-1 included. * The magic header has already been checked. The output buffer is cleared. */ -int unzip(in, out) -int in, out; /* input and output file descriptors */ +int unzip(int in, int out) { ulg orig_crc = 0; /* original crc */ ulg orig_len = 0; /* original uncompressed length */ diff --git a/bin/gzip/util.c b/bin/gzip/util.c index 841a0ce7..ce580ff9 100644 --- a/bin/gzip/util.c +++ b/bin/gzip/util.c @@ -26,8 +26,7 @@ extern ulg crc_32_tab[]; /* crc table, defined below */ * Copy input to output unchanged: zcat == cat with --force. * IN assertion: insize bytes have already been read in inbuf. */ -int copy(in, out) -int in, out; /* input and output file descriptors */ +int copy(int in, int out) { errno = 0; while (insize != 0 && (int)insize != EOF) { @@ -47,9 +46,7 @@ int in, out; /* input and output file descriptors */ * pointer, then initialize the crc shift register contents instead. * Return the current crc in either case. */ -ulg updcrc(s, n) -uch *s; /* pointer to bytes to pump through */ -unsigned n; /* number of bytes in s[] */ +ulg updcrc(uch *s, unsigned n) { register ulg c; /* temporary variable */ @@ -82,8 +79,7 @@ void clear_bufs() /* =========================================================================== * Fill the input buffer. This is called only when the buffer is empty. */ -int fill_inbuf(eof_ok) -int eof_ok; /* set if EOF acceptable as a result */ +int fill_inbuf(int eof_ok) { int len; @@ -142,9 +138,7 @@ void flush_window() * Does the same as write(), but also handles partial pipe writes and checks * for error return. */ -void write_buf(fd, buf, cnt) int fd; -voidp buf; -unsigned cnt; +void write_buf(int fd, voidp buf, unsigned cnt) { unsigned n; @@ -160,12 +154,11 @@ unsigned cnt; /* ======================================================================== * Put string s in lower case, return s. */ -char *strlwr(s) -char *s; +char *strlwr(char *s) { char *t; for (t = s; *t; t++) - *t = tolow(*t); + *t = tolower(*t); return s; } @@ -174,8 +167,7 @@ char *s; * any version suffix). For systems with file names that are not * case sensitive, force the base name to lower case. */ -char *basename(fname) -char *fname; +char *basename(char *fname) { char *p; @@ -183,6 +175,7 @@ char *fname; fname = p + 1; if (casemap('A') == 'a') strlwr(fname); + return fname; } @@ -193,10 +186,7 @@ char *fname; */ #define SEPARATOR " \t" /* separators in env variable */ -char *add_envopt(argcp, argvp, env) -int *argcp; /* pointer to argc */ -char ***argvp; /* pointer to argv */ -char *env; /* name of environment variable */ +char *add_envopt(int *argcp, char ***argvp, char *env) { char *p; /* running pointer through env variable */ char **oargv; /* runs through old argv array */ @@ -257,13 +247,13 @@ char *env; /* name of environment variable */ /* ======================================================================== * Error handlers. */ -void error(m) char *m; +void error(char *m) { fprintf(stderr, "\n%s: %s: %s\n", progname, ifname, m); abort_gzip(); } -void warn(a, b) char *a, *b; /* message strings juxtaposed in output */ +void warn(char *a, char *b) { WARN((stderr, "%s: %s: warning: %s%s\n", progname, ifname, a, b)); } @@ -289,9 +279,7 @@ void write_error() /* ======================================================================== * Display compression ratio on the given stream on 6 characters. */ -void display_ratio(num, den, file) long num; -long den; -FILE *file; +void display_ratio(long num, long den, FILE *file) { long ratio; /* 1000 times the compression ratio */ char sign; @@ -315,8 +303,7 @@ FILE *file; /* ======================================================================== * Semi-safe malloc -- never returns NULL. */ -voidp xmalloc(size) -unsigned size; +voidp xmalloc(unsigned size) { voidp cp = (voidp)malloc(size); diff --git a/bin/true/true b/bin/true/true Binary files differindex 107f7f2d..49700c41 100755 --- a/bin/true/true +++ b/bin/true/true diff --git a/include/arch/x86_64/bits/fenv.h b/include/arch/x86_64/bits/fenv.h index 40bc9e25..9ac982db 100644 --- a/include/arch/x86_64/bits/fenv.h +++ b/include/arch/x86_64/bits/fenv.h @@ -1,3 +1,5 @@ +#pragma once + #define FE_INVALID 1 #define __FE_DENORM 2 #define FE_DIVBYZERO 4 diff --git a/include/arch/x86_64/drm/drm.h b/include/arch/x86_64/drm/drm.h index a928f61f..ebd6ebb5 100644 --- a/include/arch/x86_64/drm/drm.h +++ b/include/arch/x86_64/drm/drm.h @@ -253,7 +253,7 @@ enum drm_stat_type { _DRM_STAT_DMA, /**< DMA */ _DRM_STAT_SPECIAL, /**< Special DMA (e.g., priority or polled) */ _DRM_STAT_MISSED /**< Missed DMA opportunity */ - /* Add to the *END* of the list */ + /* Add to the *END* of the list */ }; /* diff --git a/include/arch/x86_64/drm/i915_drm.h b/include/arch/x86_64/drm/i915_drm.h index e0403cb6..68f08e16 100644 --- a/include/arch/x86_64/drm/i915_drm.h +++ b/include/arch/x86_64/drm/i915_drm.h @@ -2115,10 +2115,10 @@ struct drm_i915_gem_context_param { #define I915_CONTEXT_MAX_USER_PRIORITY 1023 /* inclusive */ #define I915_CONTEXT_DEFAULT_PRIORITY 0 #define I915_CONTEXT_MIN_USER_PRIORITY -1023 /* inclusive */ - /* - * When using the following param, value should be a pointer to - * drm_i915_gem_context_param_sseu. - */ + /* + * When using the following param, value should be a pointer to + * drm_i915_gem_context_param_sseu. + */ #define I915_CONTEXT_PARAM_SSEU 0x7 /* diff --git a/include/arch/x86_64/linux/can/isotp.h b/include/arch/x86_64/linux/can/isotp.h index d986173d..3d72f3d3 100644 --- a/include/arch/x86_64/linux/can/isotp.h +++ b/include/arch/x86_64/linux/can/isotp.h @@ -85,7 +85,7 @@ struct can_isotp_options { /* __u8 value : content on rx path */ __u8 rx_ext_address; /* set address for extended addressing */ - /* __u8 value : extended address (rx) */ + /* __u8 value : extended address (rx) */ }; struct can_isotp_fc_options { diff --git a/include/arch/x86_64/linux/hdlcdrv.h b/include/arch/x86_64/linux/hdlcdrv.h index 784d1dcf..0d3f0ba7 100644 --- a/include/arch/x86_64/linux/hdlcdrv.h +++ b/include/arch/x86_64/linux/hdlcdrv.h @@ -29,7 +29,7 @@ struct hdlcdrv_channel_params { int slottime; /* the slottime in 10ms; usually 10 = 100ms */ int ppersist; /* the p-persistence 0..255 */ int fulldup; /* some driver do not support full duplex, setting */ - /* this just makes them send even if DCD is on */ + /* this just makes them send even if DCD is on */ }; struct hdlcdrv_old_channel_state { diff --git a/include/arch/x86_64/linux/scc.h b/include/arch/x86_64/linux/scc.h index ce9c783b..ac19e3ef 100644 --- a/include/arch/x86_64/linux/scc.h +++ b/include/arch/x86_64/linux/scc.h @@ -87,7 +87,7 @@ enum CLOCK_sources { CLK_DIVIDER, /* Rx = DPLL, Tx = divider (fullduplex with */ /* modems without clock regeneration */ CLK_BRG /* experimental fullduplex mode with DPLL/BRG for */ - /* MODEMs without clock recovery */ + /* MODEMs without clock recovery */ }; /* Tx state */ diff --git a/include/bits/stat.h b/include/bits/stat.h index ba43e695..0022cea8 100644 --- a/include/bits/stat.h +++ b/include/bits/stat.h @@ -3,11 +3,12 @@ #ifndef __BITS_STAT_H_ #error "Internal header — include the public API header instead." +#else +#undef __BITS_STAT_H_ #endif #define __BITS_TIMESPEC_H_ #include <bits/timespec.h> -#undef __BITS_TIMESPEC_H_ typedef __UINT64_TYPE__ dev_t; typedef __UINT64_TYPE__ ino_t; diff --git a/include/poll.h b/include/poll.h index 40367012..1e7e98bd 100644 --- a/include/poll.h +++ b/include/poll.h @@ -13,7 +13,7 @@ #define POLLNVAL 0x0020 typedef __INT64_TYPE__ time_t; -typedef __INT32_TYPE__ sigset_t; +typedef __UINT64_TYPE__ sigset_t; typedef unsigned long nfds_t; struct timespec; diff --git a/include/signal.h b/include/signal.h index 6b7f2a4a..8e49fc8a 100644 --- a/include/signal.h +++ b/include/signal.h @@ -5,7 +5,9 @@ #include <bits/sigevent.h> #define __BITS_SIGINFO_H_ -#include <bits/siginfo.h> +#include <bits/siginfo.h> // for siginfo_t + +union sigval; #define SIG_DFL ((void (*)(int))0) #define SIG_ERR ((void (*)(int)) - 1) diff --git a/include/sys/cdefs.h b/include/sys/cdefs.h index c3bb51c1..0d6f6327 100644 --- a/include/sys/cdefs.h +++ b/include/sys/cdefs.h @@ -4,16 +4,16 @@ #define __BEGIN_DECLS extern "C" { #define __END_DECLS } -#define __dead __attribute__((__noreturn__)) - -#define __used __attribute__((__used__)) -#define __unused __attribute__((__unused__)) - +#define __dead __attribute__((__noreturn__)) +#define __used __attribute__((__used__)) +#define __unused __attribute__((__unused__)) #define __packed __attribute__((__packed__)) #define __aligned(x) __attribute__((__aligned__(x))) +#define __malloc __attribute__((__malloc__)) +#define __pure __attribute__((__pure__)) +#define __nodiscard __attribute__((__warn_unused_result__)) -#define __malloc __attribute__((__malloc__)) - -#define __pure __attribute__((__pure__)) +#define __predict_true(exp) __builtin_expect((exp) != 0, 1) +#define __predict_false(exp) __builtin_expect((exp) != 0, 0) #endif diff --git a/include/sys/select.h b/include/sys/select.h index 13c48dda..16b391d1 100644 --- a/include/sys/select.h +++ b/include/sys/select.h @@ -7,6 +7,9 @@ #define __BITS_TIMESPEC_H_ #include <bits/timespec.h> +struct timespec; +struct timeval; + typedef __UINT64_TYPE__ sigset_t; int pselect(int, fd_set *restrict, fd_set *restrict, fd_set *restrict, diff --git a/include/sys/wait.h b/include/sys/wait.h index ad935dc8..1325885e 100644 --- a/include/sys/wait.h +++ b/include/sys/wait.h @@ -2,7 +2,9 @@ #define __WAIT_H #define __BITS_WAIT_H_ -#include <bits/wait.h> +#include <bits/wait.h> // for WUNTRACED +#include <signal.h> // for siginfo_t +#include <sys/types.h> // for pid_t, id_t #define __BITS_SIGINFO_H_ #include <bits/siginfo.h> diff --git a/lib/libc/arch/x86_64/clock_gettime.c b/lib/libc/arch/x86_64/clock_gettime.c index 6a7a3874..c05926fa 100644 --- a/lib/libc/arch/x86_64/clock_gettime.c +++ b/lib/libc/arch/x86_64/clock_gettime.c @@ -1,6 +1,8 @@ -#include <asm/vdso.h> -#include <syscall.h> -#include <time.h> +#include "asm/unistd_64.h" // for __NR_clock_gettime + +#include <asm/vdso.h> // for __vdso_clock_gettime +#include <syscall.h> // for __syscall_2, syscall +#include <time.h> // for clock_gettime, clockid_t int clock_gettime(clockid_t clock_id, struct timespec *tp) { diff --git a/lib/libc/arch/x86_64/crt0.c b/lib/libc/arch/x86_64/crt0.c index 546d9c8a..53ae222d 100644 --- a/lib/libc/arch/x86_64/crt0.c +++ b/lib/libc/arch/x86_64/crt0.c @@ -1,10 +1,9 @@ -#include <linux/auxvec.h> -#include <linux/elf.h> -#include <stdint.h> -#include <stdlib.h> -#include <sys/time.h> -#include <thread.h> -#include <unistd.h> +#include <linux/auxvec.h> // for AT_NULL +#include <linux/elf.h> // for Elf64_Ehdr +#include "asm/auxvec.h" // for AT_SYSINFO_EHDR + +#include <stdint.h> // for uintptr_t +#include <stdlib.h> // for exit #define weak_reference(old, new) \ extern __typeof(old) new __attribute__((__weak__, __alias__(#old))) diff --git a/lib/libc/arch/x86_64/longjmp.c b/lib/libc/arch/x86_64/longjmp.c index 6aed69a5..dbd18632 100644 --- a/lib/libc/arch/x86_64/longjmp.c +++ b/lib/libc/arch/x86_64/longjmp.c @@ -1,4 +1,6 @@ -#include <setjmp.h> +#include "bits/setjmp.h" // for jmp_buf + +#include <setjmp.h> // for longjmp __attribute__((noreturn, naked, returns_twice)) void longjmp(jmp_buf env, int val) diff --git a/lib/libc/arch/x86_64/setjmp.c b/lib/libc/arch/x86_64/setjmp.c index d268ae25..ea205e16 100644 --- a/lib/libc/arch/x86_64/setjmp.c +++ b/lib/libc/arch/x86_64/setjmp.c @@ -1,4 +1,6 @@ -#include <setjmp.h> +#include "bits/setjmp.h" // for jmp_buf + +#include <setjmp.h> // for setjmp __attribute__((naked, returns_twice)) int setjmp(jmp_buf env) { diff --git a/lib/libc/arch/x86_64/sigsetjmp.c b/lib/libc/arch/x86_64/sigsetjmp.c index d4c0a4db..2d900ce7 100644 --- a/lib/libc/arch/x86_64/sigsetjmp.c +++ b/lib/libc/arch/x86_64/sigsetjmp.c @@ -1,4 +1,4 @@ -#include <setjmp.h> +#include <setjmp.h> // for sigsetjmp, sigjmp_buf int sigsetjmp(sigjmp_buf env, int savemask) { diff --git a/lib/libc/arch/x86_64/vdso_setup.c b/lib/libc/arch/x86_64/vdso_setup.c index c410995d..e1dbd0a3 100644 --- a/lib/libc/arch/x86_64/vdso_setup.c +++ b/lib/libc/arch/x86_64/vdso_setup.c @@ -1,7 +1,7 @@ -#include <linux/auxvec.h> -#include <linux/elf.h> -#include <string.h> -#include <time.h> +#include <linux/elf.h> // for Elf64_Sym, (anonymous struct)::(anonymous) +#include <string.h> // for NULL, strcmp + +struct timespec; int (*__vdso_clock_gettime)(int, struct timespec *) = NULL; int (*__vdso_getcpu)(unsigned *, unsigned *, void *) = NULL; diff --git a/lib/libc/arpa/htonl.c b/lib/libc/arpa/htonl.c index 96f3ba4e..bab87482 100644 --- a/lib/libc/arpa/htonl.c +++ b/lib/libc/arpa/htonl.c @@ -1,5 +1,6 @@ -#include <arpa/inet.h> -#include <byteswap.h> +#include <arpa/inet.h> // for htonl +#include <byteswap.h> // for bswap32 +#include <stdint.h> // for uint32_t uint32_t htonl(uint32_t hostlong) { diff --git a/lib/libc/arpa/htons.c b/lib/libc/arpa/htons.c index 7c8dcc51..9cfa42f6 100644 --- a/lib/libc/arpa/htons.c +++ b/lib/libc/arpa/htons.c @@ -1,5 +1,6 @@ -#include <arpa/inet.h> -#include <byteswap.h> +#include <arpa/inet.h> // for htons +#include <byteswap.h> // for bswap16 +#include <stdint.h> // for uint16_t uint16_t htons(uint16_t hostshort) { diff --git a/lib/libc/arpa/inet_addr.c b/lib/libc/arpa/inet_addr.c index 5514e966..35a0795d 100644 --- a/lib/libc/arpa/inet_addr.c +++ b/lib/libc/arpa/inet_addr.c @@ -1,4 +1,4 @@ -#include <arpa/inet.h> +#include <arpa/inet.h> // for in_addr_t, inet_addr in_addr_t inet_addr(const char *cp) { diff --git a/lib/libc/arpa/inet_ntoa.c b/lib/libc/arpa/inet_ntoa.c index 9d4f9b23..74935944 100644 --- a/lib/libc/arpa/inet_ntoa.c +++ b/lib/libc/arpa/inet_ntoa.c @@ -1,4 +1,4 @@ -#include <arpa/inet.h> +#include <arpa/inet.h> // for in_addr, inet_ntoa char *inet_ntoa(struct in_addr in) { diff --git a/lib/libc/arpa/inet_pton.c b/lib/libc/arpa/inet_pton.c index 7cbb37da..99e9f4eb 100644 --- a/lib/libc/arpa/inet_pton.c +++ b/lib/libc/arpa/inet_pton.c @@ -1,4 +1,4 @@ -#include <arpa/inet.h> +#include <arpa/inet.h> // for inet_pton int inet_pton(int af, const char *restrict src, void *restrict dst) { diff --git a/lib/libc/arpa/ntohl.c b/lib/libc/arpa/ntohl.c index 0adcbc5f..691c3543 100644 --- a/lib/libc/arpa/ntohl.c +++ b/lib/libc/arpa/ntohl.c @@ -1,5 +1,6 @@ -#include <arpa/inet.h> -#include <byteswap.h> +#include <arpa/inet.h> // for ntohl +#include <byteswap.h> // for bswap32 +#include <stdint.h> // for uint32_t uint32_t ntohl(uint32_t netlong) { diff --git a/lib/libc/arpa/ntohs.c b/lib/libc/arpa/ntohs.c index c0f868bc..6c7e55d6 100644 --- a/lib/libc/arpa/ntohs.c +++ b/lib/libc/arpa/ntohs.c @@ -1,5 +1,6 @@ -#include <arpa/inet.h> -#include <byteswap.h> +#include <arpa/inet.h> // for ntohs +#include <byteswap.h> // for bswap16 +#include <stdint.h> // for uint16_t uint16_t ntohs(uint16_t netshort) { diff --git a/lib/libc/assert/assert.c b/lib/libc/assert/assert.c index a694da2c..367f5421 100644 --- a/lib/libc/assert/assert.c +++ b/lib/libc/assert/assert.c @@ -1,6 +1,6 @@ #include <assert.h> -#include <stdlib.h> -#include <stdio.h> +#include <stdio.h> // for fprintf, stderr +#include <stdlib.h> // for abort _Noreturn void __assert(const char *_Nonnull __file, int __line, const char *_Nonnull __func, diff --git a/lib/libc/ctype/isalnum.c b/lib/libc/ctype/isalnum.c index 3384aa56..3263f693 100644 --- a/lib/libc/ctype/isalnum.c +++ b/lib/libc/ctype/isalnum.c @@ -1,5 +1,8 @@ -#include <libc.h> -#include <ctype.h> +#include "features.h" // for __weak + +#include <ctype.h> // for isalnum, isalpha, isdigit, isalnum_l +#include <libc.h> // for __unused +#include <locale.h> // for locale_t int isalnum(int c) { diff --git a/lib/libc/ctype/isalpha.c b/lib/libc/ctype/isalpha.c index d046c09e..a1b89762 100644 --- a/lib/libc/ctype/isalpha.c +++ b/lib/libc/ctype/isalpha.c @@ -1,4 +1,4 @@ -#include <libc.h> +#include <libc.h> // for weak_reference int isalpha(int c) { diff --git a/lib/libc/ctype/isblank.c b/lib/libc/ctype/isblank.c index 7ad08709..c4dacfb2 100644 --- a/lib/libc/ctype/isblank.c +++ b/lib/libc/ctype/isblank.c @@ -1,4 +1,4 @@ -#include <libc.h> +#include <libc.h> // for weak_reference int isblank(int c) { diff --git a/lib/libc/ctype/iscntrl.c b/lib/libc/ctype/iscntrl.c index 6d4ff5a8..c25773b6 100644 --- a/lib/libc/ctype/iscntrl.c +++ b/lib/libc/ctype/iscntrl.c @@ -1,4 +1,4 @@ -#include <libc.h> +#include <libc.h> // for weak_reference int iscntrl(int c) { diff --git a/lib/libc/ctype/isdigit.c b/lib/libc/ctype/isdigit.c index 445e1cdc..fa36222d 100644 --- a/lib/libc/ctype/isdigit.c +++ b/lib/libc/ctype/isdigit.c @@ -1,4 +1,4 @@ -#include <libc.h> +#include <libc.h> // for weak_reference int isdigit(int c) { diff --git a/lib/libc/ctype/isgraph.c b/lib/libc/ctype/isgraph.c index 03919200..07df57d0 100644 --- a/lib/libc/ctype/isgraph.c +++ b/lib/libc/ctype/isgraph.c @@ -1,4 +1,4 @@ -#include <libc.h> +#include <libc.h> // for weak_reference int isgraph(int c) { diff --git a/lib/libc/ctype/islower.c b/lib/libc/ctype/islower.c index 34980da6..a6108e39 100644 --- a/lib/libc/ctype/islower.c +++ b/lib/libc/ctype/islower.c @@ -1,4 +1,4 @@ -#include <libc.h> +#include <libc.h> // for weak_reference int islower(int c) { diff --git a/lib/libc/ctype/isprint.c b/lib/libc/ctype/isprint.c index 76524050..dbd381e7 100644 --- a/lib/libc/ctype/isprint.c +++ b/lib/libc/ctype/isprint.c @@ -1,4 +1,4 @@ -#include <libc.h> +#include <libc.h> // for weak_reference int isprint(int c) { diff --git a/lib/libc/ctype/ispunct.c b/lib/libc/ctype/ispunct.c index 24627809..e0029757 100644 --- a/lib/libc/ctype/ispunct.c +++ b/lib/libc/ctype/ispunct.c @@ -1,5 +1,8 @@ -#include <libc.h> -#include <ctype.h> +#include "features.h" // for __weak + +#include <ctype.h> // for isalnum, isgraph, ispunct, ispunct_l +#include <libc.h> // for __unused +#include <locale.h> // for locale_t int ispunct(int c) { diff --git a/lib/libc/ctype/isspace.c b/lib/libc/ctype/isspace.c index 86630c66..468e755b 100644 --- a/lib/libc/ctype/isspace.c +++ b/lib/libc/ctype/isspace.c @@ -1,4 +1,4 @@ -#include <libc.h> +#include <libc.h> // for weak_reference int isspace(int c) { diff --git a/lib/libc/ctype/isupper.c b/lib/libc/ctype/isupper.c index 458990df..b46dce41 100644 --- a/lib/libc/ctype/isupper.c +++ b/lib/libc/ctype/isupper.c @@ -1,4 +1,4 @@ -#include <libc.h> +#include <libc.h> // for weak_reference int isupper(int c) { diff --git a/lib/libc/ctype/isxdigit.c b/lib/libc/ctype/isxdigit.c index 588df77a..90346190 100644 --- a/lib/libc/ctype/isxdigit.c +++ b/lib/libc/ctype/isxdigit.c @@ -1,4 +1,4 @@ -#include <ctype.h> +#include <ctype.h> // for isdigit, isxdigit int isxdigit(int c) { diff --git a/lib/libc/ctype/tolower.c b/lib/libc/ctype/tolower.c index aeb462d8..af196d05 100644 --- a/lib/libc/ctype/tolower.c +++ b/lib/libc/ctype/tolower.c @@ -1,5 +1,8 @@ -#include <libc.h> -#include <ctype.h> +#include "features.h" // for __weak + +#include <ctype.h> // for isupper, tolower, tolower_l +#include <libc.h> // for __unused +#include <locale.h> // for locale_t int tolower(int c) { diff --git a/lib/libc/ctype/toupper.c b/lib/libc/ctype/toupper.c index 934841fa..3f7ebf43 100644 --- a/lib/libc/ctype/toupper.c +++ b/lib/libc/ctype/toupper.c @@ -1,5 +1,6 @@ -#include <libc.h> -#include <ctype.h> +#include <ctype.h> // for islower, toupper, toupper_l +#include <libc.h> // for __unused +#include <locale.h> // for locale_t int toupper(int c) { diff --git a/lib/libc/devctl/posix_devctl.c b/lib/libc/devctl/posix_devctl.c index b7c24d79..90eea9f9 100644 --- a/lib/libc/devctl/posix_devctl.c +++ b/lib/libc/devctl/posix_devctl.c @@ -1,7 +1,9 @@ -#include <libc.h> -#include <devctl.h> -#include <errno.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_ioctl + +#include <devctl.h> // for posix_devctl, size_t +#include <errno.h> // for errno +#include <libc.h> // for __unused +#include <syscall.h> // for __syscall_3, syscall int posix_devctl(int fildes, int dcmd, void *restrict dev_data_ptr, size_t __unused nbyte, int *restrict dev_info_ptr) diff --git a/lib/libc/dirent/closedir.c b/lib/libc/dirent/closedir.c index 8a4ef3a7..873364c2 100644 --- a/lib/libc/dirent/closedir.c +++ b/lib/libc/dirent/closedir.c @@ -1,17 +1,19 @@ -#include <errno.h> -#include <__dirent.h> -#include <unistd.h> -#include <dirent.h> -#include <stdlib.h> +#include <__dirent.h> // for __DIR +#include <dirent.h> // for DIR, closedir +#include <errno.h> // for EBADF, errno +#include <stdlib.h> // for free +#include <unistd.h> // for close int closedir(DIR *dirp) { - if (dirp->fildes >= 0) { + struct __DIR *rdirp = (struct __DIR *)dirp; + + if (rdirp->fildes >= 0) { errno = EBADF; return -1; } - close(dirp->fildes); - free(dirp); + close(rdirp->fildes); + free(rdirp); return 0; } diff --git a/lib/libc/dirent/dirfd.c b/lib/libc/dirent/dirfd.c index 857303de..0eb8201b 100644 --- a/lib/libc/dirent/dirfd.c +++ b/lib/libc/dirent/dirfd.c @@ -1,6 +1,5 @@ -#include <__dirent.h> -#include <dirent.h> -#include <stdint.h> +#include <dirent.h> // for DIR, dirfd +#include <stdint.h> // for intptr_t int dirfd(DIR *dirp) { diff --git a/lib/libc/dirent/fdopendir.c b/lib/libc/dirent/fdopendir.c index 469992c1..c0e3492b 100644 --- a/lib/libc/dirent/fdopendir.c +++ b/lib/libc/dirent/fdopendir.c @@ -1,20 +1,20 @@ -#include <errno.h> -#include <__dirent.h> -#include <dirent.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <stdlib.h> +#include "stddef.h" // for NULL + +#include <__dirent.h> // for __DIR +#include <dirent.h> // for DIR, fdopendir +#include <errno.h> // for EBADF, errno +#include <stdlib.h> // for calloc DIR *fdopendir(int fildes) { - DIR *dir; + struct __DIR *dir; if (fildes < 0) { errno = EBADF; return NULL; } - if ((dir = calloc(1, sizeof(DIR))) == NULL) { + if ((dir = calloc(1, sizeof(struct __DIR))) == NULL) { return NULL; } diff --git a/lib/libc/dirent/opendir.c b/lib/libc/dirent/opendir.c index 2e250024..6a5d3b5d 100644 --- a/lib/libc/dirent/opendir.c +++ b/lib/libc/dirent/opendir.c @@ -1,8 +1,6 @@ -#include <__dirent.h> - -#include <fcntl.h> -#include <unistd.h> -#include <dirent.h> +#include <dirent.h> // for fdopendir, DIR, opendir +#include <fcntl.h> // for open, O_RDONLY +#include <stddef.h> // for NULL DIR *opendir(const char *dirname) { diff --git a/lib/libc/dirent/readdir.c b/lib/libc/dirent/readdir.c index e4ac8cbd..a24185cb 100644 --- a/lib/libc/dirent/readdir.c +++ b/lib/libc/dirent/readdir.c @@ -1,5 +1,5 @@ -#include <__dirent.h> -#include <dirent.h> +#include <dirent.h> // for readdir_r, DIR, dirent, readdir +#include <stddef.h> // for NULL struct dirent *readdir(DIR *dirp) { diff --git a/lib/libc/dirent/readdir_r.c b/lib/libc/dirent/readdir_r.c index 98b12426..68f05fa3 100644 --- a/lib/libc/dirent/readdir_r.c +++ b/lib/libc/dirent/readdir_r.c @@ -1,15 +1,15 @@ /* Maintainer: <contact@bellrise.net> */ -#include <__dirent.h> -#include <errno.h> -#include <dirent.h> -#include <syscall.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <stddef.h> - -#include <stdio.h> +#include "asm/unistd_64.h" // for __NR_getdents64 +#include "stdio.h" // for NULL +#include "sys/types.h" // for off_t + +#include <__dirent.h> // for linux_dirent64 +#include <dirent.h> // for dirent, size_t, ssize_t, DIR, readdir_r +#include <errno.h> // for EINVAL, errno +#include <stddef.h> // for offsetof +#include <string.h> // for memcpy, memset +#include <syscall.h> // for __syscall_3, syscall int readdir_r(DIR *restrict dirp, struct dirent *restrict entry, struct dirent **restrict result) diff --git a/lib/libc/endian/be16toh.c b/lib/libc/endian/be16toh.c index 40793f93..9a5e8ff3 100644 --- a/lib/libc/endian/be16toh.c +++ b/lib/libc/endian/be16toh.c @@ -1,4 +1,5 @@ -#include <endian.h> +#include <endian.h> // for be16toh +#include <stdint.h> // for uint16_t uint16_t be16toh(uint16_t big_endian_16bits) { diff --git a/lib/libc/endian/be32toh.c b/lib/libc/endian/be32toh.c index bc7d4900..d87c9f58 100644 --- a/lib/libc/endian/be32toh.c +++ b/lib/libc/endian/be32toh.c @@ -1,4 +1,5 @@ -#include <endian.h> +#include <endian.h> // for be32toh +#include <stdint.h> // for uint32_t uint32_t be32toh(uint32_t big_endian_32bits) { diff --git a/lib/libc/endian/be64toh.c b/lib/libc/endian/be64toh.c index c52cc8a6..6ccdb175 100644 --- a/lib/libc/endian/be64toh.c +++ b/lib/libc/endian/be64toh.c @@ -1,4 +1,5 @@ -#include <endian.h> +#include <endian.h> // for be64toh +#include <stdint.h> // for uint64_t uint64_t be64toh(uint64_t big_endian_64bits) { diff --git a/lib/libc/endian/htobe16.c b/lib/libc/endian/htobe16.c index bb66595f..915296f3 100644 --- a/lib/libc/endian/htobe16.c +++ b/lib/libc/endian/htobe16.c @@ -1,4 +1,5 @@ -#include <endian.h> +#include <endian.h> // for htobe16 +#include <stdint.h> // for uint16_t uint16_t htobe16(uint16_t host_16bits) { diff --git a/lib/libc/endian/htobe32.c b/lib/libc/endian/htobe32.c index 4e294a82..378c6c20 100644 --- a/lib/libc/endian/htobe32.c +++ b/lib/libc/endian/htobe32.c @@ -1,4 +1,5 @@ -#include <endian.h> +#include <endian.h> // for htobe32 +#include <stdint.h> // for uint32_t uint32_t htobe32(uint32_t host_32bits) { diff --git a/lib/libc/endian/htobe64.c b/lib/libc/endian/htobe64.c index ef39de6a..54a363c8 100644 --- a/lib/libc/endian/htobe64.c +++ b/lib/libc/endian/htobe64.c @@ -1,4 +1,5 @@ -#include <endian.h> +#include <endian.h> // for htobe64 +#include <stdint.h> // for uint64_t uint64_t htobe64(uint64_t host_64bits) { diff --git a/lib/libc/endian/htole16.c b/lib/libc/endian/htole16.c index c5b1caa7..9bdd1675 100644 --- a/lib/libc/endian/htole16.c +++ b/lib/libc/endian/htole16.c @@ -1,4 +1,5 @@ -#include <endian.h> +#include <endian.h> // for htole16 +#include <stdint.h> // for uint16_t uint16_t htole16(uint16_t host_16bits) { diff --git a/lib/libc/endian/htole32.c b/lib/libc/endian/htole32.c index 6c9a3cdc..bf4771bd 100644 --- a/lib/libc/endian/htole32.c +++ b/lib/libc/endian/htole32.c @@ -1,4 +1,5 @@ -#include <endian.h> +#include <endian.h> // for htole32 +#include <stdint.h> // for uint32_t uint32_t htole32(uint32_t host_32bits) { diff --git a/lib/libc/endian/htole64.c b/lib/libc/endian/htole64.c index 36af0bea..acd2fb14 100644 --- a/lib/libc/endian/htole64.c +++ b/lib/libc/endian/htole64.c @@ -1,4 +1,5 @@ -#include <endian.h> +#include <endian.h> // for htole64 +#include <stdint.h> // for uint64_t uint64_t htole64(uint64_t host_64bits) { diff --git a/lib/libc/endian/le16toh.c b/lib/libc/endian/le16toh.c index ea85b5f6..620be0c1 100644 --- a/lib/libc/endian/le16toh.c +++ b/lib/libc/endian/le16toh.c @@ -1,4 +1,5 @@ -#include <endian.h> +#include <endian.h> // for le16toh +#include <stdint.h> // for uint16_t uint16_t le16toh(uint16_t little_endian_16bits) { diff --git a/lib/libc/endian/le32toh.c b/lib/libc/endian/le32toh.c index f85f0f94..c053c1b2 100644 --- a/lib/libc/endian/le32toh.c +++ b/lib/libc/endian/le32toh.c @@ -1,4 +1,5 @@ -#include <endian.h> +#include <endian.h> // for le32toh +#include <stdint.h> // for uint32_t uint32_t le32toh(uint32_t little_endian_32bits) { diff --git a/lib/libc/endian/le64toh.c b/lib/libc/endian/le64toh.c index 4f2cb5fc..409863f2 100644 --- a/lib/libc/endian/le64toh.c +++ b/lib/libc/endian/le64toh.c @@ -1,4 +1,5 @@ -#include <endian.h> +#include <endian.h> // for le64toh +#include <stdint.h> // for uint64_t uint64_t le64toh(uint64_t little_endian_64bits) { diff --git a/lib/libc/fcntl/creat.c b/lib/libc/fcntl/creat.c index fdcb6655..43110794 100644 --- a/lib/libc/fcntl/creat.c +++ b/lib/libc/fcntl/creat.c @@ -1,5 +1,8 @@ -#include <fcntl.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_creat + +#include <fcntl.h> // for creat +#include <sys/types.h> // for mode_t +#include <syscall.h> // for __syscall_2, syscall int creat(const char *path, mode_t mode) { diff --git a/lib/libc/fcntl/fcntl.c b/lib/libc/fcntl/fcntl.c index ae213df5..6112567d 100644 --- a/lib/libc/fcntl/fcntl.c +++ b/lib/libc/fcntl/fcntl.c @@ -1,6 +1,9 @@ -#include <fcntl.h> -#include <stdarg.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_fcntl, __NR_close +#include "errno.h" // for EINVAL + +#include <fcntl.h> // for F_DUPFD_CLOEXEC, FD_CLOEXEC, F_SETFD, F_D... +#include <stdarg.h> // for va_arg, va_end, va_list, va_start +#include <syscall.h> // for __syscall_ret, syscall, __syscall_3, __sy... int fcntl(int fildes, int cmd, ...) { diff --git a/lib/libc/fcntl/open.c b/lib/libc/fcntl/open.c index dbdff8f9..c00820c1 100644 --- a/lib/libc/fcntl/open.c +++ b/lib/libc/fcntl/open.c @@ -1,6 +1,9 @@ -#include <fcntl.h> -#include <stdarg.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_fcntl, __NR_open + +#include <fcntl.h> // for FD_CLOEXEC, F_SETFD, O_CLOEXEC, O_CREAT +#include <stdarg.h> // for va_arg, va_end, va_list, va_start +#include <sys/types.h> // for mode_t +#include <syscall.h> // for __syscall_3, syscall int open(const char *path, int oflag, ...) { diff --git a/lib/libc/fcntl/openat.c b/lib/libc/fcntl/openat.c index bb34d600..d3475f6b 100644 --- a/lib/libc/fcntl/openat.c +++ b/lib/libc/fcntl/openat.c @@ -1,6 +1,9 @@ -#include <fcntl.h> -#include <stdarg.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_openat + +#include <fcntl.h> // for O_CREAT, openat +#include <stdarg.h> // for va_arg, va_end, va_list, va_start +#include <sys/types.h> // for mode_t +#include <syscall.h> // for __syscall_4, syscall int openat(int fd, const char *path, int oflag, ...) { diff --git a/lib/libc/fcntl/posix_fadvise.c b/lib/libc/fcntl/posix_fadvise.c index dcf278fd..08718294 100644 --- a/lib/libc/fcntl/posix_fadvise.c +++ b/lib/libc/fcntl/posix_fadvise.c @@ -1,5 +1,8 @@ -#include <fcntl.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_fadvise64 + +#include <fcntl.h> // for posix_fadvise +#include <sys/types.h> // for off_t +#include <syscall.h> // for __syscall_4, syscall int posix_fadvise(int fd, off_t offset, off_t len, int advice) { diff --git a/lib/libc/fcntl/posix_fallocate.c b/lib/libc/fcntl/posix_fallocate.c index 221f2d38..61129c4a 100644 --- a/lib/libc/fcntl/posix_fallocate.c +++ b/lib/libc/fcntl/posix_fallocate.c @@ -1,5 +1,8 @@ -#include <fcntl.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_fallocate + +#include <fcntl.h> // for posix_fallocate +#include <sys/types.h> // for off_t +#include <syscall.h> // for __syscall_4, syscall int posix_fallocate(int fd, off_t offset, off_t len) { diff --git a/lib/libc/grp/getgrgid.c b/lib/libc/grp/getgrgid.c index 66ccaff1..4ce43129 100644 --- a/lib/libc/grp/getgrgid.c +++ b/lib/libc/grp/getgrgid.c @@ -1,6 +1,7 @@ -#include <grp.h> -#include <stddef.h> -#include <limits.h> +#include <grp.h> // for getgrgid_r, getgrgid, group +#include <limits.h> // for LINE_MAX +#include <stddef.h> // for NULL +#include <sys/types.h> // for gid_t struct group *getgrgid(gid_t gid) { diff --git a/lib/libc/grp/getgrgid_r.c b/lib/libc/grp/getgrgid_r.c index b3449d14..2fa4bccd 100644 --- a/lib/libc/grp/getgrgid_r.c +++ b/lib/libc/grp/getgrgid_r.c @@ -1,9 +1,10 @@ -#include <grp.h> -#include <string.h> -#include <limits.h> -#include <errno.h> -#include <stdlib.h> -#include <stdio.h> +#include <errno.h> // for ERANGE, errno +#include <grp.h> // for group, getgrgid_r +#include <limits.h> // for LINE_MAX +#include <stdio.h> // for NULL, fclose, fgets, fopen, FILE +#include <stdlib.h> // for strtoul +#include <string.h> // for strtok, memcpy, strlen +#include <sys/types.h> // for gid_t, size_t int getgrgid_r(gid_t gid, struct group *grp, char *buf, size_t buflen, struct group **result) diff --git a/lib/libc/include/io.h b/lib/libc/include/__stdio.h index ebda4b22..ebda4b22 100644 --- a/lib/libc/include/io.h +++ b/lib/libc/include/__stdio.h diff --git a/lib/libc/include/libc.h b/lib/libc/include/libc.h index 7faee4b7..6651feaa 100644 --- a/lib/libc/include/libc.h +++ b/lib/libc/include/libc.h @@ -4,6 +4,11 @@ #include <stdatomic.h> #include <features.h> +#include <__stdio.h> +#include <thread.h> + +#define __IMPL(_v) ((__##typeof(_v))_v) + #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #define __unused __attribute__((unused)) diff --git a/lib/libc/inttypes/imaxabs.c b/lib/libc/inttypes/imaxabs.c index 3af1df67..c5137ecc 100644 --- a/lib/libc/inttypes/imaxabs.c +++ b/lib/libc/inttypes/imaxabs.c @@ -1,4 +1,4 @@ -#include <stdint.h> +#include <stdint.h> // for intmax_t intmax_t imaxabs(intmax_t j) { diff --git a/lib/libc/inttypes/imaxdiv.c b/lib/libc/inttypes/imaxdiv.c index 36fd6d20..4bfa635a 100644 --- a/lib/libc/inttypes/imaxdiv.c +++ b/lib/libc/inttypes/imaxdiv.c @@ -1,4 +1,6 @@ -#include <inttypes.h> +#include "stdint.h" // for intmax_t + +#include <inttypes.h> // for imaxdiv_t, imaxdiv imaxdiv_t imaxdiv(intmax_t num, intmax_t den) { diff --git a/lib/libc/inttypes/strtoimax.c b/lib/libc/inttypes/strtoimax.c index f66e58a0..a8f0820b 100644 --- a/lib/libc/inttypes/strtoimax.c +++ b/lib/libc/inttypes/strtoimax.c @@ -28,9 +28,11 @@ * SUCH DAMAGE. */ -#include <ctype.h> -#include <errno.h> -#include <inttypes.h> +#include "stdint.h" // for intmax_t, INTMAX_MAX, INTMAX_MIN + +#include <ctype.h> // for isalpha, isdigit, isspace, isupper, isxdigit +#include <errno.h> // for errno, ERANGE, EINVAL +#include <inttypes.h> // for strtoimax /* * Convert a string to an intmax_t diff --git a/lib/libc/inttypes/strtoumax.c b/lib/libc/inttypes/strtoumax.c index 500e255a..46eecf06 100644 --- a/lib/libc/inttypes/strtoumax.c +++ b/lib/libc/inttypes/strtoumax.c @@ -1,5 +1,5 @@ -#include <stdint.h> -#include <stdlib.h> +#include <stdint.h> // for uintmax_t +#include <stdlib.h> // for strtoull uintmax_t strtoumax(const char *restrict s, char **restrict p, int base) { diff --git a/lib/libc/libc.a b/lib/libc/libc.a Binary files differindex 49fadae3..55b3b5a6 100644 --- a/lib/libc/libc.a +++ b/lib/libc/libc.a diff --git a/lib/libc/libgen/basename.c b/lib/libc/libgen/basename.c index 0de08da4..3f2cc02b 100644 --- a/lib/libc/libgen/basename.c +++ b/lib/libc/libgen/basename.c @@ -16,10 +16,10 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <errno.h> -#include <libgen.h> -#include <limits.h> -#include <string.h> +#include <errno.h> // for ENAMETOOLONG, errno +#include <libgen.h> // for basename +#include <limits.h> // for PATH_MAX +#include <string.h> // for NULL, memcpy, strlen, size_t char *basename(char *path) { diff --git a/lib/libc/libgen/dirname.c b/lib/libc/libgen/dirname.c index 48860e2b..0c6e1ac2 100644 --- a/lib/libc/libgen/dirname.c +++ b/lib/libc/libgen/dirname.c @@ -16,10 +16,10 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <errno.h> -#include <libgen.h> -#include <limits.h> -#include <string.h> +#include <errno.h> // for ENAMETOOLONG, errno +#include <libgen.h> // for dirname +#include <limits.h> // for PATH_MAX +#include <string.h> // for NULL, memcpy, strlen, size_t char *dirname(char *path) { diff --git a/lib/libc/mman/mlock.c b/lib/libc/mman/mlock.c index a7f48b27..c46b9435 100644 --- a/lib/libc/mman/mlock.c +++ b/lib/libc/mman/mlock.c @@ -1,5 +1,7 @@ -#include <syscall.h> -#include <sys/mman.h> +#include "asm/unistd_64.h" // for __NR_mlock + +#include <stddef.h> // for size_t +#include <syscall.h> // for __syscall_2, syscall int mlock(const void *addr, size_t len) { diff --git a/lib/libc/mman/mlockall.c b/lib/libc/mman/mlockall.c index df4dcbd1..ef12edd3 100644 --- a/lib/libc/mman/mlockall.c +++ b/lib/libc/mman/mlockall.c @@ -1,5 +1,6 @@ -#include <syscall.h> -#include <sys/mman.h> +#include "asm/unistd_64.h" // for __NR_mlockall + +#include <syscall.h> // for __syscall_1, syscall int mlockall(int flags) { diff --git a/lib/libc/mman/mmap.c b/lib/libc/mman/mmap.c index d7918447..c2a3fa72 100644 --- a/lib/libc/mman/mmap.c +++ b/lib/libc/mman/mmap.c @@ -1,6 +1,7 @@ -#include <stddef.h> -#include <linux/mman.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_mmap + +#include <stddef.h> // for size_t +#include <syscall.h> // for __syscall_6, syscall typedef __INT64_TYPE__ off_t; diff --git a/lib/libc/mman/mprotect.c b/lib/libc/mman/mprotect.c index ab5c6059..5c96f9b8 100644 --- a/lib/libc/mman/mprotect.c +++ b/lib/libc/mman/mprotect.c @@ -1,5 +1,7 @@ -#include <syscall.h> -#include <sys/mman.h> +#include "asm/unistd_64.h" // for __NR_mprotect + +#include <stddef.h> // for size_t +#include <syscall.h> // for __syscall_3, syscall int mprotect(void *addr, size_t len, int prot) { diff --git a/lib/libc/mman/msync.c b/lib/libc/mman/msync.c index b8dab1a9..c25a18e7 100644 --- a/lib/libc/mman/msync.c +++ b/lib/libc/mman/msync.c @@ -1,5 +1,7 @@ -#include <syscall.h> -#include <sys/mman.h> +#include "asm/unistd_64.h" // for __NR_msync + +#include <stddef.h> // for size_t +#include <syscall.h> // for __syscall_3, syscall int msync(void *addr, size_t len, int flags) { diff --git a/lib/libc/mman/munlock.c b/lib/libc/mman/munlock.c index b934c87d..2d62c032 100644 --- a/lib/libc/mman/munlock.c +++ b/lib/libc/mman/munlock.c @@ -1,5 +1,7 @@ -#include <syscall.h> -#include <sys/mman.h> +#include "asm/unistd_64.h" // for __NR_munlock + +#include <stddef.h> // for size_t +#include <syscall.h> // for __syscall_2, syscall int munlock(const void *addr, size_t len) { diff --git a/lib/libc/mman/munlockall.c b/lib/libc/mman/munlockall.c index c7f9c8d2..ecf9ddbc 100644 --- a/lib/libc/mman/munlockall.c +++ b/lib/libc/mman/munlockall.c @@ -1,5 +1,6 @@ -#include <syscall.h> -#include <sys/mman.h> +#include "asm/unistd_64.h" // for __NR_munlockall + +#include <syscall.h> // for __syscall_0, syscall int munlockall(void) { diff --git a/lib/libc/mman/munmap.c b/lib/libc/mman/munmap.c index 6929fc64..04ad9800 100644 --- a/lib/libc/mman/munmap.c +++ b/lib/libc/mman/munmap.c @@ -1,6 +1,7 @@ -#include <sys/mman.h> -#include <syscall.h> -#include <features.h> +#include "asm/unistd_64.h" // for __NR_munmap + +#include <sys/mman.h> // for munmap, size_t +#include <syscall.h> // for __syscall_2, syscall int munmap(void *addr, size_t len) { diff --git a/lib/libc/mman/posix_madvise.c b/lib/libc/mman/posix_madvise.c index a19adec2..e81c6712 100644 --- a/lib/libc/mman/posix_madvise.c +++ b/lib/libc/mman/posix_madvise.c @@ -1,5 +1,7 @@ -#include <sys/mman.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_madvise + +#include <sys/mman.h> // for posix_madvise, size_t +#include <syscall.h> // for __syscall_3, syscall int posix_madvise(void *addr, size_t len, int advice) { diff --git a/lib/libc/msg/msgctl.c b/lib/libc/msg/msgctl.c index fd25cae4..0df2e3cf 100644 --- a/lib/libc/msg/msgctl.c +++ b/lib/libc/msg/msgctl.c @@ -1,6 +1,7 @@ -#include <endian.h> -#include <sys/msg.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_msgctl + +#include <sys/msg.h> // for msgctl +#include <syscall.h> // for __syscall_3, syscall int msgctl(int msqid, int cmd, struct msqid_ds *buf) { diff --git a/lib/libc/poll/poll.c b/lib/libc/poll/poll.c index 4ff90aa6..24d91db6 100644 --- a/lib/libc/poll/poll.c +++ b/lib/libc/poll/poll.c @@ -1,5 +1,7 @@ -#include <poll.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_poll + +#include <poll.h> // for nfds_t, poll, pollfd +#include <syscall.h> // for __syscall_3, syscall int poll(struct pollfd fds[], nfds_t nfds, int timeout) { diff --git a/lib/libc/poll/ppoll.c b/lib/libc/poll/ppoll.c index a5ab9d5e..923784da 100644 --- a/lib/libc/poll/ppoll.c +++ b/lib/libc/poll/ppoll.c @@ -1,5 +1,10 @@ -#include <poll.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_ppoll + +#include <poll.h> // for nfds_t, pollfd, ppoll +#include <signal.h> // for sigset_t +#include <syscall.h> // for __syscall_5, syscall + +struct timespec; int ppoll(struct pollfd fds[], nfds_t nfds, const struct timespec *restrict timeout, diff --git a/lib/libc/pwd/getgrgid.c b/lib/libc/pwd/getgrgid.c index 5e825c12..9b3b5af9 100644 --- a/lib/libc/pwd/getgrgid.c +++ b/lib/libc/pwd/getgrgid.c @@ -1,6 +1,7 @@ -#include <pwd.h> -#include <stddef.h> -#include <limits.h> +#include <limits.h> // for LINE_MAX +#include <pwd.h> // for getpwuid_r, getpwuid, passwd +#include <stddef.h> // for NULL +#include <sys/types.h> // for uid_t struct passwd *getpwuid(uid_t uid) { diff --git a/lib/libc/pwd/getgrgid_r.c b/lib/libc/pwd/getgrgid_r.c index 33705fdf..a0d15c74 100644 --- a/lib/libc/pwd/getgrgid_r.c +++ b/lib/libc/pwd/getgrgid_r.c @@ -1,9 +1,10 @@ -#include <pwd.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <errno.h> -#include <limits.h> +#include <errno.h> // for ERANGE, errno +#include <limits.h> // for LINE_MAX +#include <pwd.h> // for passwd, getpwuid_r +#include <stdio.h> // for NULL, fclose, fgets, fopen, FILE +#include <stdlib.h> // for strtoul +#include <string.h> // for strtok, memcpy, strlen +#include <sys/types.h> // for size_t, uid_t, gid_t static char *copy_str(const char *src, char **buf, size_t *buflen) { diff --git a/lib/libc/select/pselect.c b/lib/libc/select/pselect.c index 75d31d87..70f63f2d 100644 --- a/lib/libc/select/pselect.c +++ b/lib/libc/select/pselect.c @@ -1,6 +1,8 @@ -#include <sys/select.h> -#include <stdint.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_pselect6 + +#include <stdint.h> // for uintptr_t +#include <sys/select.h> // for fd_set, pselect, sigset_t +#include <syscall.h> // for __syscall_6, syscall, syscall_arg_t int pselect(int nfds, fd_set *restrict readfds, fd_set *restrict writefds, fd_set *restrict errorfds, const struct timespec *restrict timeout, diff --git a/lib/libc/select/select.c b/lib/libc/select/select.c index 4e9f2f99..58c96348 100644 --- a/lib/libc/select/select.c +++ b/lib/libc/select/select.c @@ -1,5 +1,7 @@ -#include <sys/select.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_pselect6 + +#include <sys/select.h> // for fd_set, select +#include <syscall.h> // for __syscall_6, syscall, syscall_arg_t int select(int nfds, fd_set *restrict readfds, fd_set *restrict writefds, fd_set *restrict errorfds, struct timeval *restrict timeout) diff --git a/lib/libc/sem/semctl.c b/lib/libc/sem/semctl.c index 78a1adf8..45b6d0e5 100644 --- a/lib/libc/sem/semctl.c +++ b/lib/libc/sem/semctl.c @@ -1,8 +1,10 @@ -#include <stdarg.h> -#include <stddef.h> -#include <sys/ipc.h> -#include <sys/sem.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_semctl + +#include <stdarg.h> // for va_arg, va_end, va_list, va_start +#include <stddef.h> // for NULL +#include <sys/ipc.h> // for IPC_SET, IPC_STAT +#include <sys/sem.h> // for GETALL, SETALL, SETVAL, semctl +#include <syscall.h> // for __syscall_4, syscall int semctl(int semid, int semnum, int cmd, ...) { diff --git a/lib/libc/sem/semget.c b/lib/libc/sem/semget.c index 75e1bab9..d3c0b41f 100644 --- a/lib/libc/sem/semget.c +++ b/lib/libc/sem/semget.c @@ -1,5 +1,8 @@ -#include <sys/sem.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_semget + +#include <sys/sem.h> // for semget +#include <sys/types.h> // for key_t +#include <syscall.h> // for __syscall_3, syscall int semget(key_t key, int nsems, int semflg) { diff --git a/lib/libc/sem/semop.c b/lib/libc/sem/semop.c index 82e956dc..6095d445 100644 --- a/lib/libc/sem/semop.c +++ b/lib/libc/sem/semop.c @@ -1,5 +1,7 @@ -#include <sys/sem.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_semop + +#include <sys/sem.h> // for semop, size_t +#include <syscall.h> // for __syscall_3, syscall int semop(int semid, struct sembuf *sops, size_t nsops) { diff --git a/lib/libc/setjmp/siglongjmp.c b/lib/libc/setjmp/siglongjmp.c index 4f39cc37..30be54d0 100644 --- a/lib/libc/setjmp/siglongjmp.c +++ b/lib/libc/setjmp/siglongjmp.c @@ -1,4 +1,4 @@ -#include <setjmp.h> +#include <setjmp.h> // for longjmp, sigjmp_buf, siglongjmp _Noreturn void siglongjmp(sigjmp_buf env, int val) { diff --git a/lib/libc/signal/kill.c b/lib/libc/signal/kill.c index d2a7ae68..65676ed4 100644 --- a/lib/libc/signal/kill.c +++ b/lib/libc/signal/kill.c @@ -1,5 +1,8 @@ -#include <signal.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_kill + +#include <signal.h> // for kill +#include <sys/types.h> // for pid_t +#include <syscall.h> // for __syscall_2, syscall int kill(pid_t pid, int sig) { diff --git a/lib/libc/signal/killpg.c b/lib/libc/signal/killpg.c index 27b7a76a..92434d7c 100644 --- a/lib/libc/signal/killpg.c +++ b/lib/libc/signal/killpg.c @@ -1,6 +1,6 @@ -#include <errno.h> -#include <signal.h> -#include <syscall.h> +#include <errno.h> // for EINVAL, errno +#include <signal.h> // for kill, killpg +#include <sys/types.h> // for pid_t int killpg(pid_t pgrp, int sig) { diff --git a/lib/libc/signal/psiginfo.c b/lib/libc/signal/psiginfo.c index 47e10508..55accdd3 100644 --- a/lib/libc/signal/psiginfo.c +++ b/lib/libc/signal/psiginfo.c @@ -1,4 +1,4 @@ -#include <signal.h> +#include <signal.h> // for psignal, psiginfo, siginfo_t void psiginfo(const siginfo_t *pinfo, const char *message) { diff --git a/lib/libc/signal/psignal.c b/lib/libc/signal/psignal.c index 200b353c..fdf0dc94 100644 --- a/lib/libc/signal/psignal.c +++ b/lib/libc/signal/psignal.c @@ -1,6 +1,6 @@ -#include <stdio.h> -#include <string.h> -#include <signal.h> +#include <signal.h> // for psignal +#include <stdio.h> // for fprintf, stderr +#include <string.h> // for strsignal void psignal(int signum, const char *message) { diff --git a/lib/libc/signal/pthread_kill.c b/lib/libc/signal/pthread_kill.c index 9323a869..d6855c0c 100644 --- a/lib/libc/signal/pthread_kill.c +++ b/lib/libc/signal/pthread_kill.c @@ -1,6 +1,9 @@ -#include <thread.h> -#include <asm-generic/signal.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_tkill +#include "errno.h" // for EINVAL + +#include <asm-generic/signal.h> // for _NSIG +#include <syscall.h> // for __syscall_2, syscall +#include <thread.h> // for __thread_self typedef struct __thread_self *pthread_t; diff --git a/lib/libc/signal/pthread_sigmask.c b/lib/libc/signal/pthread_sigmask.c index 4fcc278f..5e657a6e 100644 --- a/lib/libc/signal/pthread_sigmask.c +++ b/lib/libc/signal/pthread_sigmask.c @@ -1,7 +1,13 @@ -#include <errno.h> -#include <asm-generic/signal.h> -#include <libc.h> -#include <stddef.h> +#define __ASSEMBLY__ +#include <asm-generic/signal.h> // for SIGRTMIN + +#undef __ASSEMBLY__ + +#include <errno.h> // for errno +#include <libc.h> // for unlikely +#include <stddef.h> // for NULL + +typedef __UINT64_TYPE__ sigset_t; int sigdelset(sigset_t *, int); int sigismember(const sigset_t *, int); diff --git a/lib/libc/signal/raise.c b/lib/libc/signal/raise.c index 3bdbc9cc..32dc1c6b 100644 --- a/lib/libc/signal/raise.c +++ b/lib/libc/signal/raise.c @@ -1,5 +1,5 @@ -#include <unistd.h> -#include <signal.h> +#include <signal.h> // for kill, raise +#include <unistd.h> // for getpid int raise(int sig) { diff --git a/lib/libc/signal/sig2str.c b/lib/libc/signal/sig2str.c index 2532d539..eec1c805 100644 --- a/lib/libc/signal/sig2str.c +++ b/lib/libc/signal/sig2str.c @@ -1,7 +1,7 @@ -#include <stdio.h> -#include <string.h> -#include <asm-generic/signal.h> -#include <__signal.h> +#include <__signal.h> // for __sys_signame +#include <asm-generic/signal.h> // for SIGRTMAX, SIGRTMIN, SIGHUP, SIGSYS +#include <stdio.h> // for snprintf +#include <string.h> // for strlcpy int sig2str(int signum, char *str) { diff --git a/lib/libc/signal/sigaction.c b/lib/libc/signal/sigaction.c index f8377ebb..6039574a 100644 --- a/lib/libc/signal/sigaction.c +++ b/lib/libc/signal/sigaction.c @@ -1,5 +1,7 @@ -#include <signal.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_rt_sigaction + +#include <signal.h> // for sigaction, sigset_t +#include <syscall.h> // for __syscall_4, syscall int sigaction(int sig, const struct sigaction *restrict act, struct sigaction *restrict oact) diff --git a/lib/libc/signal/sigaddset.c b/lib/libc/signal/sigaddset.c index 33e74bd0..5606989d 100644 --- a/lib/libc/signal/sigaddset.c +++ b/lib/libc/signal/sigaddset.c @@ -1,4 +1,4 @@ -#include <signal.h> +#include <signal.h> // for sigaddset, sigset_t int sigaddset(sigset_t *set, int signo) { diff --git a/lib/libc/signal/sigemptyset.c b/lib/libc/signal/sigemptyset.c index 6552bf45..a5c8958e 100644 --- a/lib/libc/signal/sigemptyset.c +++ b/lib/libc/signal/sigemptyset.c @@ -1,4 +1,4 @@ -#include <signal.h> +#include <signal.h> // for sigemptyset, sigset_t int sigemptyset(sigset_t *set) { diff --git a/lib/libc/signal/sigismember.c b/lib/libc/signal/sigismember.c index 8adf5fab..0b73e6ee 100644 --- a/lib/libc/signal/sigismember.c +++ b/lib/libc/signal/sigismember.c @@ -1,4 +1,4 @@ -#include <asm-generic/signal.h> +#include <asm-generic/signal.h> // for _NSIG typedef __UINT64_TYPE__ __sigset_t; diff --git a/lib/libc/signal/sigpending.c b/lib/libc/signal/sigpending.c index b57f4adf..b0b4e92c 100644 --- a/lib/libc/signal/sigpending.c +++ b/lib/libc/signal/sigpending.c @@ -1,5 +1,7 @@ -#include <signal.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_rt_sigpending + +#include <signal.h> // for sigpending, sigset_t +#include <syscall.h> // for __syscall_1, syscall int sigpending(sigset_t *set) { diff --git a/lib/libc/signal/sigprocmask.c b/lib/libc/signal/sigprocmask.c index 54063b9d..f74d5774 100644 --- a/lib/libc/signal/sigprocmask.c +++ b/lib/libc/signal/sigprocmask.c @@ -1,5 +1,7 @@ -#include <signal.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_rt_sigprocmask + +#include <signal.h> // for sigset_t, sigprocmask +#include <syscall.h> // for __syscall_4, syscall int sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict oset) { diff --git a/lib/libc/signal/sigqueue.c b/lib/libc/signal/sigqueue.c index 9e5b6ddd..b38725cd 100644 --- a/lib/libc/signal/sigqueue.c +++ b/lib/libc/signal/sigqueue.c @@ -1,5 +1,5 @@ -#include <signal.h> -#include <errno.h> +#include <errno.h> // for errno +#include <signal.h> // for pthread_sigmask, sigset_t, sigprocmask int sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old) { diff --git a/lib/libc/signal/sigsuspend.c b/lib/libc/signal/sigsuspend.c index 1e6b88a6..93701d55 100644 --- a/lib/libc/signal/sigsuspend.c +++ b/lib/libc/signal/sigsuspend.c @@ -1,5 +1,7 @@ -#include <signal.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_rt_sigsuspend + +#include <signal.h> // for sigset_t, sigsuspend +#include <syscall.h> // for __syscall_2, syscall int sigsuspend(const sigset_t *sigmask) { diff --git a/lib/libc/signal/sigtimedwait.c b/lib/libc/signal/sigtimedwait.c index d55a4310..dc85e5d1 100644 --- a/lib/libc/signal/sigtimedwait.c +++ b/lib/libc/signal/sigtimedwait.c @@ -1,5 +1,9 @@ -#include <signal.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_rt_sigtimedwait + +#include <signal.h> // for siginfo_t, sigset_t, sigtimedwait +#include <syscall.h> // for __syscall_4, syscall + +struct timespec; #define _NSIG 64 diff --git a/lib/libc/signal/sigwait.c b/lib/libc/signal/sigwait.c index 59b0dd6c..61067aeb 100644 --- a/lib/libc/signal/sigwait.c +++ b/lib/libc/signal/sigwait.c @@ -1,4 +1,4 @@ -#include <signal.h> +#include <signal.h> // for sigtimedwait, siginfo_t, sigset_t, sigwait int sigwait(const sigset_t *restrict mask, int *restrict sig) { diff --git a/lib/libc/signal/sigwaitinfo.c b/lib/libc/signal/sigwaitinfo.c index bb51f8b5..a1533120 100644 --- a/lib/libc/signal/sigwaitinfo.c +++ b/lib/libc/signal/sigwaitinfo.c @@ -1,4 +1,4 @@ -#include <signal.h> +#include <signal.h> // for sigtimedwait, siginfo_t, sigset_t, sigwaitinfo int sigwaitinfo(const sigset_t *restrict mask, siginfo_t *restrict si) { diff --git a/lib/libc/signal/str2sig.c b/lib/libc/signal/str2sig.c index 288948d7..77796c4d 100644 --- a/lib/libc/signal/str2sig.c +++ b/lib/libc/signal/str2sig.c @@ -1,9 +1,9 @@ -#include <__signal.h> -#include <errno.h> -#include <stdlib.h> -#include <string.h> -#include <stdbool.h> -#include <asm-generic/signal.h> +#include <__signal.h> // for __sys_signame +#include <asm-generic/signal.h> // for SIGRTMAX, SIGRTMIN, SIGHUP, SIGSYS +#include <errno.h> // for errno +#include <stdbool.h> // for bool +#include <stdlib.h> // for strtol, NULL +#include <string.h> // for strcmp, strncmp, size_t int str2sig(const char *restrict str, int *restrict pnum) { diff --git a/lib/libc/socket/accept.c b/lib/libc/socket/accept.c index 61c469c8..f3ec738d 100644 --- a/lib/libc/socket/accept.c +++ b/lib/libc/socket/accept.c @@ -1,5 +1,7 @@ -#include <sys/socket.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_accept + +#include <sys/socket.h> // for accept, socklen_t +#include <syscall.h> // for __syscall_3, syscall int accept(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len) diff --git a/lib/libc/socket/accept4.c b/lib/libc/socket/accept4.c index 8171098b..88c761f5 100644 --- a/lib/libc/socket/accept4.c +++ b/lib/libc/socket/accept4.c @@ -1,5 +1,7 @@ -#include <sys/socket.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_accept4 + +#include <sys/socket.h> // for accept4, socklen_t +#include <syscall.h> // for __syscall_4, syscall int accept4(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len, int flag) diff --git a/lib/libc/socket/bind.c b/lib/libc/socket/bind.c index 111ac321..ef39d03b 100644 --- a/lib/libc/socket/bind.c +++ b/lib/libc/socket/bind.c @@ -1,5 +1,7 @@ -#include <sys/socket.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_bind + +#include <sys/socket.h> // for bind, socklen_t +#include <syscall.h> // for __syscall_3, syscall int bind(int socket, const struct sockaddr *address, socklen_t address_len) { diff --git a/lib/libc/socket/connect.c b/lib/libc/socket/connect.c index fc4502cb..19c9ef95 100644 --- a/lib/libc/socket/connect.c +++ b/lib/libc/socket/connect.c @@ -1,5 +1,7 @@ -#include <sys/socket.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_connect + +#include <sys/socket.h> // for connect, socklen_t +#include <syscall.h> // for __syscall_3, syscall int connect(int socket, const struct sockaddr *address, socklen_t address_len) { diff --git a/lib/libc/socket/getpeername.c b/lib/libc/socket/getpeername.c index 4b694220..f1bc35e8 100644 --- a/lib/libc/socket/getpeername.c +++ b/lib/libc/socket/getpeername.c @@ -1,5 +1,7 @@ -#include <sys/socket.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_getpeername + +#include <sys/socket.h> // for getpeername, socklen_t +#include <syscall.h> // for __syscall_3, syscall int getpeername(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len) diff --git a/lib/libc/socket/getsockname.c b/lib/libc/socket/getsockname.c index d8b356fb..b8422261 100644 --- a/lib/libc/socket/getsockname.c +++ b/lib/libc/socket/getsockname.c @@ -1,5 +1,7 @@ -#include <sys/socket.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_getsockname + +#include <sys/socket.h> // for getsockname, socklen_t +#include <syscall.h> // for __syscall_3, syscall int getsockname(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len) diff --git a/lib/libc/socket/getsockopt.c b/lib/libc/socket/getsockopt.c index 2ab56774..0c9db0ad 100644 --- a/lib/libc/socket/getsockopt.c +++ b/lib/libc/socket/getsockopt.c @@ -1,5 +1,7 @@ -#include <sys/socket.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_getsockopt + +#include <sys/socket.h> // for getsockopt, socklen_t +#include <syscall.h> // for __syscall_5, syscall int getsockopt(int socket, int level, int option_name, void *restrict option_value, socklen_t *restrict option_len) diff --git a/lib/libc/socket/listen.c b/lib/libc/socket/listen.c index 2866fe27..a204ba28 100644 --- a/lib/libc/socket/listen.c +++ b/lib/libc/socket/listen.c @@ -1,5 +1,7 @@ -#include <sys/socket.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_listen + +#include <sys/socket.h> // for listen +#include <syscall.h> // for __syscall_2, syscall int listen(int socket, int backlog) { diff --git a/lib/libc/socket/recv.c b/lib/libc/socket/recv.c index 87bec811..884b753f 100644 --- a/lib/libc/socket/recv.c +++ b/lib/libc/socket/recv.c @@ -1,5 +1,8 @@ -#include <sys/socket.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_recvfrom + +#include <sys/socket.h> // for recv +#include <sys/types.h> // for size_t, ssize_t +#include <syscall.h> // for __syscall_6, syscall ssize_t recv(int socket, void *buffer, size_t length, int flags) { diff --git a/lib/libc/socket/recvfrom.c b/lib/libc/socket/recvfrom.c index a3faa0bb..d37089d9 100644 --- a/lib/libc/socket/recvfrom.c +++ b/lib/libc/socket/recvfrom.c @@ -1,5 +1,8 @@ -#include <sys/socket.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_recvfrom + +#include <sys/socket.h> // for recvfrom, socklen_t +#include <sys/types.h> // for size_t, ssize_t +#include <syscall.h> // for __syscall_6, syscall ssize_t recvfrom(int socket, void *restrict buffer, size_t length, int flags, struct sockaddr *restrict address, diff --git a/lib/libc/socket/recvmsg.c b/lib/libc/socket/recvmsg.c index 29183f35..1b2cfdf1 100644 --- a/lib/libc/socket/recvmsg.c +++ b/lib/libc/socket/recvmsg.c @@ -1,5 +1,8 @@ -#include <sys/socket.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_recvmsg + +#include <sys/socket.h> // for recvmsg +#include <sys/types.h> // for ssize_t +#include <syscall.h> // for __syscall_3, syscall ssize_t recvmsg(int socket, struct msghdr *message, int flags) { diff --git a/lib/libc/socket/send.c b/lib/libc/socket/send.c index a2760a2f..7ba42525 100644 --- a/lib/libc/socket/send.c +++ b/lib/libc/socket/send.c @@ -1,5 +1,8 @@ -#include <sys/socket.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_sendto + +#include <sys/socket.h> // for send +#include <sys/types.h> // for size_t, ssize_t +#include <syscall.h> // for __syscall_6, syscall ssize_t send(int socket, const void *buffer, size_t length, int flags) { diff --git a/lib/libc/socket/sendmsg.c b/lib/libc/socket/sendmsg.c index 6414021c..b977f7da 100644 --- a/lib/libc/socket/sendmsg.c +++ b/lib/libc/socket/sendmsg.c @@ -1,5 +1,8 @@ -#include <syscall.h> -#include <sys/socket.h> +#include "asm/unistd_64.h" // for __NR_sendmsg + +#include <sys/socket.h> // for sendmsg +#include <sys/types.h> // for ssize_t +#include <syscall.h> // for __syscall_3, syscall ssize_t sendmsg(int socket, const struct msghdr *message, int flags) { diff --git a/lib/libc/socket/sendto.c b/lib/libc/socket/sendto.c index f9628f50..97376037 100644 --- a/lib/libc/socket/sendto.c +++ b/lib/libc/socket/sendto.c @@ -1,5 +1,8 @@ -#include <sys/socket.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_sendto + +#include <sys/socket.h> // for sendto, socklen_t +#include <sys/types.h> // for size_t, ssize_t +#include <syscall.h> // for __syscall_6, syscall ssize_t sendto(int socket, const void *message, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len) diff --git a/lib/libc/socket/setsockopt.c b/lib/libc/socket/setsockopt.c index 8f25bab4..740b2d08 100644 --- a/lib/libc/socket/setsockopt.c +++ b/lib/libc/socket/setsockopt.c @@ -1,5 +1,7 @@ -#include <sys/socket.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_setsockopt + +#include <sys/socket.h> // for setsockopt, socklen_t +#include <syscall.h> // for __syscall_5, syscall int setsockopt(int socket, int level, int option_name, const void *option_value, socklen_t option_len) diff --git a/lib/libc/socket/shutdown.c b/lib/libc/socket/shutdown.c index 96c8053c..7fcae79b 100644 --- a/lib/libc/socket/shutdown.c +++ b/lib/libc/socket/shutdown.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_shutdown + +#include <syscall.h> // for __syscall_2, syscall int shutdown(int socket, int how) { diff --git a/lib/libc/socket/sockatmark.c b/lib/libc/socket/sockatmark.c index f7178aa0..4ae64d95 100644 --- a/lib/libc/socket/sockatmark.c +++ b/lib/libc/socket/sockatmark.c @@ -1,5 +1,7 @@ -#include <syscall.h> -#include <asm-generic/sockios.h> +#include "asm/unistd_64.h" // for __NR_ioctl + +#include <asm-generic/sockios.h> // for SIOCATMARK +#include <syscall.h> // for __syscall_3, syscall int sockatmark(int s) { diff --git a/lib/libc/socket/socket.c b/lib/libc/socket/socket.c index 34b5d67b..09847ff9 100644 --- a/lib/libc/socket/socket.c +++ b/lib/libc/socket/socket.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_socket + +#include <syscall.h> // for __syscall_3, syscall int socket(int domain, int type, int protocol) { diff --git a/lib/libc/socket/socketpair.c b/lib/libc/socket/socketpair.c index 6e78b30b..e116c645 100644 --- a/lib/libc/socket/socketpair.c +++ b/lib/libc/socket/socketpair.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_socketpair + +#include <syscall.h> // for __syscall_4, syscall int socketpair(int domain, int type, int protocol, int socket_vector[2]) { diff --git a/lib/libc/stat/chmod.c b/lib/libc/stat/chmod.c index 6b7283e2..f204df83 100644 --- a/lib/libc/stat/chmod.c +++ b/lib/libc/stat/chmod.c @@ -1,5 +1,8 @@ -#include <sys/stat.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_chmod + +#include <sys/stat.h> // for chmod +#include <sys/types.h> // for mode_t +#include <syscall.h> // for __syscall_2, syscall int chmod(const char *path, mode_t mode) { diff --git a/lib/libc/stat/fchmod.c b/lib/libc/stat/fchmod.c index 22593fd6..c7b0b0f3 100644 --- a/lib/libc/stat/fchmod.c +++ b/lib/libc/stat/fchmod.c @@ -1,5 +1,8 @@ -#include <sys/stat.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_fchmod + +#include <sys/stat.h> // for fchmod +#include <sys/types.h> // for mode_t +#include <syscall.h> // for __syscall_2, syscall int fchmod(int fildes, mode_t mode) { diff --git a/lib/libc/stat/fchmodat.c b/lib/libc/stat/fchmodat.c index 71a3c0c5..30c8230c 100644 --- a/lib/libc/stat/fchmodat.c +++ b/lib/libc/stat/fchmodat.c @@ -1,5 +1,8 @@ -#include <sys/stat.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_fchmodat2 + +#include <sys/stat.h> // for fchmodat +#include <sys/types.h> // for mode_t +#include <syscall.h> // for __syscall_4, syscall int fchmodat(int fd, const char *path, mode_t mode, int flag) { diff --git a/lib/libc/stat/fstat.c b/lib/libc/stat/fstat.c index 7a9fb4e4..9c3a9df2 100644 --- a/lib/libc/stat/fstat.c +++ b/lib/libc/stat/fstat.c @@ -1,6 +1,4 @@ -#include <fcntl.h> -#include <sys/stat.h> -#include <syscall.h> +#include <sys/stat.h> // for fstatat, fstat int fstat(int fildes, struct stat *buf) { diff --git a/lib/libc/stat/fstatat.c b/lib/libc/stat/fstatat.c index d7aecbc5..c36ba3e3 100644 --- a/lib/libc/stat/fstatat.c +++ b/lib/libc/stat/fstatat.c @@ -1,8 +1,12 @@ -#include <linux/stat.h> +#include <linux/stat.h> // for statx, statx_timestamp, STATX_BASIC_STATS +#include <time.h> // for timespec + #define __BITS_STAT_H_ -#include <bits/stat.h> -#undef __BITS_STAT_H_ -#include <syscall.h> + +#include "asm/unistd_64.h" // for __NR_statx + +#include <bits/stat.h> // for stat +#include <syscall.h> // for __syscall_5, syscall #define makedev(major, minor) \ ((((major) & 0xfffff000ULL) << 32) | \ diff --git a/lib/libc/stat/futimens.c b/lib/libc/stat/futimens.c index 38c6876f..f3bb425d 100644 --- a/lib/libc/stat/futimens.c +++ b/lib/libc/stat/futimens.c @@ -1,4 +1,6 @@ -#include <sys/stat.h> +#define __BITS_STAT_H_ +#include <bits/stat.h> // for timespec +#include <sys/stat.h> // for utimensat, futimens int futimens(int fd, const struct timespec times[2]) { diff --git a/lib/libc/stat/lstat.c b/lib/libc/stat/lstat.c index a188f78d..77ded510 100644 --- a/lib/libc/stat/lstat.c +++ b/lib/libc/stat/lstat.c @@ -1,5 +1,5 @@ -#include <fcntl.h> -#include <sys/stat.h> +#include <fcntl.h> // for AT_FDCWD, AT_SYMLINK_NOFOLLOW +#include <sys/stat.h> // for fstatat, lstat int lstat(const char *restrict path, struct stat *restrict buf) { diff --git a/lib/libc/stat/mkdir.c b/lib/libc/stat/mkdir.c index 1f97fb3f..58de4a89 100644 --- a/lib/libc/stat/mkdir.c +++ b/lib/libc/stat/mkdir.c @@ -1,6 +1,8 @@ -#include <fcntl.h> -#include <syscall.h> -#include <sys/stat.h> +#include "asm/unistd_64.h" // for __NR_mkdir + +#include <sys/stat.h> // for mkdir +#include <sys/types.h> // for mode_t +#include <syscall.h> // for __syscall_2, syscall int mkdir(const char *path, mode_t mode) { diff --git a/lib/libc/stat/mkdirat.c b/lib/libc/stat/mkdirat.c index d129008b..49a4cecf 100644 --- a/lib/libc/stat/mkdirat.c +++ b/lib/libc/stat/mkdirat.c @@ -1,6 +1,8 @@ -#include <fcntl.h> -#include <syscall.h> -#include <sys/stat.h> +#include "asm/unistd_64.h" // for __NR_mkdirat + +#include <sys/stat.h> // for mkdirat +#include <sys/types.h> // for mode_t +#include <syscall.h> // for __syscall_3, syscall int mkdirat(int fd, const char *path, mode_t mode) { diff --git a/lib/libc/stat/mkfifo.c b/lib/libc/stat/mkfifo.c index 60efcf73..6c64fe35 100644 --- a/lib/libc/stat/mkfifo.c +++ b/lib/libc/stat/mkfifo.c @@ -1,4 +1,5 @@ -#include <sys/stat.h> +#include <sys/stat.h> // for mknod, S_IFIFO, mkfifo +#include <sys/types.h> // for mode_t int mkfifo(const char *path, mode_t mode) { diff --git a/lib/libc/stat/mkfifoat.c b/lib/libc/stat/mkfifoat.c index d3a1f970..d4023c63 100644 --- a/lib/libc/stat/mkfifoat.c +++ b/lib/libc/stat/mkfifoat.c @@ -1,4 +1,5 @@ -#include <sys/stat.h> +#include <sys/stat.h> // for mknodat, S_IFIFO, mkfifoat +#include <sys/types.h> // for mode_t int mkfifoat(int fd, const char *path, mode_t mode) { diff --git a/lib/libc/stat/mknod.c b/lib/libc/stat/mknod.c index 1a4a5c6c..b8efed01 100644 --- a/lib/libc/stat/mknod.c +++ b/lib/libc/stat/mknod.c @@ -1,6 +1,9 @@ -#include <fcntl.h> -#include <syscall.h> -#include <sys/stat.h> +#include "asm/unistd_64.h" // for __NR_mknodat + +#include <fcntl.h> // for AT_FDCWD +#include <sys/stat.h> // for mknod +#include <sys/types.h> // for dev_t, mode_t +#include <syscall.h> // for __syscall_4, syscall int mknod(const char *path, mode_t mode, dev_t dev) { diff --git a/lib/libc/stat/mknodat.c b/lib/libc/stat/mknodat.c index 9967248e..5ac50f5c 100644 --- a/lib/libc/stat/mknodat.c +++ b/lib/libc/stat/mknodat.c @@ -1,5 +1,8 @@ -#include <syscall.h> -#include <sys/stat.h> +#include "asm/unistd_64.h" // for __NR_mknodat + +#include <sys/stat.h> // for mknodat +#include <sys/types.h> // for dev_t, mode_t +#include <syscall.h> // for __syscall_4, syscall int mknodat(int fd, const char *path, mode_t mode, dev_t dev) { diff --git a/lib/libc/stat/stat.c b/lib/libc/stat/stat.c index 95bdf73d..d839f0eb 100644 --- a/lib/libc/stat/stat.c +++ b/lib/libc/stat/stat.c @@ -1,5 +1,5 @@ -#include <fcntl.h> -#include <sys/stat.h> +#include <fcntl.h> // for AT_FDCWD +#include <sys/stat.h> // for fstatat, stat int stat(const char *restrict path, struct stat *restrict buf) { diff --git a/lib/libc/stat/umask.c b/lib/libc/stat/umask.c index 2724317a..f9026df8 100644 --- a/lib/libc/stat/umask.c +++ b/lib/libc/stat/umask.c @@ -1,5 +1,8 @@ -#include <sys/stat.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_umask + +#include <sys/stat.h> // for umask +#include <sys/types.h> // for mode_t +#include <syscall.h> // for __syscall_1, syscall mode_t umask(mode_t cmask) { diff --git a/lib/libc/stat/utimensat.c b/lib/libc/stat/utimensat.c index d51611a3..5193a819 100644 --- a/lib/libc/stat/utimensat.c +++ b/lib/libc/stat/utimensat.c @@ -1,5 +1,7 @@ -#include <time.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_utimensat + +#include <syscall.h> // for __syscall_4, syscall +#include <time.h> // for timespec int utimensat(int fd, const char *path, const struct timespec times[2], int flag) diff --git a/lib/libc/statvfs/fstatvfs.c b/lib/libc/statvfs/fstatvfs.c index 048db737..d48a92f0 100644 --- a/lib/libc/statvfs/fstatvfs.c +++ b/lib/libc/statvfs/fstatvfs.c @@ -1,6 +1,8 @@ -#include <__statvfs.h> -#include <syscall.h> -#include <asm-generic/statfs.h> +#include "asm/unistd_64.h" // for __NR_fstatfs + +#include <__statvfs.h> // for __statvfs +#include <asm-generic/statfs.h> // for statfs +#include <syscall.h> // for __syscall_2, syscall int fstatvfs(int fildes, struct __statvfs *buf) { diff --git a/lib/libc/statvfs/statvfs.c b/lib/libc/statvfs/statvfs.c index 3a7c1f3e..93ab5afb 100644 --- a/lib/libc/statvfs/statvfs.c +++ b/lib/libc/statvfs/statvfs.c @@ -1,6 +1,8 @@ -#include <__statvfs.h> -#include <syscall.h> -#include <asm-generic/statfs.h> +#include "asm/unistd_64.h" // for __NR_statfs + +#include <__statvfs.h> // for __statvfs +#include <asm-generic/statfs.h> // for statfs +#include <syscall.h> // for __syscall_2, syscall int statvfs(const char *restrict path, struct __statvfs *restrict buf) { diff --git a/lib/libc/stdio/asprintf.c b/lib/libc/stdio/asprintf.c index b868cce1..c82ef019 100644 --- a/lib/libc/stdio/asprintf.c +++ b/lib/libc/stdio/asprintf.c @@ -1,5 +1,5 @@ -#include <stdio.h> -#include <stdarg.h> +#include <stdarg.h> // for va_end, va_start +#include <stdio.h> // for vasprintf, asprintf, va_list int asprintf(char **restrict ptr, const char *restrict format, ...) { diff --git a/lib/libc/stdio/clearerr.c b/lib/libc/stdio/clearerr.c index a49e5c2d..87d733ae 100644 --- a/lib/libc/stdio/clearerr.c +++ b/lib/libc/stdio/clearerr.c @@ -1,10 +1,13 @@ -#include <stdio.h> -#include <io.h> +#include "__stdio.h" // for _IO_EOF, _IO_ERR +#include "stddef.h" // for NULL + +#include <libc.h> // for __IMPL +#include <stdio.h> // for FILE, clearerr void clearerr(FILE *stream) { if (stream == NULL) return; - stream->flags &= ~(_IO_ERR | _IO_EOF); + __IMPL(stream)->flags &= ~(_IO_ERR | _IO_EOF); } diff --git a/lib/libc/stdio/dprintf.c b/lib/libc/stdio/dprintf.c index 10877b22..f9a73654 100644 --- a/lib/libc/stdio/dprintf.c +++ b/lib/libc/stdio/dprintf.c @@ -1,5 +1,5 @@ -#include <stdio.h> -#include <stdarg.h> +#include <stdarg.h> // for va_end, va_start +#include <stdio.h> // for vdprintf, dprintf, va_list int dprintf(int fildes, const char *restrict format, ...) { diff --git a/lib/libc/stdio/dtoa.c b/lib/libc/stdio/dtoa.c index 9b0eea99..faf4bd8c 100644 --- a/lib/libc/stdio/dtoa.c +++ b/lib/libc/stdio/dtoa.c @@ -210,17 +210,15 @@ * used for input more than STRTOD_DIGLIM digits long (default 40). */ -#include <thread.h> -#include <threads.h> -#include <atomic.h> +#include <atomic.h> // for LIBC_LOCK, LIBC_UNLOCK +#include <libc.h> // for __IMPL +#include <threads.h> // for thrd_current static atomic_flag dtoa_lock[2] = { ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT }; #define ACQUIRE_DTOA_LOCK(n) LIBC_LOCK(dtoa_lock[(n)]) #define FREE_DTOA_LOCK(n) LIBC_UNLOCK(dtoa_lock[(n)]) -#define dtoa_get_threadno() thrd_current()->tid - #define IEEE_8087 #define Honor_FLT_ROUNDS #define MULTIPLE_THREADS @@ -233,8 +231,10 @@ typedef unsigned Long ULong; #endif #ifdef DEBUG -#include <assert.h> #include "stdio.h" + +#include <assert.h> + #define Bug(x) \ { \ fprintf(stderr, "%s\n", x); \ @@ -247,8 +247,11 @@ int dtoa_stats[7]; /* strtod_{64,96,bigcomp},dtoa_{exact,64,96,bigcomp} */ #define Debug(x) /*nothing*/ #endif -#include "stdlib.h" -#include "string.h" +#include "__stdio.h" // for size_t +#include "bits/fenv.h" // for FE_DOWNWARD, FE_TOWARDZERO, FE_UPWARD +#include "stdatomic.h" // for ATOMIC_FLAG_INIT, atomic_flag +#include "stdlib.h" // for malloc, free, realloc, strtod +#include "string.h" // for memcpy, memset #ifdef USE_LOCALE #include "locale.h" @@ -256,7 +259,7 @@ int dtoa_stats[7]; /* strtod_{64,96,bigcomp},dtoa_{exact,64,96,bigcomp} */ #ifdef Honor_FLT_ROUNDS #ifndef Trust_FLT_ROUNDS -#include <fenv.h> +#include <fenv.h> // for fegetround #endif #endif @@ -310,7 +313,7 @@ static double private_mem[PRIVATE_mem], *pmem_next = private_mem; #define NO_STRTOD_BIGCOMP #endif -#include "errno.h" +#include "errno.h" // for errno, ERANGE #ifdef NO_ERRNO /*{*/ #undef Set_errno @@ -350,13 +353,9 @@ static double private_mem[PRIVATE_mem], *pmem_next = private_mem; #define LONG_MAX 2147483647 #endif -#else /* ifndef Bad_float_h */ -#include "float.h" -#endif /* Bad_float_h */ - -#ifndef __MATH_H__ -#include "math.h" -#endif +#else /* ifndef Bad_float_h */ +#include "float.h" // for DBL_MAX_EXP, FLT_RADIX, DBL_DIG, FLT_ROUNDS +#endif /* Bad_float_h */ #ifdef __cplusplus extern "C" { @@ -1557,7 +1556,8 @@ void set_max_dtoa_threads(unsigned int n) static ThInfo *get_TI(void) { - unsigned int thno = dtoa_get_threadno(); + unsigned int thno = __IMPL(thrd_current())->tid; + if (thno < maxthreads) return TI1 + thno; if (thno == 0) diff --git a/lib/libc/stdio/fclose.c b/lib/libc/stdio/fclose.c index 8f0b4cef..8b0586c6 100644 --- a/lib/libc/stdio/fclose.c +++ b/lib/libc/stdio/fclose.c @@ -1,6 +1,6 @@ -#include <io.h> -#include <stdio.h> -#include <unistd.h> +#include <libc.h> // for __IMPL +#include <stdio.h> // for fflush, FILE, fclose, stderr, stdin, stdout +#include <unistd.h> // for close int fclose(FILE *stream) { @@ -8,7 +8,7 @@ int fclose(FILE *stream) return -1; if (stream != stdin && stream != stdout && stream != stderr) { - if (close(stream->fd) == -1) + if (close(__IMPL(stream)->fd) == -1) return -1; } diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c index 23f94843..f762a83d 100644 --- a/lib/libc/stdio/fdopen.c +++ b/lib/libc/stdio/fdopen.c @@ -1,7 +1,12 @@ -#include <io.h> -#include <libc.h> -#include <unistd.h> -#include <stdio.h> +#include "__stdio.h" // for __libc_fadd +#include "features.h" // for __weak +#include "stdatomic.h" // for atomic_flag_clear +#include "stddef.h" // for NULL + +#include <libc.h> // for __IMPL +#include <stdio.h> // for FILE, _IONBF, SEEK_END, _IOLBF, fdopen +#include <stdlib.h> // for calloc, free +#include <unistd.h> // for lseek, off_t __weak void __stdio_cleanup(void) { @@ -9,31 +14,32 @@ __weak void __stdio_cleanup(void) FILE *fdopen(int fildes, const char *mode) { - FILE *fp; + FILE *stream; if (mode == NULL || (mode[0] != 'r' && mode[0] != 'w' && mode[0] != 'a')) { return NULL; } - if ((fp = calloc(1, sizeof(FILE))) == NULL) + if ((stream = calloc(1, sizeof(FILE))) == NULL) return NULL; - fp->fd = fildes; - atomic_flag_clear(&fp->lock); + __IMPL(stream)->fd = fildes; + atomic_flag_clear(&__IMPL(stream)->lock); if (mode[0] == 'r') { - fp->type = _IONBF; + __IMPL(stream)->type = _IONBF; } else if (mode[0] == 'w') { - fp->type = _IOLBF; + __IMPL(stream)->type = _IOLBF; } else if (mode[0] == 'a') { - fp->type = _IONBF; + __IMPL(stream)->type = _IONBF; + off_t offset = lseek(fildes, 0, SEEK_END); if (offset == (off_t)-1) { - free(fp); + free(stream); return NULL; } } - __libc_fadd(fp); - return fp; + __libc_fadd(stream); + return stream; } diff --git a/lib/libc/stdio/feof.c b/lib/libc/stdio/feof.c index 0b3eb1ec..f8478d03 100644 --- a/lib/libc/stdio/feof.c +++ b/lib/libc/stdio/feof.c @@ -1,10 +1,12 @@ -#include <stdio.h> -#include <io.h> +#include "stddef.h" // for NULL + +#include <libc.h> // for __IMPL +#include <stdio.h> // for FILE, feof int feof(FILE *stream) { - if (!stream) + if (stream == NULL) return 0; - return stream->eof; + return __IMPL(stream)->eof; } diff --git a/lib/libc/stdio/ferror.c b/lib/libc/stdio/ferror.c index b4e438b3..69ef439d 100644 --- a/lib/libc/stdio/ferror.c +++ b/lib/libc/stdio/ferror.c @@ -1,10 +1,13 @@ -#include <stdio.h> -#include <io.h> +#include "__stdio.h" // for _IO_ERR +#include "stddef.h" // for NULL + +#include <libc.h> // for __IMPL +#include <stdio.h> // for FILE, ferror int ferror(FILE *stream) { - if (!stream) + if (stream == NULL) return 0; - return (stream->flags & _IO_ERR) != 0; + return (__IMPL(stream)->flags & _IO_ERR) != 0; } diff --git a/lib/libc/stdio/fflush.c b/lib/libc/stdio/fflush.c index 9af9ca2d..001e3139 100644 --- a/lib/libc/stdio/fflush.c +++ b/lib/libc/stdio/fflush.c @@ -1,85 +1,77 @@ -#include <stdio.h> -#include <unistd.h> -#include <atomic.h> -#include <io.h> -#include <errno.h> -#include <string.h> -#include <fcntl.h> +#include "__stdio.h" // for _IO_ERR +#include "stddef.h" // for NULL + +#include <atomic.h> // for LIBC_UNLOCK, LIBC_LOCK +#include <errno.h> // for errno, EBADF, EIO +#include <fcntl.h> // for O_ACCMODE, O_RDONLY +#include <libc.h> // for __IMPL +#include <stdio.h> // for EOF, FILE, fflush +#include <string.h> // for memmove +#include <unistd.h> // for size_t, write, ssize_t int fflush(FILE *stream) { - // Handle NULL stream - flush all open streams if (stream == NULL) { // TODO: Implement flushing all open streams // For now, just return success return 0; } - // Nothing to flush if buffer is empty - if (stream->buf_len == 0) { + if (__IMPL(stream)->buf_len == 0) { return 0; } - // Handle special case of invalid file descriptor - if (stream->fd == -1) { + if (__IMPL(stream)->fd == -1) { stream->buf_len = 0; return 0; } - // Check if stream is in error state - if (stream->flags & _IO_ERR) { + if (__IMPL(stream)->flags & _IO_ERR) { errno = EIO; return EOF; } - // Check if stream is writable - if ((stream->flags & O_ACCMODE) == O_RDONLY) { + if ((__IMPL(stream)->flags & O_ACCMODE) == O_RDONLY) { errno = EBADF; return EOF; } - LIBC_LOCK(stream->lock); + LIBC_LOCK(__IMPL(stream)->lock); - size_t bytes_to_write = stream->buf_len; + size_t bytes_to_write = __IMPL(stream)->buf_len; size_t total_written = 0; - char *buf_ptr = stream->buf; + char *buf_ptr = __IMPL(stream)->buf; - // Write all buffered data while (total_written < bytes_to_write) { - ssize_t result = write(stream->fd, buf_ptr + total_written, + ssize_t result = write(__IMPL(stream)->fd, + buf_ptr + total_written, bytes_to_write - total_written); if (result < 0) { - // Write error occurred - stream->flags |= _IO_ERR; - LIBC_UNLOCK(stream->lock); + __IMPL(stream)->flags |= _IO_ERR; + LIBC_UNLOCK(__IMPL(stream)->lock); return EOF; } if (result == 0) { - // No progress made (shouldn't happen with regular - // files) break; } total_written += result; } - // Update buffer state if (total_written == bytes_to_write) { - // All data was written successfully - stream->buf_len = 0; - stream->buf_pos = 0; + __IMPL(stream)->buf_len = 0; + __IMPL(stream)->buf_pos = 0; } else { - // Partial write - move remaining data to beginning of buffer size_t remaining = bytes_to_write - total_written; - memmove(stream->buf, stream->buf + total_written, remaining); - stream->buf_len = remaining; - stream->buf_pos = 0; + memmove(__IMPL(stream)->buf, + __IMPL(stream)->buf + total_written, remaining); + __IMPL(stream)->buf_len = remaining; + __IMPL(stream)->buf_pos = 0; } - LIBC_UNLOCK(stream->lock); + LIBC_UNLOCK(__IMPL(stream)->lock); - // Return success if all data was written, error otherwise return (total_written == bytes_to_write) ? 0 : EOF; } diff --git a/lib/libc/stdio/fgetc.c b/lib/libc/stdio/fgetc.c index 658eaffe..a7612f42 100644 --- a/lib/libc/stdio/fgetc.c +++ b/lib/libc/stdio/fgetc.c @@ -1,4 +1,4 @@ -#include <stdio.h> +#include <stdio.h> // for fread, FILE, fgetc int fgetc(FILE *stream) { diff --git a/lib/libc/stdio/fgets.c b/lib/libc/stdio/fgets.c index 75ffb064..adeae1b4 100644 --- a/lib/libc/stdio/fgets.c +++ b/lib/libc/stdio/fgets.c @@ -1,5 +1,7 @@ -#include <libc.h> -#include <stdio.h> +#include "stddef.h" // for NULL + +#include <libc.h> // for weak_reference +#include <stdio.h> // for fread, FILE, fgets char *fgets(char *restrict s, int n, FILE *restrict stream) { diff --git a/lib/libc/stdio/fileno.c b/lib/libc/stdio/fileno.c index 09db0ad5..ad3eda7f 100644 --- a/lib/libc/stdio/fileno.c +++ b/lib/libc/stdio/fileno.c @@ -1,15 +1,15 @@ -#include <io.h> -#include <errno.h> -#include <atomic.h> -#include <stdio.h> +#include <atomic.h> // for LIBC_LOCK, LIBC_UNLOCK +#include <errno.h> // for EBADF, errno +#include <libc.h> // for __IMPL +#include <stdio.h> // for FILE, fileno int fileno(FILE *stream) { int fd; - LIBC_LOCK(stream->lock); - fd = stream->fd; - LIBC_UNLOCK(stream->lock); + LIBC_LOCK(__IMPL(stream)->lock); + fd = __IMPL(stream)->fd; + LIBC_UNLOCK(__IMPL(stream)->lock); if (fd < 0) { errno = EBADF; diff --git a/lib/libc/stdio/fmemopen.c b/lib/libc/stdio/fmemopen.c index b1fa0f8a..21e811fd 100644 --- a/lib/libc/stdio/fmemopen.c +++ b/lib/libc/stdio/fmemopen.c @@ -1,10 +1,13 @@ -#include <io.h> -#include <errno.h> -#include <fcntl.h> -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#include <libc.h> +#include "__stdio.h" // for __libc_fadd +#include "features.h" // for __weak +#include "stddef.h" // for NULL + +#include <errno.h> // for EINVAL, errno +#include <fcntl.h> // for O_WRONLY, O_CREAT, O_RDONLY, O_APPEND, O_RDWR +#include <libc.h> // for __IMPL +#include <stdio.h> // for FILE, _IOFBF, fmemopen, size_t +#include <stdlib.h> // for calloc, free +#include <string.h> // for strchr __weak void __stdio_cleanup(void) { @@ -13,15 +16,15 @@ __weak void __stdio_cleanup(void) FILE *fmemopen(void *restrict buf, size_t max_size, const char *restrict mode) { int flags; - FILE *f = calloc(1, sizeof(FILE)); + FILE *stream = calloc(1, sizeof(FILE)); - if (f == NULL) - return f; + if (stream == NULL) + return stream; - f->fd = -1; - f->buf = buf; - f->buf_size = max_size; - f->type = _IOFBF; + __IMPL(stream)->fd = -1; + __IMPL(stream)->buf = buf; + __IMPL(stream)->buf_size = max_size; + __IMPL(stream)->type = _IOFBF; if (mode[0] == 'r') { flags = O_RDONLY; @@ -30,7 +33,7 @@ FILE *fmemopen(void *restrict buf, size_t max_size, const char *restrict mode) } else if (mode[0] == 'a') { flags = O_WRONLY | O_CREAT | O_APPEND; } else { - free(f); + free(stream); errno = EINVAL; return NULL; } @@ -39,9 +42,9 @@ FILE *fmemopen(void *restrict buf, size_t max_size, const char *restrict mode) flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR; } - f->flags = flags; + __IMPL(stream)->flags = flags; - __libc_fadd(f); + __libc_fadd(stream); - return f; + return stream; } diff --git a/lib/libc/stdio/fopen.c b/lib/libc/stdio/fopen.c index 1f15820b..a56b907d 100644 --- a/lib/libc/stdio/fopen.c +++ b/lib/libc/stdio/fopen.c @@ -1,11 +1,15 @@ -#include <io.h> -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> -#include <libc.h> +#include "__stdio.h" // for __libc_fadd +#include "features.h" // for __weak +#include "stdatomic.h" // for atomic_flag_clear +#include "stddef.h" // for NULL + +#include <errno.h> // for EINVAL, errno +#include <fcntl.h> // for O_WRONLY, O_CREAT, O_RDONLY, open, O_APPEND +#include <libc.h> // for __IMPL +#include <stdio.h> // for FILE, BUFSIZ, fopen, _IOLBF +#include <stdlib.h> // for calloc, free, malloc +#include <string.h> // for strchr +#include <unistd.h> // for close __weak void __stdio_cleanup(void) { @@ -14,7 +18,7 @@ __weak void __stdio_cleanup(void) FILE *fopen(const char *restrict pathname, const char *restrict mode) { int fd, flags, _mode; - FILE *fp; + FILE *stream; _mode = 0; if (mode[0] == 'r') { @@ -36,21 +40,22 @@ FILE *fopen(const char *restrict pathname, const char *restrict mode) if ((fd = open(pathname, flags, _mode)) < 0) return NULL; - if ((fp = calloc(1, sizeof(FILE))) == NULL) + if ((stream = calloc(1, sizeof(FILE))) == NULL) return NULL; - fp->fd = fd; - fp->buf_size = BUFSIZ; - fp->flags = flags; - fp->type = _IOLBF; - atomic_flag_clear(&fp->lock); - if ((fp->buf = malloc(BUFSIZ)) == NULL) { + __IMPL(stream)->fd = fd; + __IMPL(stream)->buf_size = BUFSIZ; + __IMPL(stream)->flags = flags; + __IMPL(stream)->type = _IOLBF; + atomic_flag_clear(&stream->lock); + + if ((__IMPL(stream)->buf = malloc(BUFSIZ)) == NULL) { close(fd); - free(fp); + free(stream); return NULL; } - __libc_fadd(fp); + __libc_fadd(stream); - return fp; + return stream; } diff --git a/lib/libc/stdio/fprintf.c b/lib/libc/stdio/fprintf.c index c0d14a48..c7f31f34 100644 --- a/lib/libc/stdio/fprintf.c +++ b/lib/libc/stdio/fprintf.c @@ -1,5 +1,5 @@ -#include <stdio.h> -#include <stdarg.h> +#include <stdarg.h> // for va_end, va_start +#include <stdio.h> // for fprintf, vfprintf, FILE, va_list int fprintf(FILE *restrict stream, const char *restrict format, ...) { diff --git a/lib/libc/stdio/fputc.c b/lib/libc/stdio/fputc.c index c544d5dd..08ab0cfc 100644 --- a/lib/libc/stdio/fputc.c +++ b/lib/libc/stdio/fputc.c @@ -1,27 +1,24 @@ -#include <stdio.h> -#include <errno.h> -#include <string.h> -#include <io.h> +#include "stddef.h" // for NULL + +#include <errno.h> // for EINVAL, errno +#include <libc.h> // for __IMPL +#include <stdio.h> // for EOF, fwrite, FILE, fputc int fputc(int c, FILE *stream) { - if (!stream) { + if (stream == NULL) { errno = EINVAL; return EOF; } - // Special case for string buffer operations (snprintf) - // When fd is -1, we're writing to a string buffer - if (stream->fd == -1 && stream->buf != NULL) { - // Check if there's space (leave room for null terminator) - if (stream->buf_len >= stream->buf_size - 1) { + if (__IMPL(stream)->fd == -1 && __IMPL(stream)->buf != NULL) { + if (__IMPL(stream)->buf_len >= __IMPL(stream)->buf_size - 1) { return EOF; } - stream->buf[stream->buf_len++] = (char)c; + __IMPL(stream)->buf[__IMPL(stream)->buf_len++] = (char)c; return (unsigned char)c; } - // For regular file operations, use fwrite return fwrite(&c, 1, 1, stream) ? c : EOF; } diff --git a/lib/libc/stdio/fputs.c b/lib/libc/stdio/fputs.c index 8538b9c2..2ba0d4d1 100644 --- a/lib/libc/stdio/fputs.c +++ b/lib/libc/stdio/fputs.c @@ -1,5 +1,5 @@ -#include <stdio.h> -#include <string.h> +#include <stdio.h> // for fwrite, EOF, FILE, fputs +#include <string.h> // for strlen int fputs(const char *restrict s, FILE *restrict stream) { diff --git a/lib/libc/stdio/fread.c b/lib/libc/stdio/fread.c index a27b64c4..fb4ca3f6 100644 --- a/lib/libc/stdio/fread.c +++ b/lib/libc/stdio/fread.c @@ -1,8 +1,10 @@ -#include <io.h> -#include <unistd.h> -#include <string.h> -#include <atomic.h> -#include <stdio.h> +#include "__stdio.h" // for _IO_EOF, _IO_ERR + +#include <atomic.h> // for LIBC_LOCK, LIBC_UNLOCK +#include <libc.h> // for __IMPL +#include <stdio.h> // for fread, BUFSIZ, FILE +#include <string.h> // for memcpy +#include <unistd.h> // for size_t, read, ssize_t char __stdin_buffer[BUFSIZ]; @@ -16,35 +18,38 @@ size_t fread(void *restrict ptr, size_t size, size_t nitems, size_t bytes_read = 0; char *p = ptr; - LIBC_LOCK(stream->lock); + LIBC_LOCK(__IMPL(stream)->lock); while (total > 0) { - if (stream->buf_pos < stream->buf_len) { - size_t available = stream->buf_len - stream->buf_pos; + if (__IMPL(stream)->buf_pos < __IMPL(stream)->buf_len) { + size_t available = __IMPL(stream)->buf_len - + __IMPL(stream)->buf_pos; size_t to_copy = total < available ? total : available; - memcpy(p, stream->buf + stream->buf_pos, to_copy); - stream->buf_pos += to_copy; + memcpy(p, __IMPL(stream)->buf + __IMPL(stream)->buf_pos, + to_copy); + __IMPL(stream)->buf_pos += to_copy; p += to_copy; bytes_read += to_copy; total -= to_copy; continue; } - ssize_t ret = read(stream->fd, stream->buf, stream->buf_size); + ssize_t ret = read(__IMPL(stream)->fd, __IMPL(stream)->buf, + __IMPL(stream)->buf_size); if (ret <= 0) { if (ret < 0) - stream->flags |= _IO_ERR; + __IMPL(stream)->flags |= _IO_ERR; else - stream->flags |= _IO_EOF; + __IMPL(stream)->flags |= _IO_EOF; break; } - stream->buf_len = ret; - stream->buf_pos = 0; + __IMPL(stream)->buf_len = ret; + __IMPL(stream)->buf_pos = 0; } - LIBC_UNLOCK(stream->lock); + LIBC_UNLOCK(__IMPL(stream)->lock); return bytes_read / size; } diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index af12cd2c..0e425e8e 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -1,28 +1,31 @@ -#include <unistd.h> -#include <io.h> -#include <stdio.h> -#include <atomic.h> +#include "__stdio.h" // for _IO_EOF, _IO_ERR +#include "stddef.h" // for NULL + +#include <atomic.h> // for LIBC_LOCK, LIBC_UNLOCK +#include <libc.h> // for __IMPL +#include <stdio.h> // for FILE, fseek +#include <unistd.h> // for lseek, off_t int fseek(FILE *stream, long offset, int whence) { - if (stream == NULL || stream->fd < 0) + if (stream == NULL || __IMPL(stream)->fd < 0) return -1; - LIBC_LOCK(stream->lock); + LIBC_LOCK(__IMPL(stream)->lock); - stream->buf_pos = 0; - stream->buf_len = 0; - stream->flags &= ~_IO_EOF; + __IMPL(stream)->buf_pos = 0; + __IMPL(stream)->buf_len = 0; + __IMPL(stream)->flags &= ~_IO_EOF; - off_t result = lseek(stream->fd, offset, whence); + off_t result = lseek(__IMPL(stream)->fd, offset, whence); - LIBC_UNLOCK(stream->lock); + LIBC_UNLOCK(__IMPL(stream)->lock); if (result == (off_t)-1) { - stream->flags |= _IO_ERR; + __IMPL(stream)->flags |= _IO_ERR; return -1; } - stream->offset = result; + __IMPL(stream)->offset = result; return 0; } diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c index c28fe143..d26ba071 100644 --- a/lib/libc/stdio/ftell.c +++ b/lib/libc/stdio/ftell.c @@ -1,6 +1,7 @@ -#include <stdio.h> -#include <limits.h> -#include <errno.h> +#include <errno.h> // for EOVERFLOW, errno +#include <limits.h> // for LONG_MAX +#include <stdio.h> // for ftello, FILE, ftell +#include <sys/types.h> // for off_t long ftell(FILE *stream) { diff --git a/lib/libc/stdio/ftello.c b/lib/libc/stdio/ftello.c index d0e5dfa1..d69008cf 100644 --- a/lib/libc/stdio/ftello.c +++ b/lib/libc/stdio/ftello.c @@ -1,7 +1,5 @@ -#include <io.h> -#include <atomic.h> -#include <stdio.h> -#include <unistd.h> +#include <stdio.h> // for fseek, FILE, SEEK_CUR, ftello +#include <sys/types.h> // for off_t off_t ftello(FILE *stream) { diff --git a/lib/libc/stdio/fwrite.c b/lib/libc/stdio/fwrite.c index 709b1c72..4adbca81 100644 --- a/lib/libc/stdio/fwrite.c +++ b/lib/libc/stdio/fwrite.c @@ -1,11 +1,13 @@ -#include <io.h> -#include <libc.h> -#include <atomic.h> -#include <stdio.h> -#include <errno.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> +#include "__stdio.h" // for _IO_ERR +#include "stddef.h" // for NULL + +#include <atomic.h> // for LIBC_UNLOCK, LIBC_LOCK +#include <errno.h> // for errno, EOVERFLOW, EBADF, EINVAL, EIO +#include <fcntl.h> // for O_ACCMODE, O_RDONLY +#include <libc.h> // for __IMPL +#include <stdio.h> // for fflush, fwrite, BUFSIZ, FILE, _IOFBF, _IOLBF +#include <string.h> // for memcpy, memchr +#include <unistd.h> // for size_t, ssize_t, write char __stdout_buffer[BUFSIZ]; void (*__stdio_cleanup)(void); @@ -17,131 +19,117 @@ size_t fwrite(const void *restrict ptr, size_t size, size_t nitems, size_t written = 0; const char *data = (const char *)ptr; - // Validate parameters - if (!ptr || !stream || size == 0) { - if (size == 0) + if (ptr == NULL || stream == NULL || size == 0) { + if (size == 0) { return nitems; + } errno = EINVAL; return 0; } - // Special case for string buffer operations (snprintf) - // When fd is -1, we're writing to a string buffer - if (stream->fd == -1 && stream->buf != NULL) { - // Calculate total bytes with overflow check + if (__IMPL(stream)->fd == -1 && __IMPL(stream)->buf != NULL) { if (__builtin_mul_overflow(size, nitems, &total_bytes)) { errno = EOVERFLOW; return 0; } - // Check remaining buffer space (leave room for null terminator) size_t space_left = - stream->buf_size > stream->buf_len ? - stream->buf_size - stream->buf_len - 1 : + __IMPL(stream)->buf_size > __IMPL(stream)->buf_len ? + __IMPL(stream)->buf_size - + __IMPL(stream)->buf_len - 1 : 0; if (space_left == 0) { return 0; } - // Copy as much as fits size_t to_copy = total_bytes < space_left ? total_bytes : space_left; if (to_copy > 0) { - memcpy(stream->buf + stream->buf_len, data, to_copy); - stream->buf_len += to_copy; + memcpy(__IMPL(stream)->buf + __IMPL(stream)->buf_len, + data, to_copy); + __IMPL(stream)->buf_len += to_copy; } - // Return number of complete items written return to_copy == total_bytes ? nitems : to_copy / size; } - // Calculate total bytes with overflow check if (__builtin_mul_overflow(size, nitems, &total_bytes)) { errno = EOVERFLOW; return 0; } - // Check if stream is writable (fix the flag check) - if ((stream->flags & O_ACCMODE) == O_RDONLY) { + if ((__IMPL(stream)->flags & O_ACCMODE) == O_RDONLY) { errno = EBADF; return 0; } - // Check for error state - if (stream->flags & _IO_ERR) { + if (__IMPL(stream)->flags & _IO_ERR) { errno = EIO; return 0; } - LIBC_LOCK(stream->lock); + LIBC_LOCK(__IMPL(stream)->lock); - // Handle unbuffered I/O - if (stream->type == _IONBF) { - ssize_t result = write(stream->fd, data, total_bytes); - LIBC_UNLOCK(stream->lock); + if (__IMPL(stream)->type == _IONBF) { + ssize_t result = write(__IMPL(stream)->fd, data, total_bytes); + LIBC_UNLOCK(__IMPL(stream)->lock); if (result < 0) { - stream->flags |= _IO_ERR; + __IMPL(stream)->flags |= _IO_ERR; return 0; } return result == (ssize_t)total_bytes ? nitems : result / size; } - // Handle buffered I/O (both _IOFBF and _IOLBF) size_t remaining = total_bytes; while (remaining > 0) { - // Check if buffer is full - size_t space_available = stream->buf_size - stream->buf_len; + size_t space_available = + __IMPL(stream)->buf_size - __IMPL(stream)->buf_len; if (space_available == 0) { - // Flush the buffer - LIBC_UNLOCK(stream->lock); + LIBC_UNLOCK(__IMPL(stream)->lock); if (fflush(stream) != 0) { return written / size; } - space_available = stream->buf_size; + space_available = __IMPL(stream)->buf_size; } - // Determine how much to copy this iteration size_t to_copy = remaining < space_available ? remaining : space_available; - // Copy data to buffer - memcpy(stream->buf + stream->buf_len, data + written, to_copy); - stream->buf_len += to_copy; + memcpy(__IMPL(stream)->buf + __IMPL(stream)->buf_len, + data + written, to_copy); + __IMPL(stream)->buf_len += to_copy; written += to_copy; remaining -= to_copy; - // For line buffered streams, check if we need to flush - if (stream->type == _IOLBF) { - // Look for newlines in the data we just added - char *newline_pos = - memchr(stream->buf + stream->buf_len - to_copy, - '\n', to_copy); + if (__IMPL(stream)->type == _IOLBF) { + char *newline_pos = memchr( + __IMPL(stream)->buf + __IMPL(stream)->buf_len - + to_copy, + '\n', to_copy); if (newline_pos != NULL) { - LIBC_UNLOCK(stream->lock); + LIBC_UNLOCK(__IMPL(stream)->lock); if (fflush(stream) != 0) { return written / size; } } } - // For fully buffered streams, flush if buffer is full - else if (stream->type == _IOFBF && - stream->buf_len == stream->buf_size) { - LIBC_UNLOCK(stream->lock); + else if (__IMPL(stream)->type == _IOFBF && + __IMPL(stream)->buf_len == __IMPL(stream)->buf_size) { + LIBC_UNLOCK(__IMPL(stream)->lock); if (fflush(stream) != 0) { return written / size; } } } - LIBC_UNLOCK(stream->lock); + LIBC_UNLOCK(__IMPL(stream)->lock); - // Return number of complete items written return written == total_bytes ? nitems : written / size; } diff --git a/lib/libc/stdio/getc.c b/lib/libc/stdio/getc.c index 251675aa..242c8396 100644 --- a/lib/libc/stdio/getc.c +++ b/lib/libc/stdio/getc.c @@ -1,5 +1,5 @@ -#include <libc.h> -#include <stdio.h> +#include <libc.h> // for weak_reference +#include <stdio.h> // for fgetc, FILE, getc, getc_unlocked int getc(FILE *stream) { diff --git a/lib/libc/stdio/getchar.c b/lib/libc/stdio/getchar.c index 8c690d56..d26c3c6b 100644 --- a/lib/libc/stdio/getchar.c +++ b/lib/libc/stdio/getchar.c @@ -1,5 +1,5 @@ -#include <libc.h> -#include <stdio.h> +#include <libc.h> // for weak_reference +#include <stdio.h> // for fgetc, getchar, getchar_unlocked, stdin int getchar(void) { diff --git a/lib/libc/stdio/pclose.c b/lib/libc/stdio/pclose.c index daae5bf5..241d4de0 100644 --- a/lib/libc/stdio/pclose.c +++ b/lib/libc/stdio/pclose.c @@ -1,10 +1,10 @@ -#include <io.h> -#include <stdio.h> -#include <sys/wait.h> +#include <libc.h> // for __IMPL +#include <stdio.h> // for fclose, FILE, pclose +#include <sys/wait.h> // for waitpid int pclose(FILE *stream) { int stat; fclose(stream); - return (waitpid(stream->pid, &stat, 0) < 0) ? -1 : stat; + return (waitpid(__IMPL(stream)->pid, &stat, 0) < 0) ? -1 : stat; } diff --git a/lib/libc/stdio/perror.c b/lib/libc/stdio/perror.c index f3f4bb19..63c708a9 100644 --- a/lib/libc/stdio/perror.c +++ b/lib/libc/stdio/perror.c @@ -1,8 +1,8 @@ -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <unistd.h> -#include <sys/uio.h> +#include <errno.h> // for errno +#include <stdio.h> // for NULL, perror +#include <string.h> // for strlen, strerror +#include <sys/uio.h> // for iovec, writev +#include <unistd.h> // for STDERR_FILENO void perror(const char *s) { diff --git a/lib/libc/stdio/popen.c b/lib/libc/stdio/popen.c index 92b6a099..09c931ad 100644 --- a/lib/libc/stdio/popen.c +++ b/lib/libc/stdio/popen.c @@ -1,8 +1,10 @@ -#include <io.h> -#include <errno.h> -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> +#include "stddef.h" // for NULL + +#include <errno.h> // for EINVAL, errno +#include <fcntl.h> // for O_RDONLY, O_CLOEXEC, O_WRONLY +#include <libc.h> // for __IMPL +#include <stdio.h> // for FILE, fclose, fdopen, popen +#include <unistd.h> // for close, dup2, _exit, execl, fork, pipe2, STDIN_FI... FILE *popen(const char *command, const char *mode) { @@ -58,7 +60,7 @@ FILE *popen(const char *command, const char *mode) close(pipefd[0]); } - stream->pid = pid; + __IMPL(stream)->pid = pid; return stream; } diff --git a/lib/libc/stdio/printf.c b/lib/libc/stdio/printf.c index e8e7c388..e45a5118 100644 --- a/lib/libc/stdio/printf.c +++ b/lib/libc/stdio/printf.c @@ -1,5 +1,5 @@ -#include <stdio.h> -#include <stdarg.h> +#include <stdarg.h> // for va_end, va_start +#include <stdio.h> // for printf, vfprintf, stdout, va_list int printf(const char *restrict format, ...) { diff --git a/lib/libc/stdio/putc.c b/lib/libc/stdio/putc.c index 2486926a..421de457 100644 --- a/lib/libc/stdio/putc.c +++ b/lib/libc/stdio/putc.c @@ -1,5 +1,5 @@ -#include <libc.h> -#include <stdio.h> +#include <libc.h> // for weak_reference +#include <stdio.h> // for fputc, FILE, putc, putc_unlocked int putc(int c, FILE *stream) { diff --git a/lib/libc/stdio/putchar.c b/lib/libc/stdio/putchar.c index f54bb9d7..c9e3ba08 100644 --- a/lib/libc/stdio/putchar.c +++ b/lib/libc/stdio/putchar.c @@ -1,5 +1,5 @@ -#include <libc.h> -#include <stdio.h> +#include <libc.h> // for weak_reference +#include <stdio.h> // for putc, putchar, putchar_unlocked, stdout int putchar(int c) { diff --git a/lib/libc/stdio/puts.c b/lib/libc/stdio/puts.c index 41024337..1688a7cb 100644 --- a/lib/libc/stdio/puts.c +++ b/lib/libc/stdio/puts.c @@ -1,5 +1,5 @@ -#include <stdio.h> -#include <string.h> +#include <stdio.h> // for fwrite, stdout, puts +#include <string.h> // for strlen int puts(const char *s) { diff --git a/lib/libc/stdio/remove.c b/lib/libc/stdio/remove.c index 9aec52e9..25bbd3bd 100644 --- a/lib/libc/stdio/remove.c +++ b/lib/libc/stdio/remove.c @@ -1,6 +1,9 @@ -#include <stdio.h> -#include <fcntl.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_unlinkat +#include "errno.h" // for EISDIR, errno + +#include <fcntl.h> // for AT_FDCWD, AT_REMOVEDIR +#include <stdio.h> // for remove +#include <syscall.h> // for __syscall_3, syscall int remove(const char *path) { diff --git a/lib/libc/stdio/rename.c b/lib/libc/stdio/rename.c index 612326e8..8857f852 100644 --- a/lib/libc/stdio/rename.c +++ b/lib/libc/stdio/rename.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_rename + +#include <syscall.h> // for __syscall_2, syscall int rename(const char *old, const char *new) { diff --git a/lib/libc/stdio/renameat.c b/lib/libc/stdio/renameat.c index 93d435fa..fde966c4 100644 --- a/lib/libc/stdio/renameat.c +++ b/lib/libc/stdio/renameat.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_renameat + +#include <syscall.h> // for __syscall_4, syscall int renameat(int oldfd, const char *old, int newfd, const char *new) { diff --git a/lib/libc/stdio/rewind.c b/lib/libc/stdio/rewind.c index b047fa41..728e2d75 100644 --- a/lib/libc/stdio/rewind.c +++ b/lib/libc/stdio/rewind.c @@ -1,4 +1,4 @@ -#include <stdio.h> +#include <stdio.h> // for clearerr, fseek, FILE, SEEK_SET, rewind void rewind(FILE *stream) { diff --git a/lib/libc/stdio/setbuf.c b/lib/libc/stdio/setbuf.c index a1ef7b31..ddddf4ac 100644 --- a/lib/libc/stdio/setbuf.c +++ b/lib/libc/stdio/setbuf.c @@ -1,5 +1,4 @@ -#include <io.h> -#include <stdio.h> +#include <stdio.h> // for setvbuf, BUFSIZ, FILE, NULL, _IOFBF, _IONBF, setbuf void setbuf(FILE *restrict stream, char *restrict buf) { diff --git a/lib/libc/stdio/setvbuf.c b/lib/libc/stdio/setvbuf.c index 56d7196c..02928a35 100644 --- a/lib/libc/stdio/setvbuf.c +++ b/lib/libc/stdio/setvbuf.c @@ -1,5 +1,7 @@ -#include <io.h> -#include <stdio.h> +#include "stddef.h" // for NULL + +#include <libc.h> // for __IMPL +#include <stdio.h> // for _IONBF, FILE, _IOFBF, _IOLBF, setvbuf, size_t int setvbuf(FILE *restrict stream, char *restrict buf, int type, size_t size) { @@ -8,13 +10,13 @@ int setvbuf(FILE *restrict stream, char *restrict buf, int type, size_t size) if (type != _IONBF && (buf == NULL || size == 0)) return -1; - if (stream->fd < 0) + if (__IMPL(stream)->fd < 0) return -1; - stream->buf = buf; - stream->buf_size = size; - stream->buf_pos = 0; - stream->type = type; + __IMPL(stream)->buf = buf; + __IMPL(stream)->buf_size = size; + __IMPL(stream)->buf_pos = 0; + __IMPL(stream)->type = type; return 0; } diff --git a/lib/libc/stdio/snprintf.c b/lib/libc/stdio/snprintf.c index 81f2c5b6..49204437 100644 --- a/lib/libc/stdio/snprintf.c +++ b/lib/libc/stdio/snprintf.c @@ -1,5 +1,5 @@ -#include <stdio.h> -#include <stdarg.h> +#include <stdarg.h> // for va_end, va_start +#include <stdio.h> // for snprintf, vsnprintf, size_t, va_list int snprintf(char *restrict s, size_t n, const char *restrict format, ...) { diff --git a/lib/libc/stdio/sprintf.c b/lib/libc/stdio/sprintf.c index 057c162d..a0ed7bf1 100644 --- a/lib/libc/stdio/sprintf.c +++ b/lib/libc/stdio/sprintf.c @@ -1,6 +1,5 @@ -#include <stdio.h> -#include <limits.h> -#include <stdarg.h> +#include <stdarg.h> // for va_end, va_start +#include <stdio.h> // for sprintf, vsprintf, va_list int sprintf(char *restrict s, const char *restrict format, ...) { diff --git a/lib/libc/stdio/stderr.c b/lib/libc/stdio/stderr.c index 42098960..155f0e3e 100644 --- a/lib/libc/stdio/stderr.c +++ b/lib/libc/stdio/stderr.c @@ -1,6 +1,8 @@ -#include <io.h> -#include <fcntl.h> -#include <unistd.h> +#include "__stdio.h" // for __FILE +#include "stdatomic.h" // for ATOMIC_FLAG_INIT + +#include <fcntl.h> // for O_WRONLY +#include <unistd.h> // for STDERR_FILENO #define BUFSIZ 4096 diff --git a/lib/libc/stdio/stdin.c b/lib/libc/stdio/stdin.c index 329c9528..b4194704 100644 --- a/lib/libc/stdio/stdin.c +++ b/lib/libc/stdio/stdin.c @@ -1,7 +1,8 @@ -#include <io.h> -#include <libc.h> -#include <fcntl.h> -#include <unistd.h> +#include "__stdio.h" // for __FILE +#include "features.h" // for __weak + +#include <fcntl.h> // for O_RDONLY +#include <unistd.h> // for STDOUT_FILENO #define BUFSIZ 4096 #define _IOLBF 0x1 diff --git a/lib/libc/stdio/stdout.c b/lib/libc/stdio/stdout.c index 3645e07d..a21125c3 100644 --- a/lib/libc/stdio/stdout.c +++ b/lib/libc/stdio/stdout.c @@ -1,8 +1,11 @@ -#include <io.h> -#include <libc.h> -#include <fcntl.h> -#include <atomic.h> -#include <unistd.h> +#include "__stdio.h" // for __FILE, __libc_fadd +#include "features.h" // for __weak +#include "stdatomic.h" // for ATOMIC_FLAG_INIT, atomic_flag + +#include <atomic.h> // for LIBC_LOCK, LIBC_UNLOCK +#include <fcntl.h> // for O_WRONLY +#include <stddef.h> // for NULL +#include <unistd.h> // for STDOUT_FILENO #define BUFSIZ 4096 diff --git a/lib/libc/stdio/vasprintf.c b/lib/libc/stdio/vasprintf.c index 128d4ee3..1f012caa 100644 --- a/lib/libc/stdio/vasprintf.c +++ b/lib/libc/stdio/vasprintf.c @@ -1,6 +1,6 @@ -#include <io.h> -#include <stdarg.h> -#include <stdio.h> +#include <stdarg.h> // for va_copy, va_end +#include <stdio.h> // for vsnprintf, va_list, vasprintf +#include <stdlib.h> // for malloc // TODO: maybe use memstream in future?? int vasprintf(char **restrict ptr, const char *restrict format, va_list ap) diff --git a/lib/libc/stdio/vdprintf.c b/lib/libc/stdio/vdprintf.c index 66a041cc..4647d641 100644 --- a/lib/libc/stdio/vdprintf.c +++ b/lib/libc/stdio/vdprintf.c @@ -1,12 +1,16 @@ -#include <io.h> -#include <stdio.h> +#include "__stdio.h" // for __FILE + +#include <stdio.h> // for vfprintf, _IONBF, va_list, vdprintf int vdprintf(int fildes, const char *restrict format, va_list ap) { int r; - FILE f; - f.fd = fildes; - f.type = _IONBF; - r = vfprintf(&f, format, ap); + struct __FILE stream; + + stream.fd = fildes; + stream.type = _IONBF; + + r = vfprintf(&stream, format, ap); + return r; } diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index 90e60f7f..126c1193 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -1,14 +1,12 @@ -#include <ctype.h> -#include <errno.h> -#include <stdio.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdarg.h> -#include <stdlib.h> -#include <string.h> -#include <stddef.h> -#include <math.h> -#include <unistd.h> +#include <ctype.h> // for isdigit +#include <errno.h> // for EINVAL, errno +#include <math.h> // for frexp, isinf, isnan +#include <stdarg.h> // for va_arg +#include <stddef.h> // for NULL, ptrdiff_t +#include <stdint.h> // for uintptr_t, intmax_t, uintmax_t +#include <stdio.h> // for fwrite, fputc, vfprintf, FILE, va_list +#include <string.h> // for memmove, strlcpy, strlen +#include <sys/types.h> // for size_t, ssize_t extern char *dtoa(double, int mode, int ndigits, int *decpt, int *sign, char **rve); diff --git a/lib/libc/stdio/vprintf.c b/lib/libc/stdio/vprintf.c index 10e938b7..c6cc8b4c 100644 --- a/lib/libc/stdio/vprintf.c +++ b/lib/libc/stdio/vprintf.c @@ -1,4 +1,4 @@ -#include <stdio.h> +#include <stdio.h> // for vfprintf, vprintf, stdout, va_list int vprintf(const char *restrict format, va_list ap) { diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c index 7afae866..818cffb5 100644 --- a/lib/libc/stdio/vsnprintf.c +++ b/lib/libc/stdio/vsnprintf.c @@ -1,42 +1,43 @@ -#include <io.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdatomic.h> -#include <fcntl.h> +#include "__stdio.h" // for __FILE +#include "stddef.h" // for NULL + +#include <fcntl.h> // for O_WRONLY +#include <stdatomic.h> // for atomic_flag_clear +#include <stdio.h> // for vfprintf, vsnprintf, _IONBF, size_t, va_list +#include <string.h> // for memset int vsnprintf(char *restrict s, size_t n, const char *restrict format, va_list ap) { int r; - FILE f; + struct __FILE stream; if (n == 0) { return 0; } - if (!s) { + if (s == NULL) { return -1; } - memset(&f, 0, sizeof(f)); - f.fd = -1; - f.flags = O_WRONLY; - f.type = _IONBF; - atomic_flag_clear(&f.lock); - f.buf = s; - f.buf_size = n; - f.buf_len = 0; - f.buf_pos = 0; - f.eof = 0; - f.unget_cnt = 0; - f.offset = 0; - f.next = NULL; - - r = vfprintf(&f, format, ap); - - if (f.buf_len < n) { - s[f.buf_len] = '\0'; + memset(&stream, 0, sizeof(stream)); + stream.fd = -1; + stream.flags = O_WRONLY; + stream.type = _IONBF; + atomic_flag_clear(&stream.lock); + stream.buf = s; + stream.buf_size = n; + stream.buf_len = 0; + stream.buf_pos = 0; + stream.eof = 0; + stream.unget_cnt = 0; + stream.offset = 0; + stream.next = NULL; + + r = vfprintf(&stream, format, ap); + + if (stream.buf_len < n) { + s[stream.buf_len] = '\0'; } else if (n > 0) { s[n - 1] = '\0'; r = n - 1; diff --git a/lib/libc/stdio/vsprintf.c b/lib/libc/stdio/vsprintf.c index eec52313..b8da63b4 100644 --- a/lib/libc/stdio/vsprintf.c +++ b/lib/libc/stdio/vsprintf.c @@ -1,5 +1,4 @@ -#include <stdarg.h> -#include <stdio.h> +#include <stdio.h> // for vsnprintf, vsprintf, size_t, va_list int vsprintf(char *restrict s, const char *restrict format, va_list ap) { diff --git a/lib/libc/stdlib/exit.c b/lib/libc/stdlib/exit.c index 34b8a0f2..5fea520e 100644 --- a/lib/libc/stdlib/exit.c +++ b/lib/libc/stdlib/exit.c @@ -1,4 +1,4 @@ -#include <io.h> +#include <libc.h> #include <libc.h> #include <unistd.h> #include <stdio.h> @@ -9,26 +9,26 @@ weak_reference(__dummy_atexit_fvec, __atexit_fvec); void (*__dummy_stdio_cleanup)(void); weak_reference(__dummy_stdio_cleanup, __stdio_cleanup); -static void __fclose(FILE *fp) +static void __fclose(FILE *stream) { - if (fp == NULL) { + if (stream == NULL) { return; } - if (fp->buf_len > 0) { - fflush(fp); + if (__IMPL(stream)->buf_len > 0) { + fflush(stream); } - if (fp->fd > STDERR_FILENO) { - close(fp->fd); + if (__IMPL(stream)->fd > STDERR_FILENO) { + close(__IMPL(stream)->fd); } - if (fp->buf) { - free(fp->buf); + if (__IMPL(stream)->buf) { + free(__IMPL(stream)->buf); } - if (fp != stdout && fp != stderr && fp != stdin) { - free(fp); + if (stream != stdout && stream != stderr && stream != stdin) { + free(stream); } } diff --git a/lib/libc/string/memccpy.c b/lib/libc/string/memccpy.c index 29828182..4b3c83cd 100644 --- a/lib/libc/string/memccpy.c +++ b/lib/libc/string/memccpy.c @@ -1,4 +1,4 @@ -#include <stddef.h> +#include <stddef.h> // for NULL, size_t void *memccpy(void *restrict s1, const void *restrict s2, int c, size_t n) { diff --git a/lib/libc/string/memchr.c b/lib/libc/string/memchr.c index 38850aed..230e042f 100644 --- a/lib/libc/string/memchr.c +++ b/lib/libc/string/memchr.c @@ -1,4 +1,4 @@ -#include <stddef.h> +#include <stddef.h> // for NULL, size_t void *memchr(const void *s, int c, size_t n) { diff --git a/lib/libc/string/memcmp.c b/lib/libc/string/memcmp.c index 5efb282f..da1766c4 100644 --- a/lib/libc/string/memcmp.c +++ b/lib/libc/string/memcmp.c @@ -1,4 +1,4 @@ -#include <stddef.h> +#include <stddef.h> // for size_t int memcmp(const void *s1, const void *s2, size_t n) { diff --git a/lib/libc/string/memcpy.c b/lib/libc/string/memcpy.c index 05586b55..8af4577c 100644 --- a/lib/libc/string/memcpy.c +++ b/lib/libc/string/memcpy.c @@ -1,6 +1,6 @@ -#include <errno.h> -#include <string.h> -#include <features.h> +#include <errno.h> // for EINVAL, ERANGE +#include <features.h> // for __weak +#include <string.h> // for rsize_t, NULL, memcpy, size_t, errno_t, memcpy_s __weak void *memcpy(void *restrict s1, const void *restrict s2, size_t n); diff --git a/lib/libc/string/memmem.c b/lib/libc/string/memmem.c index 7a450cf7..b30a700a 100644 --- a/lib/libc/string/memmem.c +++ b/lib/libc/string/memmem.c @@ -1,4 +1,4 @@ -#include <string.h> +#include <string.h> // for memcmp, size_t, NULL, memmem void *memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) diff --git a/lib/libc/string/memmove.c b/lib/libc/string/memmove.c index 88968185..db83694f 100644 --- a/lib/libc/string/memmove.c +++ b/lib/libc/string/memmove.c @@ -1,5 +1,5 @@ -#include <stddef.h> -#include <stdint.h> +#include <stddef.h> // for size_t +#include <stdint.h> // for uint8_t, uintptr_t void *memmove(void *dst, const void *src, size_t n) { diff --git a/lib/libc/string/memset.c b/lib/libc/string/memset.c index da969d16..316a1873 100644 --- a/lib/libc/string/memset.c +++ b/lib/libc/string/memset.c @@ -1,4 +1,4 @@ -#include <string.h> +#include <string.h> // for memset, size_t void *memset(void *s, int c, size_t n) { diff --git a/lib/libc/string/stpcpy.c b/lib/libc/string/stpcpy.c index 04c3a17f..f3619557 100644 --- a/lib/libc/string/stpcpy.c +++ b/lib/libc/string/stpcpy.c @@ -1,4 +1,4 @@ -#include <string.h> +#include <string.h> // for stpcpy char *stpcpy(char *restrict s1, const char *restrict s2) { diff --git a/lib/libc/string/stpncpy.c b/lib/libc/string/stpncpy.c index 8f7ebd01..1afa59fc 100644 --- a/lib/libc/string/stpncpy.c +++ b/lib/libc/string/stpncpy.c @@ -1,4 +1,4 @@ -#include <stddef.h> +#include <stddef.h> // for size_t char *strncpy(char *restrict s1, const char *restrict s2, size_t n) { diff --git a/lib/libc/string/strchr.c b/lib/libc/string/strchr.c index db632a2e..06fb51bc 100644 --- a/lib/libc/string/strchr.c +++ b/lib/libc/string/strchr.c @@ -1,4 +1,4 @@ -#include <string.h> +#include <string.h> // for strchr, NULL char *strchr(const char *s, int c) { diff --git a/lib/libc/string/strcmp.c b/lib/libc/string/strcmp.c index 836522f1..e3e5ca03 100644 --- a/lib/libc/string/strcmp.c +++ b/lib/libc/string/strcmp.c @@ -1,4 +1,4 @@ -#include <stddef.h> +#include <stddef.h> // for NULL int strcmp(const char *s1, const char *s2) { diff --git a/lib/libc/string/strcoll.c b/lib/libc/string/strcoll.c index 6efaa3d3..7a1502f0 100644 --- a/lib/libc/string/strcoll.c +++ b/lib/libc/string/strcoll.c @@ -1,6 +1,8 @@ -#include <libc.h> -#include <string.h> -#include <locale.h> +#include "features.h" // for __weak + +#include <libc.h> // for __unused +#include <locale.h> // for locale_t +#include <string.h> // for strcmp, strcoll, strcoll_l int strcoll(const char *s1, const char *s2) { diff --git a/lib/libc/string/strcspn.c b/lib/libc/string/strcspn.c index 9f1f2bcd..4efb38ae 100644 --- a/lib/libc/string/strcspn.c +++ b/lib/libc/string/strcspn.c @@ -1,4 +1,4 @@ -#include <string.h> +#include <string.h> // for size_t, strchr, strcspn, NULL size_t strcspn(const char *s1, const char *s2) { diff --git a/lib/libc/string/strdup.c b/lib/libc/string/strdup.c index 1210bfdc..97b5d712 100644 --- a/lib/libc/string/strdup.c +++ b/lib/libc/string/strdup.c @@ -1,5 +1,5 @@ -#include <stdlib.h> -#include <string.h> +#include <stdlib.h> // for NULL, malloc +#include <string.h> // for memcpy, strlen, size_t, strdup char *strdup(const char *s) { diff --git a/lib/libc/string/strerror.c b/lib/libc/string/strerror.c index c091ac79..e7800d08 100644 --- a/lib/libc/string/strerror.c +++ b/lib/libc/string/strerror.c @@ -1,7 +1,10 @@ -#include <libc.h> -#include <errno.h> -#include <string.h> -#include <locale.h> +#include "__stdio.h" // for size_t +#include "features.h" // for __weak + +#include <errno.h> // for ERANGE, E2BIG, EACCES, EADDRINUSE, EADDRNOTAVAIL +#include <libc.h> // for __unused +#include <locale.h> // for locale_t +#include <string.h> // for memcpy, strerror, strlen, strerror_l, strerror_r char *strerror(int errnum) { diff --git a/lib/libc/string/strlcat.c b/lib/libc/string/strlcat.c index a2c333e0..751f1616 100644 --- a/lib/libc/string/strlcat.c +++ b/lib/libc/string/strlcat.c @@ -1,4 +1,4 @@ -#include <string.h> +#include <string.h> // for size_t, strlen, memcpy, strlcat size_t strlcat(char *restrict dst, const char *restrict src, size_t dstsize) { diff --git a/lib/libc/string/strlcpy.c b/lib/libc/string/strlcpy.c index 2f2f6a3b..fcbcebab 100644 --- a/lib/libc/string/strlcpy.c +++ b/lib/libc/string/strlcpy.c @@ -1,4 +1,4 @@ -#include <string.h> +#include <string.h> // for size_t, memcpy, strlen, strlcpy size_t strlcpy(char *restrict dst, const char *restrict src, size_t dstsize) { diff --git a/lib/libc/string/strlen.c b/lib/libc/string/strlen.c index 0eb222fa..6371b588 100644 --- a/lib/libc/string/strlen.c +++ b/lib/libc/string/strlen.c @@ -1,4 +1,4 @@ -#include <stddef.h> +#include <stddef.h> // for size_t, NULL size_t strlen(const char *str) { diff --git a/lib/libc/string/strncat.c b/lib/libc/string/strncat.c index ce0d8e24..1a957e43 100644 --- a/lib/libc/string/strncat.c +++ b/lib/libc/string/strncat.c @@ -1,4 +1,4 @@ -#include <string.h> +#include <string.h> // for strncat, size_t char *strncat(char *restrict s1, const char *restrict s2, size_t n) { diff --git a/lib/libc/string/strncmp.c b/lib/libc/string/strncmp.c index 2fbc2395..1675890a 100644 --- a/lib/libc/string/strncmp.c +++ b/lib/libc/string/strncmp.c @@ -1,4 +1,4 @@ -#include <stddef.h> +#include <stddef.h> // for size_t int strncmp(const char *s1, const char *s2, size_t n) { diff --git a/lib/libc/string/strncpy.c b/lib/libc/string/strncpy.c index c43b88c8..b0541b44 100644 --- a/lib/libc/string/strncpy.c +++ b/lib/libc/string/strncpy.c @@ -1,4 +1,4 @@ -#include <stddef.h> +#include <stddef.h> // for size_t char *strncpy(char *restrict s1, const char *restrict s2, size_t n) { diff --git a/lib/libc/string/strndup.c b/lib/libc/string/strndup.c index 70e10501..318561ca 100644 --- a/lib/libc/string/strndup.c +++ b/lib/libc/string/strndup.c @@ -1,5 +1,5 @@ -#include <stdlib.h> -#include <string.h> +#include <stdlib.h> // for NULL, malloc +#include <string.h> // for memcpy, size_t, strndup char *strndup(const char *s, size_t size) { diff --git a/lib/libc/string/strnlen.c b/lib/libc/string/strnlen.c index 11da22ec..d1dc98bb 100644 --- a/lib/libc/string/strnlen.c +++ b/lib/libc/string/strnlen.c @@ -1,4 +1,4 @@ -#include <stddef.h> +#include <stddef.h> // for size_t size_t strnlen(const char *s, size_t maxlen) { diff --git a/lib/libc/string/strpbrk.c b/lib/libc/string/strpbrk.c index 21d6507f..a03bb31a 100644 --- a/lib/libc/string/strpbrk.c +++ b/lib/libc/string/strpbrk.c @@ -1,4 +1,4 @@ -#include <stddef.h> +#include <stddef.h> // for NULL char *strpbrk(const char *s1, const char *s2) { diff --git a/lib/libc/string/strrchr.c b/lib/libc/string/strrchr.c index d2807569..5d66035e 100644 --- a/lib/libc/string/strrchr.c +++ b/lib/libc/string/strrchr.c @@ -1,4 +1,4 @@ -#include <stddef.h> +#include <stddef.h> // for NULL char *strrchr(const char *s, int c) { diff --git a/lib/libc/string/strspn.c b/lib/libc/string/strspn.c index 78277ae7..3b7036cc 100644 --- a/lib/libc/string/strspn.c +++ b/lib/libc/string/strspn.c @@ -1,5 +1,4 @@ -#include <stddef.h> -#include <string.h> +#include <string.h> // for size_t, strchr, strspn, NULL size_t strspn(const char *s1, const char *s2) { diff --git a/lib/libc/string/strstr.c b/lib/libc/string/strstr.c index c3e2d5dd..1c35e826 100644 --- a/lib/libc/string/strstr.c +++ b/lib/libc/string/strstr.c @@ -1,4 +1,4 @@ -#include <stddef.h> +#include <stddef.h> // for NULL char *strstr(const char *s1, const char *s2) { diff --git a/lib/libc/string/strtok.c b/lib/libc/string/strtok.c index 33d0d685..918765b1 100644 --- a/lib/libc/string/strtok.c +++ b/lib/libc/string/strtok.c @@ -1,5 +1,4 @@ -#include <stddef.h> -#include <string.h> +#include <string.h> // for NULL, strchr, strtok char *strtok(char *restrict s, const char *restrict sep) { diff --git a/lib/libc/string/strtok_r.c b/lib/libc/string/strtok_r.c index 57555b14..ee3fc243 100644 --- a/lib/libc/string/strtok_r.c +++ b/lib/libc/string/strtok_r.c @@ -1,4 +1,4 @@ -#include <string.h> +#include <string.h> // for NULL, strchr, strtok_r char *strtok_r(char *restrict s, const char *restrict sep, char **restrict state) diff --git a/lib/libc/string/strxfrm.c b/lib/libc/string/strxfrm.c index d216733b..947a4331 100644 --- a/lib/libc/string/strxfrm.c +++ b/lib/libc/string/strxfrm.c @@ -1,5 +1,9 @@ -#include <libc.h> -#include <string.h> +#include "__stdio.h" // for size_t +#include "features.h" // for __weak + +#include <libc.h> // for __unused +#include <locale.h> // for locale_t +#include <string.h> // for strlcpy, strlen, strxfrm, strxfrm_l size_t strxfrm(char *restrict s1, const char *restrict s2, size_t n) { diff --git a/lib/libc/strings/strcasecmp.c b/lib/libc/strings/strcasecmp.c index e96f059a..fc38be4a 100644 --- a/lib/libc/strings/strcasecmp.c +++ b/lib/libc/strings/strcasecmp.c @@ -1,5 +1,8 @@ -#include <libc.h> -#include <ctype.h> +#include "features.h" // for __weak + +#include <ctype.h> // for tolower +#include <libc.h> // for __unused +#include <locale.h> // for locale_t int strcasecmp(const char *s1, const char *s2) { diff --git a/lib/libc/strings/strncasecmp.c b/lib/libc/strings/strncasecmp.c index 7c2c9717..12ae0fae 100644 --- a/lib/libc/strings/strncasecmp.c +++ b/lib/libc/strings/strncasecmp.c @@ -1,6 +1,9 @@ -#include <libc.h> -#include <ctype.h> -#include <stddef.h> +#include "__stdio.h" // for size_t +#include "features.h" // for __weak + +#include <ctype.h> // for tolower +#include <libc.h> // for __unused +#include <locale.h> // for locale_t int strncasecmp(const char *s1, const char *s2, size_t n) { diff --git a/lib/libc/sys/ioctl.c b/lib/libc/sys/ioctl.c index 9d7cde36..45fbdca7 100644 --- a/lib/libc/sys/ioctl.c +++ b/lib/libc/sys/ioctl.c @@ -1,5 +1,7 @@ -#include <stdarg.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_ioctl + +#include <stdarg.h> // for va_arg, va_end, va_list, va_start +#include <syscall.h> // for __syscall_3, syscall int ioctl(int fildes, unsigned long request, ...) { diff --git a/lib/libc/sys/mount.c b/lib/libc/sys/mount.c index 0cb95fcf..4ef617b9 100644 --- a/lib/libc/sys/mount.c +++ b/lib/libc/sys/mount.c @@ -1,5 +1,7 @@ -#include <syscall.h> -#include <sys/mount.h> +#include "asm/unistd_64.h" // for __NR_mount + +#include <sys/mount.h> // for mount +#include <syscall.h> // for __syscall_5, syscall int mount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *_Nullable data) diff --git a/lib/libc/sys/umount.c b/lib/libc/sys/umount.c index ae1ecf8a..91ce5a77 100644 --- a/lib/libc/sys/umount.c +++ b/lib/libc/sys/umount.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_umount2 + +#include <syscall.h> // for __syscall_2, syscall int umount(const char *target) { diff --git a/lib/libc/sys/umount2.c b/lib/libc/sys/umount2.c index a75588a8..12f37f98 100644 --- a/lib/libc/sys/umount2.c +++ b/lib/libc/sys/umount2.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_umount2 + +#include <syscall.h> // for __syscall_2, syscall int umount2(const char *target, int flags) { diff --git a/lib/libc/syslog/closelog.c b/lib/libc/syslog/closelog.c index df9b5a49..58efcf07 100644 --- a/lib/libc/syslog/closelog.c +++ b/lib/libc/syslog/closelog.c @@ -1,4 +1,4 @@ -#include <syslog.h> +#include <syslog.h> // for closelog void closelog(void) { diff --git a/lib/libc/syslog/openlog.c b/lib/libc/syslog/openlog.c index 0abf8bb8..5248540e 100644 --- a/lib/libc/syslog/openlog.c +++ b/lib/libc/syslog/openlog.c @@ -1,4 +1,4 @@ -#include <syslog.h> +#include <syslog.h> // for setlogmask int setlogmask(int maskpri) { diff --git a/lib/libc/syslog/setlogmask.c b/lib/libc/syslog/setlogmask.c index 0abf8bb8..5248540e 100644 --- a/lib/libc/syslog/setlogmask.c +++ b/lib/libc/syslog/setlogmask.c @@ -1,4 +1,4 @@ -#include <syslog.h> +#include <syslog.h> // for setlogmask int setlogmask(int maskpri) { diff --git a/lib/libc/uio/readv.c b/lib/libc/uio/readv.c index baca678d..2a69d02c 100644 --- a/lib/libc/uio/readv.c +++ b/lib/libc/uio/readv.c @@ -1,8 +1,10 @@ -#include <unistd.h> -#include <linux/uio.h> -#include <syscall.h> -#include <errno.h> -#include <string.h> +#include <linux/uio.h> // for iovec, UIO_MAXIOV +#include "asm/unistd_64.h" // for __NR_readv + +#include <errno.h> // for errno, EAGAIN, EINTR, EINVAL +#include <string.h> // for memcpy +#include <sys/types.h> // for ssize_t, size_t +#include <syscall.h> // for __syscall_3, syscall ssize_t readv(int fd, const struct iovec *iov, int iovcnt) { @@ -29,8 +31,10 @@ ssize_t readv(int fd, const struct iovec *iov, int iovcnt) return total; return ret; } - if (ret == 0) + + if (ret == 0) { break; // EOF + } total += ret; diff --git a/lib/libc/uio/writev.c b/lib/libc/uio/writev.c index 6f629ba0..d59e7d8f 100644 --- a/lib/libc/uio/writev.c +++ b/lib/libc/uio/writev.c @@ -1,8 +1,11 @@ -#include <unistd.h> -#include <syscall.h> -#include <errno.h> -#include <string.h> -#include <linux/uio.h> +#include "asm/unistd_64.h" // for __NR_writev + +#include <errno.h> // for errno, EAGAIN, EINTR, EINVAL +#include <string.h> // for memcpy +#include <sys/types.h> // for ssize_t, size_t +#include <syscall.h> // for __syscall_3, syscall + +#include <linux/uio.h> // for iovec, UIO_MAXIOV ssize_t writev(int fd, const struct iovec *iov, int iovcnt) { diff --git a/lib/libc/unistd/_Fork.c b/lib/libc/unistd/_Fork.c index 080dd880..5ad326da 100644 --- a/lib/libc/unistd/_Fork.c +++ b/lib/libc/unistd/_Fork.c @@ -1,6 +1,8 @@ -#include <unistd.h> -#include <syscall.h> -#include <linux/signal.h> +#include "asm/unistd_64.h" // for __NR_clone + +#include <signal.h> // for SIGCHLD +#include <syscall.h> // for __syscall_2, syscall +#include <unistd.h> // for _Fork, pid_t pid_t _Fork(void) { diff --git a/lib/libc/unistd/_exit.c b/lib/libc/unistd/_exit.c index ffd502c4..f45312d3 100644 --- a/lib/libc/unistd/_exit.c +++ b/lib/libc/unistd/_exit.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_exit + +#include <syscall.h> // for __syscall, __syscall_1 void _exit(int status) { diff --git a/lib/libc/unistd/access.c b/lib/libc/unistd/access.c index 7735d8c4..17b910b4 100644 --- a/lib/libc/unistd/access.c +++ b/lib/libc/unistd/access.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_access + +#include <syscall.h> // for __syscall_2, syscall int access(const char *path, int amode) { diff --git a/lib/libc/unistd/alarm.c b/lib/libc/unistd/alarm.c index 5d171cc7..a1d61698 100644 --- a/lib/libc/unistd/alarm.c +++ b/lib/libc/unistd/alarm.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_alarm + +#include <syscall.h> // for __syscall_1, syscall unsigned alarm(unsigned seconds) { diff --git a/lib/libc/unistd/chdir.c b/lib/libc/unistd/chdir.c index 5c66cc0c..42f108ae 100644 --- a/lib/libc/unistd/chdir.c +++ b/lib/libc/unistd/chdir.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_chdir + +#include <syscall.h> // for __syscall_1, syscall int chdir(const char *path) { diff --git a/lib/libc/unistd/chown.c b/lib/libc/unistd/chown.c index fa7e0e7b..50ce565e 100644 --- a/lib/libc/unistd/chown.c +++ b/lib/libc/unistd/chown.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_chown + +#include <syscall.h> // for __syscall_3, syscall +#include <unistd.h> // for chown, gid_t, uid_t int chown(const char *path, uid_t owner, gid_t group) { diff --git a/lib/libc/unistd/close.c b/lib/libc/unistd/close.c index 57e45c33..fe55533e 100644 --- a/lib/libc/unistd/close.c +++ b/lib/libc/unistd/close.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_close + +#include <syscall.h> // for __syscall_1, syscall int close(int fildes) { diff --git a/lib/libc/unistd/dup.c b/lib/libc/unistd/dup.c index 764c16f6..9342a6a4 100644 --- a/lib/libc/unistd/dup.c +++ b/lib/libc/unistd/dup.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_dup + +#include <syscall.h> // for __syscall_1, syscall int dup(int fildes) { diff --git a/lib/libc/unistd/dup2.c b/lib/libc/unistd/dup2.c index ce1125ac..f810424b 100644 --- a/lib/libc/unistd/dup2.c +++ b/lib/libc/unistd/dup2.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_dup2 + +#include <syscall.h> // for __syscall_2, syscall int dup2(int fildes, int fildes2) { diff --git a/lib/libc/unistd/dup3.c b/lib/libc/unistd/dup3.c index aa9c0fab..bb9c6381 100644 --- a/lib/libc/unistd/dup3.c +++ b/lib/libc/unistd/dup3.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_dup3 + +#include <syscall.h> // for __syscall_3, syscall int dup3(int fildes, int fildes2, int flag) { diff --git a/lib/libc/unistd/execl.c b/lib/libc/unistd/execl.c index 5dc7bc74..568d49a2 100644 --- a/lib/libc/unistd/execl.c +++ b/lib/libc/unistd/execl.c @@ -1,6 +1,6 @@ -#include <stdarg.h> -#include <stddef.h> -#include <unistd.h> +#include <stdarg.h> // for va_arg, va_end, va_start, va_list +#include <stddef.h> // for NULL +#include <unistd.h> // for execvp, execl int execl(const char *path, const char *argv0, ...) { diff --git a/lib/libc/unistd/execlp.c b/lib/libc/unistd/execlp.c index db044d50..6857970f 100644 --- a/lib/libc/unistd/execlp.c +++ b/lib/libc/unistd/execlp.c @@ -1,5 +1,6 @@ -#include <stdarg.h> -#include <unistd.h> +#include <stdarg.h> // for va_arg, va_end, va_start, va_list +#include <stddef.h> // for NULL +#include <unistd.h> // for execve, execlp int execlp(const char *path, const char *argv0, ...) { diff --git a/lib/libc/unistd/execv.c b/lib/libc/unistd/execv.c index 60ee6d87..99793833 100644 --- a/lib/libc/unistd/execv.c +++ b/lib/libc/unistd/execv.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_execve + +#include <syscall.h> // for __syscall_3, syscall +#include <unistd.h> // for execv extern char **environ; diff --git a/lib/libc/unistd/execve.c b/lib/libc/unistd/execve.c index 43226d98..a91776f3 100644 --- a/lib/libc/unistd/execve.c +++ b/lib/libc/unistd/execve.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_execve + +#include <syscall.h> // for __syscall_3, syscall int execve(const char *file, char *const argv[], char *const envp[]) { diff --git a/lib/libc/unistd/execvp.c b/lib/libc/unistd/execvp.c index c678ed36..88cde91e 100644 --- a/lib/libc/unistd/execvp.c +++ b/lib/libc/unistd/execvp.c @@ -1,9 +1,9 @@ -#include <errno.h> -#include <limits.h> -#include <string.h> -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> +#include <errno.h> // for errno, ENAMETOOLONG, ENOENT +#include <limits.h> // for PATH_MAX +#include <stdio.h> // for NULL, snprintf +#include <stdlib.h> // for getenv +#include <string.h> // for strchr, strlen, strstr +#include <unistd.h> // for execv, execvp extern char **environ; diff --git a/lib/libc/unistd/faccessat.c b/lib/libc/unistd/faccessat.c index 61680aea..3087db1c 100644 --- a/lib/libc/unistd/faccessat.c +++ b/lib/libc/unistd/faccessat.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_faccessat + +#include <syscall.h> // for __syscall_4, syscall int faccessat(int fd, const char *path, int amode, int flag) { diff --git a/lib/libc/unistd/fchdir.c b/lib/libc/unistd/fchdir.c index 9c0ed172..b2147b31 100644 --- a/lib/libc/unistd/fchdir.c +++ b/lib/libc/unistd/fchdir.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_fchdir + +#include <syscall.h> // for __syscall_1, syscall int fchdir(int fildes) { diff --git a/lib/libc/unistd/fchown.c b/lib/libc/unistd/fchown.c index ba0ff964..29d5b969 100644 --- a/lib/libc/unistd/fchown.c +++ b/lib/libc/unistd/fchown.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_fchown + +#include <syscall.h> // for __syscall_3, syscall +#include <unistd.h> // for fchown, gid_t, uid_t int fchown(int fildes, uid_t owner, gid_t group) { diff --git a/lib/libc/unistd/fchownat.c b/lib/libc/unistd/fchownat.c index 3e08472b..c501ca65 100644 --- a/lib/libc/unistd/fchownat.c +++ b/lib/libc/unistd/fchownat.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_fchownat + +#include <syscall.h> // for __syscall_5, syscall +#include <unistd.h> // for fchownat, gid_t, uid_t int fchownat(int fd, const char *path, uid_t owner, gid_t group, int flag) { diff --git a/lib/libc/unistd/fdatasync.c b/lib/libc/unistd/fdatasync.c index e65c79f0..50a91225 100644 --- a/lib/libc/unistd/fdatasync.c +++ b/lib/libc/unistd/fdatasync.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_fdatasync + +#include <syscall.h> // for __syscall_1, syscall int fdatasync(int fildes) { diff --git a/lib/libc/unistd/fork.c b/lib/libc/unistd/fork.c index 38657406..dae69860 100644 --- a/lib/libc/unistd/fork.c +++ b/lib/libc/unistd/fork.c @@ -1,4 +1,4 @@ -#include <unistd.h> +#include <unistd.h> // for _Fork, fork, pid_t pid_t fork(void) { diff --git a/lib/libc/unistd/fsync.c b/lib/libc/unistd/fsync.c index e92e1cc1..e821dc3e 100644 --- a/lib/libc/unistd/fsync.c +++ b/lib/libc/unistd/fsync.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_fsync + +#include <syscall.h> // for __syscall_1, syscall int fsync(int fildes) { diff --git a/lib/libc/unistd/ftruncate.c b/lib/libc/unistd/ftruncate.c index f032ed1b..fc42046b 100644 --- a/lib/libc/unistd/ftruncate.c +++ b/lib/libc/unistd/ftruncate.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_ftruncate + +#include <syscall.h> // for __syscall_2, syscall +#include <unistd.h> // for ftruncate, off_t int ftruncate(int fildes, off_t length) { diff --git a/lib/libc/unistd/getcwd.c b/lib/libc/unistd/getcwd.c index 5494f6e3..54fa5ca9 100644 --- a/lib/libc/unistd/getcwd.c +++ b/lib/libc/unistd/getcwd.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_getcwd + +#include <syscall.h> // for __syscall_2, syscall +#include <unistd.h> // for getcwd, size_t char *getcwd(char *buf, size_t size) { diff --git a/lib/libc/unistd/getegid.c b/lib/libc/unistd/getegid.c index b50e5839..696523e2 100644 --- a/lib/libc/unistd/getegid.c +++ b/lib/libc/unistd/getegid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_getegid + +#include <syscall.h> // for __syscall_0, syscall +#include <unistd.h> // for getegid, gid_t gid_t getegid(void) { diff --git a/lib/libc/unistd/getentropy.c b/lib/libc/unistd/getentropy.c index 3a651ba5..feab9328 100644 --- a/lib/libc/unistd/getentropy.c +++ b/lib/libc/unistd/getentropy.c @@ -1,5 +1,4 @@ -#include <unistd.h> -#include <syscall.h> +#include <unistd.h> // for getentropy, size_t int getentropy(void *buffer, size_t length) { diff --git a/lib/libc/unistd/geteuid.c b/lib/libc/unistd/geteuid.c index aee26a42..a66c159c 100644 --- a/lib/libc/unistd/geteuid.c +++ b/lib/libc/unistd/geteuid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_geteuid + +#include <syscall.h> // for __syscall_0, syscall +#include <unistd.h> // for geteuid, gid_t gid_t geteuid(void) { diff --git a/lib/libc/unistd/getgid.c b/lib/libc/unistd/getgid.c index 7d19d58e..1c206911 100644 --- a/lib/libc/unistd/getgid.c +++ b/lib/libc/unistd/getgid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_getgid + +#include <syscall.h> // for __syscall_0, syscall +#include <unistd.h> // for getgid, gid_t gid_t getgid(void) { diff --git a/lib/libc/unistd/getgroups.c b/lib/libc/unistd/getgroups.c index fb1346e5..dbb9abb3 100644 --- a/lib/libc/unistd/getgroups.c +++ b/lib/libc/unistd/getgroups.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_getgroups + +#include <syscall.h> // for __syscall_2, syscall +#include <unistd.h> // for getgroups, gid_t int getgroups(int gidsetsize, gid_t grouplist[]) { diff --git a/lib/libc/unistd/gethostid.c b/lib/libc/unistd/gethostid.c index e3079534..37f325b6 100644 --- a/lib/libc/unistd/gethostid.c +++ b/lib/libc/unistd/gethostid.c @@ -1,4 +1,3 @@ -#include <syscall.h> long gethostid(void) { diff --git a/lib/libc/unistd/gethostname.c b/lib/libc/unistd/gethostname.c index 5bd303f5..caa870da 100644 --- a/lib/libc/unistd/gethostname.c +++ b/lib/libc/unistd/gethostname.c @@ -1,5 +1,4 @@ -#include <unistd.h> -#include <syscall.h> +#include <unistd.h> // for gethostname, size_t int gethostname(char *name, size_t namelen) { diff --git a/lib/libc/unistd/getlogin.c b/lib/libc/unistd/getlogin.c index 04355db1..921a00d6 100644 --- a/lib/libc/unistd/getlogin.c +++ b/lib/libc/unistd/getlogin.c @@ -1,4 +1,3 @@ -#include <syscall.h> char *getlogin(void) { diff --git a/lib/libc/unistd/getlogin_r.c b/lib/libc/unistd/getlogin_r.c index 70ae5ddd..018453fb 100644 --- a/lib/libc/unistd/getlogin_r.c +++ b/lib/libc/unistd/getlogin_r.c @@ -1,5 +1,4 @@ -#include <unistd.h> -#include <syscall.h> +#include <unistd.h> // for getlogin_r, size_t int getlogin_r(char *name, size_t namesize) { diff --git a/lib/libc/unistd/getopt.c b/lib/libc/unistd/getopt.c index 8ef18d37..0a3b38cb 100644 --- a/lib/libc/unistd/getopt.c +++ b/lib/libc/unistd/getopt.c @@ -1,7 +1,6 @@ -#include <unistd.h> -#include <stdio.h> -#include <string.h> -#include <sys/uio.h> +#include <string.h> // for strlen +#include <sys/uio.h> // for iovec, writev +#include <unistd.h> // for STDERR_FILENO, getopt, optarg, opterr, optind char *optarg; int optind = 1, opterr = 1, optopt; diff --git a/lib/libc/unistd/getpgid.c b/lib/libc/unistd/getpgid.c index aed55bb9..d78396aa 100644 --- a/lib/libc/unistd/getpgid.c +++ b/lib/libc/unistd/getpgid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_getpgid + +#include <syscall.h> // for __syscall_1, syscall +#include <unistd.h> // for pid_t, getpgid pid_t getpgid(pid_t pid) { diff --git a/lib/libc/unistd/getpid.c b/lib/libc/unistd/getpid.c index 46562867..57ea18c6 100644 --- a/lib/libc/unistd/getpid.c +++ b/lib/libc/unistd/getpid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_getpid + +#include <syscall.h> // for __syscall_0, syscall +#include <unistd.h> // for getpid, pid_t pid_t getpid(void) { diff --git a/lib/libc/unistd/getppid.c b/lib/libc/unistd/getppid.c index 16bf101e..bf994995 100644 --- a/lib/libc/unistd/getppid.c +++ b/lib/libc/unistd/getppid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_getppid + +#include <syscall.h> // for __syscall_0, syscall +#include <unistd.h> // for getppid, pid_t pid_t getppid(void) { diff --git a/lib/libc/unistd/getresgid.c b/lib/libc/unistd/getresgid.c index ccdbabaa..60c818cc 100644 --- a/lib/libc/unistd/getresgid.c +++ b/lib/libc/unistd/getresgid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_getresgid + +#include <syscall.h> // for __syscall_3, syscall +#include <unistd.h> // for gid_t, getresgid int getresgid(gid_t *restrict rgid, gid_t *restrict egid, gid_t *restrict sgid) { diff --git a/lib/libc/unistd/getresuid.c b/lib/libc/unistd/getresuid.c index a9a405ae..7d26f610 100644 --- a/lib/libc/unistd/getresuid.c +++ b/lib/libc/unistd/getresuid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_getresuid + +#include <syscall.h> // for __syscall_3, syscall +#include <unistd.h> // for uid_t, getresuid int getresuid(uid_t *restrict ruid, uid_t *restrict euid, uid_t *restrict suid) { diff --git a/lib/libc/unistd/getsid.c b/lib/libc/unistd/getsid.c index e0a06780..46518105 100644 --- a/lib/libc/unistd/getsid.c +++ b/lib/libc/unistd/getsid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_getsid + +#include <syscall.h> // for __syscall_1, syscall +#include <unistd.h> // for pid_t, getsid pid_t getsid(pid_t pid) { diff --git a/lib/libc/unistd/getuid.c b/lib/libc/unistd/getuid.c index 9223ae6f..67289d54 100644 --- a/lib/libc/unistd/getuid.c +++ b/lib/libc/unistd/getuid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_getuid + +#include <syscall.h> // for __syscall_0, syscall +#include <unistd.h> // for getuid, uid_t uid_t getuid(void) { diff --git a/lib/libc/unistd/isatty.c b/lib/libc/unistd/isatty.c index afb15460..c253e14a 100644 --- a/lib/libc/unistd/isatty.c +++ b/lib/libc/unistd/isatty.c @@ -1,7 +1,9 @@ -#include <termios.h> -#include <unistd.h> -#include <syscall.h> -#include <asm-generic/ioctls.h> +#include "asm/unistd_64.h" // for __NR_ioctl + +#include <asm-generic/ioctls.h> // for TIOCGWINSZ +#include <syscall.h> // for __syscall_3, syscall +#include <termios.h> // for winsize +#include <unistd.h> // for isatty int isatty(int fildes) { diff --git a/lib/libc/unistd/lchown.c b/lib/libc/unistd/lchown.c index a18be4c6..ea5f4700 100644 --- a/lib/libc/unistd/lchown.c +++ b/lib/libc/unistd/lchown.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_lchown + +#include <syscall.h> // for __syscall_3, syscall +#include <unistd.h> // for gid_t, lchown, uid_t int lchown(const char *path, uid_t owner, gid_t group) { diff --git a/lib/libc/unistd/link.c b/lib/libc/unistd/link.c index 07204ed0..9b00d16c 100644 --- a/lib/libc/unistd/link.c +++ b/lib/libc/unistd/link.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_link + +#include <syscall.h> // for __syscall_2, syscall +#include <unistd.h> // for link int link(const char *path1, const char *path2) { diff --git a/lib/libc/unistd/linkat.c b/lib/libc/unistd/linkat.c index 72dca11e..378bbb4d 100644 --- a/lib/libc/unistd/linkat.c +++ b/lib/libc/unistd/linkat.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_linkat + +#include <syscall.h> // for __syscall_5, syscall +#include <unistd.h> // for linkat int linkat(int fd1, const char *path1, int fd2, const char *path2, int flag) { diff --git a/lib/libc/unistd/lockf.c b/lib/libc/unistd/lockf.c index 6f109c55..824f1cef 100644 --- a/lib/libc/unistd/lockf.c +++ b/lib/libc/unistd/lockf.c @@ -1,5 +1,4 @@ -#include <unistd.h> -#include <syscall.h> +#include <unistd.h> // for lockf, off_t int lockf(int fildes, int function, off_t size) { diff --git a/lib/libc/unistd/lseek.c b/lib/libc/unistd/lseek.c index d8b41f88..fb574f7b 100644 --- a/lib/libc/unistd/lseek.c +++ b/lib/libc/unistd/lseek.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_lseek + +#include <syscall.h> // for __syscall_3, syscall +#include <unistd.h> // for off_t, lseek off_t lseek(int fildes, off_t offset, int whence) { diff --git a/lib/libc/unistd/nice.c b/lib/libc/unistd/nice.c index 6da984df..78dccbb0 100644 --- a/lib/libc/unistd/nice.c +++ b/lib/libc/unistd/nice.c @@ -1,5 +1,4 @@ -#include <unistd.h> -#include <syscall.h> +#include <unistd.h> // for nice int nice(int incr) { diff --git a/lib/libc/unistd/pause.c b/lib/libc/unistd/pause.c index bd959bc5..98ff98d4 100644 --- a/lib/libc/unistd/pause.c +++ b/lib/libc/unistd/pause.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_pause + +#include <syscall.h> // for __syscall_0, syscall int pause(void) { diff --git a/lib/libc/unistd/pipe.c b/lib/libc/unistd/pipe.c index 4f8e0e98..3c1509d0 100644 --- a/lib/libc/unistd/pipe.c +++ b/lib/libc/unistd/pipe.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_pipe + +#include <syscall.h> // for __syscall_1, syscall int pipe(int fildes[2]) { diff --git a/lib/libc/unistd/pipe2.c b/lib/libc/unistd/pipe2.c index a28aecdd..5ac36338 100644 --- a/lib/libc/unistd/pipe2.c +++ b/lib/libc/unistd/pipe2.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_pipe2 + +#include <syscall.h> // for __syscall_2, syscall int pipe2(int fildes[2], int flag) { diff --git a/lib/libc/unistd/posix_close.c b/lib/libc/unistd/posix_close.c index 78ec692e..95c7686f 100644 --- a/lib/libc/unistd/posix_close.c +++ b/lib/libc/unistd/posix_close.c @@ -1,5 +1,7 @@ -#include <libc.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_close + +#include <libc.h> // for __unused +#include <syscall.h> // for __syscall_1, syscall int posix_close(int fildes, int __unused flag) { diff --git a/lib/libc/unistd/pread.c b/lib/libc/unistd/pread.c index ad8e71b0..0e7aaaff 100644 --- a/lib/libc/unistd/pread.c +++ b/lib/libc/unistd/pread.c @@ -1,5 +1,5 @@ -#include <unistd.h> -#include <syscall.h> +#include <syscall.h> // for __NR_pread, __syscall_4, syscall +#include <unistd.h> // for off_t, pread, size_t, ssize_t ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset) { diff --git a/lib/libc/unistd/pwrite.c b/lib/libc/unistd/pwrite.c index 8a2eadbe..8c2e66f0 100644 --- a/lib/libc/unistd/pwrite.c +++ b/lib/libc/unistd/pwrite.c @@ -1,5 +1,5 @@ -#include <unistd.h> -#include <syscall.h> +#include <syscall.h> // for __NR_pwrite, __syscall_4, syscall +#include <unistd.h> // for off_t, pwrite, size_t, ssize_t ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset) { diff --git a/lib/libc/unistd/read.c b/lib/libc/unistd/read.c index 54c29586..cd9d4bf4 100644 --- a/lib/libc/unistd/read.c +++ b/lib/libc/unistd/read.c @@ -1,5 +1,7 @@ -#include <syscall.h> -#include <unistd.h> +#include "asm/unistd_64.h" // for __NR_read + +#include <syscall.h> // for __syscall_3, syscall +#include <unistd.h> // for read, size_t, ssize_t ssize_t read(int fildes, void *buf, size_t nbyte) { diff --git a/lib/libc/unistd/readlink.c b/lib/libc/unistd/readlink.c index 8587f526..e8d97d80 100644 --- a/lib/libc/unistd/readlink.c +++ b/lib/libc/unistd/readlink.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_readlink + +#include <syscall.h> // for __syscall_3, syscall +#include <unistd.h> // for readlink, size_t, ssize_t ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize) { diff --git a/lib/libc/unistd/readlinkat.c b/lib/libc/unistd/readlinkat.c index d2a87b2b..0276f676 100644 --- a/lib/libc/unistd/readlinkat.c +++ b/lib/libc/unistd/readlinkat.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_readlinkat + +#include <syscall.h> // for __syscall_4, syscall +#include <unistd.h> // for readlinkat, size_t, ssize_t ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize) diff --git a/lib/libc/unistd/rmdir.c b/lib/libc/unistd/rmdir.c index 5aab225c..70519c85 100644 --- a/lib/libc/unistd/rmdir.c +++ b/lib/libc/unistd/rmdir.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_rmdir + +#include <syscall.h> // for __syscall_1, syscall int rmdir(const char *path) { diff --git a/lib/libc/unistd/setegid.c b/lib/libc/unistd/setegid.c index 7fd9adb6..50fa2a52 100644 --- a/lib/libc/unistd/setegid.c +++ b/lib/libc/unistd/setegid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_setresgid + +#include <syscall.h> // for __syscall_3, syscall +#include <unistd.h> // for gid_t, setegid int setegid(gid_t gid) { diff --git a/lib/libc/unistd/seteuid.c b/lib/libc/unistd/seteuid.c index 6d86bee5..48fb8b3d 100644 --- a/lib/libc/unistd/seteuid.c +++ b/lib/libc/unistd/seteuid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_setresuid + +#include <syscall.h> // for __syscall_3, syscall +#include <unistd.h> // for seteuid, uid_t int seteuid(uid_t uid) { diff --git a/lib/libc/unistd/setgid.c b/lib/libc/unistd/setgid.c index aa07c330..edf5619a 100644 --- a/lib/libc/unistd/setgid.c +++ b/lib/libc/unistd/setgid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_setgid + +#include <syscall.h> // for __syscall_1, syscall +#include <unistd.h> // for gid_t, setgid int setgid(gid_t gid) { diff --git a/lib/libc/unistd/setpgid.c b/lib/libc/unistd/setpgid.c index e4fd6efd..87f50e8f 100644 --- a/lib/libc/unistd/setpgid.c +++ b/lib/libc/unistd/setpgid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_setpgid + +#include <syscall.h> // for __syscall_2, syscall +#include <unistd.h> // for pid_t, setpgid int setpgid(pid_t pid, pid_t pgid) { diff --git a/lib/libc/unistd/setregid.c b/lib/libc/unistd/setregid.c index 633f22a6..a4d61d8c 100644 --- a/lib/libc/unistd/setregid.c +++ b/lib/libc/unistd/setregid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_setregid + +#include <syscall.h> // for __syscall_2, syscall +#include <unistd.h> // for gid_t, setregid int setregid(gid_t rgid, gid_t egid) { diff --git a/lib/libc/unistd/setresgid.c b/lib/libc/unistd/setresgid.c index 6de609fa..3f288103 100644 --- a/lib/libc/unistd/setresgid.c +++ b/lib/libc/unistd/setresgid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_setresgid + +#include <syscall.h> // for __syscall_3, syscall +#include <unistd.h> // for gid_t, setresgid int setresgid(gid_t rgid, gid_t egid, gid_t sgid) { diff --git a/lib/libc/unistd/setresuid.c b/lib/libc/unistd/setresuid.c index 1fd74baa..4c01b523 100644 --- a/lib/libc/unistd/setresuid.c +++ b/lib/libc/unistd/setresuid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_setresuid + +#include <syscall.h> // for __syscall_3, syscall +#include <unistd.h> // for uid_t, setresuid int setresuid(uid_t ruid, uid_t euid, uid_t suid) { diff --git a/lib/libc/unistd/setreuid.c b/lib/libc/unistd/setreuid.c index 5f277ba3..f41caa3c 100644 --- a/lib/libc/unistd/setreuid.c +++ b/lib/libc/unistd/setreuid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_setreuid + +#include <syscall.h> // for __syscall_2, syscall +#include <unistd.h> // for uid_t, setreuid int setreuid(uid_t ruid, uid_t euid) { diff --git a/lib/libc/unistd/setsid.c b/lib/libc/unistd/setsid.c index 16b812e0..bd81b08a 100644 --- a/lib/libc/unistd/setsid.c +++ b/lib/libc/unistd/setsid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_setsid + +#include <syscall.h> // for __syscall_0, syscall +#include <unistd.h> // for pid_t, setsid pid_t setsid(void) { diff --git a/lib/libc/unistd/setuid.c b/lib/libc/unistd/setuid.c index ab8ff73f..18d9cdc2 100644 --- a/lib/libc/unistd/setuid.c +++ b/lib/libc/unistd/setuid.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_setuid + +#include <syscall.h> // for __syscall_1, syscall +#include <unistd.h> // for setuid, uid_t int setuid(uid_t uid) { diff --git a/lib/libc/unistd/sleep.c b/lib/libc/unistd/sleep.c index b2aef854..2b63a9ed 100644 --- a/lib/libc/unistd/sleep.c +++ b/lib/libc/unistd/sleep.c @@ -1,5 +1,5 @@ -#include <time.h> -#include <unistd.h> +#include <time.h> // for nanosleep, timespec +#include <unistd.h> // for sleep unsigned sleep(unsigned seconds) { diff --git a/lib/libc/unistd/swab.c b/lib/libc/unistd/swab.c index 5e4e7e3b..b1a47c03 100644 --- a/lib/libc/unistd/swab.c +++ b/lib/libc/unistd/swab.c @@ -1,4 +1,4 @@ -#include <unistd.h> +#include <unistd.h> // for ssize_t, swab void swab(const void *restrict src, void *restrict dest, ssize_t nbytes) { diff --git a/lib/libc/unistd/symlink.c b/lib/libc/unistd/symlink.c index 0b84148e..29f10c07 100644 --- a/lib/libc/unistd/symlink.c +++ b/lib/libc/unistd/symlink.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_symlink + +#include <syscall.h> // for __syscall_2, syscall int symlink(const char *path1, const char *path2) { diff --git a/lib/libc/unistd/symlinkat.c b/lib/libc/unistd/symlinkat.c index d4dd2ee0..e5d8135e 100644 --- a/lib/libc/unistd/symlinkat.c +++ b/lib/libc/unistd/symlinkat.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_symlinkat + +#include <syscall.h> // for __syscall_3, syscall int symlinkat(const char *path1, int fd, const char *path2) diff --git a/lib/libc/unistd/sync.c b/lib/libc/unistd/sync.c index e655213b..47818ce9 100644 --- a/lib/libc/unistd/sync.c +++ b/lib/libc/unistd/sync.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_sync + +#include <syscall.h> // for __syscall_0, syscall void sync(void) { diff --git a/lib/libc/unistd/truncate.c b/lib/libc/unistd/truncate.c index 2611d40a..21570da5 100644 --- a/lib/libc/unistd/truncate.c +++ b/lib/libc/unistd/truncate.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_truncate + +#include <syscall.h> // for __syscall_2, syscall +#include <unistd.h> // for off_t, truncate int truncate(const char *path, off_t length) { diff --git a/lib/libc/unistd/unlink.c b/lib/libc/unistd/unlink.c index 1d3859f9..6c699ac8 100644 --- a/lib/libc/unistd/unlink.c +++ b/lib/libc/unistd/unlink.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_unlink + +#include <syscall.h> // for __syscall_1, syscall int unlink(const char *path) { diff --git a/lib/libc/unistd/unlinkat.c b/lib/libc/unistd/unlinkat.c index 837105a1..4a6162ae 100644 --- a/lib/libc/unistd/unlinkat.c +++ b/lib/libc/unistd/unlinkat.c @@ -1,4 +1,6 @@ -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_unlinkat + +#include <syscall.h> // for __syscall_3, syscall int unlinkat(int fd, const char *path, int flag) { diff --git a/lib/libc/unistd/write.c b/lib/libc/unistd/write.c index c7bd5dbc..b0b22403 100644 --- a/lib/libc/unistd/write.c +++ b/lib/libc/unistd/write.c @@ -1,5 +1,7 @@ -#include <unistd.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_write + +#include <syscall.h> // for __syscall_3, syscall +#include <unistd.h> // for size_t, ssize_t, write ssize_t write(int fd, const void *buf, size_t count) { diff --git a/lib/libc/utsname/uname.c b/lib/libc/utsname/uname.c index babf5685..cefa26b6 100644 --- a/lib/libc/utsname/uname.c +++ b/lib/libc/utsname/uname.c @@ -1,5 +1,7 @@ -#include <sys/utsname.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_uname + +#include <sys/utsname.h> // for uname +#include <syscall.h> // for __syscall_1, syscall int uname(struct utsname *name) { diff --git a/lib/libc/wait/wait.c b/lib/libc/wait/wait.c index f0583bfc..262c6b75 100644 --- a/lib/libc/wait/wait.c +++ b/lib/libc/wait/wait.c @@ -1,5 +1,8 @@ -#include <sys/wait.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_wait4 +#include "sys/types.h" // for pid_t + +#include <sys/wait.h> // for wait +#include <syscall.h> // for __syscall_4, syscall pid_t wait(int *stat_loc) { diff --git a/lib/libc/wait/waitid.c b/lib/libc/wait/waitid.c index 5b6237b8..31060ddc 100644 --- a/lib/libc/wait/waitid.c +++ b/lib/libc/wait/waitid.c @@ -1,5 +1,9 @@ -#include <sys/wait.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_waitid + +#include <signal.h> // for siginfo_t +#include <sys/types.h> // for id_t +#include <sys/wait.h> // for idtype_t, waitid +#include <syscall.h> // for __syscall_4, syscall int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) { diff --git a/lib/libc/wait/waitpid.c b/lib/libc/wait/waitpid.c index a5746efc..30acd0f4 100644 --- a/lib/libc/wait/waitpid.c +++ b/lib/libc/wait/waitpid.c @@ -1,5 +1,8 @@ -#include <sys/wait.h> -#include <syscall.h> +#include "asm/unistd_64.h" // for __NR_wait4 +#include "sys/types.h" // for pid_t + +#include <sys/wait.h> // for waitpid +#include <syscall.h> // for __syscall_4, syscall pid_t waitpid(pid_t pid, int *stat_loc, int options) { diff --git a/lib/libm/__complex.h b/lib/libm/__complex.h index 10b22df9..2c54d1e9 100644 --- a/lib/libm/__complex.h +++ b/lib/libm/__complex.h @@ -1,6 +1,7 @@ #ifndef __LIBC_COMPLEX_H__ #define __LIBC_COMPLEX_H__ +#include <sys/cdefs.h> #include <math.h> #include <complex.h> @@ -45,7 +46,7 @@ static const long double DP3 = 0L; #define MACHEPL 1.1e-19L #endif -static void cchsh(double x, double *c, double *s) +void cchsh(double x, double *c, double *s) { double e, ei; @@ -61,7 +62,7 @@ static void cchsh(double x, double *c, double *s) } } -static void cchshl(long double x, long double *c, long double *s) +void cchshl(long double x, long double *c, long double *s) { long double e, ei; @@ -77,7 +78,7 @@ static void cchshl(long double x, long double *c, long double *s) } } -static void cchshf(float x, float *c, float *s) +void cchshf(float x, float *c, float *s) { float e, ei; @@ -93,7 +94,7 @@ static void cchshf(float x, float *c, float *s) } } -static double redupi(double x) +double redupi(double x) { double t; long i; @@ -110,7 +111,7 @@ static double redupi(double x) return t; } -static float redupif(float x) +float redupif(float x) { float t; long i; @@ -143,7 +144,7 @@ static long double redupil(long double x) return ((x - t * DP1) - t * DP2) - t * DP3; } -static long double ctansl(long double complex z) +long double ctansl(long double complex z) { long double f, x, x2, y, y2, rn, t; long double d; diff --git a/lib/libm/__cosl.c b/lib/libm/__cosl.c index 09d42d6b..c7f72114 100644 --- a/lib/libm/__cosl.c +++ b/lib/libm/__cosl.c @@ -42,8 +42,9 @@ * almost for free from the complications needed to search for the best * higher coefficients. */ -static const long double C1 = 0.0416666666666666666136L; /* 0xaaaaaaaaaaaaaa9b.0p-68 - */ +static const long double C1 = + 0.0416666666666666666136L; /* 0xaaaaaaaaaaaaaa9b.0p-68 + */ static const double C2 = -0.0013888888888888874, /* -0x16c16c16c16c10.0p-62 */ C3 = 0.000024801587301571716, /* 0x1a01a01a018e22.0p-68 */ C4 = -0.00000027557319215507120, /* -0x127e4fb7602f22.0p-74 */ diff --git a/lib/libm/__rem_pio2l.c b/lib/libm/__rem_pio2l.c index 6576ade1..f6310774 100644 --- a/lib/libm/__rem_pio2l.c +++ b/lib/libm/__rem_pio2l.c @@ -45,9 +45,10 @@ static const double pio2_1 = 1.57079632679597125389e+00, /* 0x3FF921FB, 0x54444000 */ pio2_2 = -1.07463465549783099519e-12, /* -0x12e7b967674000.0p-92 */ pio2_3 = 6.36831716351370313614e-25; /* 0x18a2e037074000.0p-133 */ -static const long double pio4 = 0x1.921fb54442d1846ap-1L, - invpio2 = 6.36619772367581343076e-01L, /* 0xa2f9836e4e44152a.0p-64 - */ +static const long double + pio4 = 0x1.921fb54442d1846ap-1L, + invpio2 = 6.36619772367581343076e-01L, /* 0xa2f9836e4e44152a.0p-64 + */ pio2_1t = -1.07463465549719416346e-12L, /* -0x973dcb3b399d747f.0p-103 */ pio2_2t = 6.36831716351095013979e-25L, /* 0xc51701b839a25205.0p-144 */ pio2_3t = -2.75299651904407171810e-37L; /* -0xbb5bf6c7ddd660ce.0p-185 */ @@ -60,22 +61,29 @@ static const long double pio4 = 0x1.921fb54442d1846ap-1L, #define ROUND2 119 #define NX 5 #define NY 3 -static const long double pio4 = 0x1.921fb54442d18469898cc51701b8p-1L, - invpio2 = - 6.3661977236758134307553505349005747e-01L, /* 0x145f306dc9c882a53f84eafa3ea6a.0p-113 - */ - pio2_1 = 1.5707963267948966192292994253909555e+00L, /* 0x1921fb54442d18469800000000000.0p-112 +static const long double + pio4 = 0x1.921fb54442d18469898cc51701b8p-1L, + invpio2 = + 6.3661977236758134307553505349005747e-01L, /* 0x145f306dc9c882a53f84eafa3ea6a.0p-113 + */ + pio2_1 = + 1.5707963267948966192292994253909555e+00L, /* 0x1921fb54442d18469800000000000.0p-112 + */ + pio2_1t = + 2.0222662487959507323996846200947577e-21L, /* 0x13198a2e03707344a4093822299f3.0p-181 + */ + pio2_2 = + 2.0222662487959507323994779168837751e-21L, /* 0x13198a2e03707344a400000000000.0p-181 + */ + pio2_2t = + 2.0670321098263988236496903051604844e-43L, /* 0x127044533e63a0105df531d89cd91.0p-254 + */ + pio2_3 = + 2.0670321098263988236499468110329591e-43L, /* 0x127044533e63a0105e00000000000.0p-254 + */ + pio2_3t = + -2.5650587247459238361625433492959285e-65L; /* -0x159c4ec64ddaeb5f78671cbfb2210.0p-327 */ - pio2_1t = 2.0222662487959507323996846200947577e-21L, /* 0x13198a2e03707344a4093822299f3.0p-181 - */ - pio2_2 = 2.0222662487959507323994779168837751e-21L, /* 0x13198a2e03707344a400000000000.0p-181 - */ - pio2_2t = 2.0670321098263988236496903051604844e-43L, /* 0x127044533e63a0105df531d89cd91.0p-254 - */ - pio2_3 = 2.0670321098263988236499468110329591e-43L, /* 0x127044533e63a0105e00000000000.0p-254 - */ - pio2_3t = -2.5650587247459238361625433492959285e-65L; /* -0x159c4ec64ddaeb5f78671cbfb2210.0p-327 - */ #endif int __rem_pio2l(long double x, long double *y) diff --git a/lib/libm/__sinl.c b/lib/libm/__sinl.c index afd36211..6b57783e 100644 --- a/lib/libm/__sinl.c +++ b/lib/libm/__sinl.c @@ -25,8 +25,9 @@ * * See __cosl.c for more details about the polynomial. */ -static const long double S1 = -0.166666666666666666671L; /* -0xaaaaaaaaaaaaaaab.0p-66 - */ +static const long double S1 = + -0.166666666666666666671L; /* -0xaaaaaaaaaaaaaaab.0p-66 + */ static const double S2 = 0.0083333333333333332, /* 0x11111111111111.0p-59 */ S3 = -0.00019841269841269427, /* -0x1a01a01a019f81.0p-65 */ S4 = 0.0000027557319223597490, /* 0x171de3a55560f7.0p-71 */ diff --git a/lib/libm/__tanl.c b/lib/libm/__tanl.c index b279051f..7526735c 100644 --- a/lib/libm/__tanl.c +++ b/lib/libm/__tanl.c @@ -24,8 +24,9 @@ * * See __cosl.c for more details about the polynomial. */ -static const long double T3 = 0.333333333333333333180L, /* 0xaaaaaaaaaaaaaaa5.0p-65 - */ +static const long double + T3 = 0.333333333333333333180L, /* 0xaaaaaaaaaaaaaaa5.0p-65 + */ T5 = 0.133333333333333372290L, /* 0x88888888888893c3.0p-66 */ T7 = 0.0539682539682504975744L, /* 0xdd0dd0dd0dc13ba2.0p-68 */ pio4 = 0.785398163397448309628L, /* 0xc90fdaa22168c235.0p-64 */ diff --git a/lib/libm/cacoshf.c b/lib/libm/cacoshf.c index 67c9258b..63d23257 100644 --- a/lib/libm/cacoshf.c +++ b/lib/libm/cacoshf.c @@ -2,7 +2,5 @@ float complex cacoshf(float complex z) { - float complex w; - return clogf(z + csqrtf(z + 1) * csqrtf(z - 1)); } diff --git a/lib/libm/lgamma_r.c b/lib/libm/lgamma_r.c index 00eeb27b..6cb89858 100644 --- a/lib/libm/lgamma_r.c +++ b/lib/libm/lgamma_r.c @@ -253,9 +253,10 @@ double __lgamma_r(double x, int *signgamp) z = y * y; w = z * y; p1 = t0 + - w * (t3 + w * (t6 + w * (t9 + w * t12))); /* parallel - comp - */ + w * (t3 + + w * (t6 + w * (t9 + w * t12))); /* parallel + comp + */ p2 = t1 + w * (t4 + w * (t7 + w * (t10 + w * t13))); p3 = t2 + w * (t5 + w * (t8 + w * (t11 + w * t14))); p = z * p1 - (tt - w * (p2 + y * p3)); diff --git a/lib/libm/lgammaf_r.c b/lib/libm/lgammaf_r.c index 4b63298e..b1a02fb8 100644 --- a/lib/libm/lgammaf_r.c +++ b/lib/libm/lgammaf_r.c @@ -187,9 +187,10 @@ float __lgammaf_r(float x, int *signgamp) z = y * y; w = z * y; p1 = t0 + - w * (t3 + w * (t6 + w * (t9 + w * t12))); /* parallel - comp - */ + w * (t3 + + w * (t6 + w * (t9 + w * t12))); /* parallel + comp + */ p2 = t1 + w * (t4 + w * (t7 + w * (t10 + w * t13))); p3 = t2 + w * (t5 + w * (t8 + w * (t11 + w * t14))); p = z * p1 - (tt - w * (p2 + y * p3)); diff --git a/lib/libm/libm.a b/lib/libm/libm.a Binary files differindex 6a4a03c3..036141da 100644 --- a/lib/libm/libm.a +++ b/lib/libm/libm.a diff --git a/lib/libm/projf.c b/lib/libm/projf.c index 4efd9605..a0bcf369 100644 --- a/lib/libm/projf.c +++ b/lib/libm/projf.c @@ -3,9 +3,11 @@ float complex cprojf(float complex z) { float_complex w = { .z = z }; + if (isinf(crealf(z)) || isinf(cimagf(z))) { REAL_PART(w) = INFINITY; IMAG_PART(w) = copysignf(0.0, cimagf(z)); } - return (w.z); + + return w.z; } @@ -10,6 +10,7 @@ export MSG = @printf '\033[34m%-8s\033[0m %s\n' this-makefile = $(lastword $(MAKEFILE_LIST)) srctree = $(realpath $(dir $(this-makefile))) +.DEFAULT_GOAL := all LLVM ?= 1 ifneq ($(LLVM),1) @@ -37,6 +38,10 @@ ifndef ARCH ARCH := x86_64 endif +ifeq ($(CCACHE),1) + CC := ccache $(CC) +endif + export CC LD AR STRIP CROSS_COMPILE ARCH ifeq ($(V),1) @@ -77,6 +82,14 @@ KBUILD_CFLAGS += -fno-stack-check # Weird loops transformations to wcslen KBUILD_CFLAGS += -fno-builtin-wcslen +ifeq ($(CONFIG_WERROR),y) +KBUILD_CFLAGS += -Werror +endif + +ifeq ($(CONFIG_DEBUG),y) +KBUILD_CFLAGS += -g -Og -fno-omit-frame-pointer +endif + KBUILD_ASFLAGS := # Assembly does not need -nostdinc; clang warns it is unused. @@ -131,15 +144,22 @@ defconfig: $(Q)$(MAKE) -f scripts/kconfig/makefile defconfig include-what-you-use: compile_commands.json - $(Q)iwyu_tool.py -p. -j$(nproc) -- \ - --update_comments | \ + $(Q)iwyu_tool.py -p. -j$(nproc) -- -Xiwyu --update_comments -Xiwyu --transitive_includes_only -Xiwyu --no_internal_mappings | \ fix_includes.py --comments \ --quoted_includes_first \ + --nosafe_headers \ --update_comments \ --reorder clang-tidy: compile_commands.json - $(Q)clang-tidy -header-filter=.* -p=. $(shell find . -name '*.c' -o -name '*.h' | grep -v './scripts/\|dtoa\|linux\|arch\|bits') + $(Q)run-clang-tidy.py \ + -p . \ + -fix \ + -fix-errors \ + -header-filter='.*' \ + -source-filter='.*\.(c|h)$$' \ + -exclude-header-filter='(scripts/|dtoa|linux|arch|bits)' \ + -j $(shell nproc) clang-format: $(Q)clang-format -i $(shell find . -name '*.c' -o -name '*.h' | grep -v './scripts/') diff --git a/scripts/makefile.build b/scripts/makefile.build index b5b9aebc..fe8f1a78 100644 --- a/scripts/makefile.build +++ b/scripts/makefile.build @@ -2,6 +2,7 @@ obj-y := obj-m := always := targets := +.DEFAULT_GOAL := all src := $(patsubst %/,%,$(obj)) |
