summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/arch/x86_64/clock_gettime.c8
-rw-r--r--lib/libc/arch/x86_64/crt0.c13
-rw-r--r--lib/libc/arch/x86_64/longjmp.c4
-rw-r--r--lib/libc/arch/x86_64/setjmp.c4
-rw-r--r--lib/libc/arch/x86_64/sigsetjmp.c2
-rw-r--r--lib/libc/arch/x86_64/vdso_setup.c8
-rw-r--r--lib/libc/arpa/htonl.c5
-rw-r--r--lib/libc/arpa/htons.c5
-rw-r--r--lib/libc/arpa/inet_addr.c2
-rw-r--r--lib/libc/arpa/inet_ntoa.c2
-rw-r--r--lib/libc/arpa/inet_pton.c2
-rw-r--r--lib/libc/arpa/ntohl.c5
-rw-r--r--lib/libc/arpa/ntohs.c5
-rw-r--r--lib/libc/assert/assert.c4
-rw-r--r--lib/libc/ctype/isalnum.c7
-rw-r--r--lib/libc/ctype/isalpha.c2
-rw-r--r--lib/libc/ctype/isblank.c2
-rw-r--r--lib/libc/ctype/iscntrl.c2
-rw-r--r--lib/libc/ctype/isdigit.c2
-rw-r--r--lib/libc/ctype/isgraph.c2
-rw-r--r--lib/libc/ctype/islower.c2
-rw-r--r--lib/libc/ctype/isprint.c2
-rw-r--r--lib/libc/ctype/ispunct.c7
-rw-r--r--lib/libc/ctype/isspace.c2
-rw-r--r--lib/libc/ctype/isupper.c2
-rw-r--r--lib/libc/ctype/isxdigit.c2
-rw-r--r--lib/libc/ctype/tolower.c7
-rw-r--r--lib/libc/ctype/toupper.c5
-rw-r--r--lib/libc/devctl/posix_devctl.c10
-rw-r--r--lib/libc/dirent/closedir.c18
-rw-r--r--lib/libc/dirent/dirfd.c5
-rw-r--r--lib/libc/dirent/fdopendir.c16
-rw-r--r--lib/libc/dirent/opendir.c8
-rw-r--r--lib/libc/dirent/readdir.c4
-rw-r--r--lib/libc/dirent/readdir_r.c20
-rw-r--r--lib/libc/endian/be16toh.c3
-rw-r--r--lib/libc/endian/be32toh.c3
-rw-r--r--lib/libc/endian/be64toh.c3
-rw-r--r--lib/libc/endian/htobe16.c3
-rw-r--r--lib/libc/endian/htobe32.c3
-rw-r--r--lib/libc/endian/htobe64.c3
-rw-r--r--lib/libc/endian/htole16.c3
-rw-r--r--lib/libc/endian/htole32.c3
-rw-r--r--lib/libc/endian/htole64.c3
-rw-r--r--lib/libc/endian/le16toh.c3
-rw-r--r--lib/libc/endian/le32toh.c3
-rw-r--r--lib/libc/endian/le64toh.c3
-rw-r--r--lib/libc/fcntl/creat.c7
-rw-r--r--lib/libc/fcntl/fcntl.c9
-rw-r--r--lib/libc/fcntl/open.c9
-rw-r--r--lib/libc/fcntl/openat.c9
-rw-r--r--lib/libc/fcntl/posix_fadvise.c7
-rw-r--r--lib/libc/fcntl/posix_fallocate.c7
-rw-r--r--lib/libc/grp/getgrgid.c7
-rw-r--r--lib/libc/grp/getgrgid_r.c13
-rw-r--r--lib/libc/include/__stdio.h (renamed from lib/libc/include/io.h)0
-rw-r--r--lib/libc/include/libc.h5
-rw-r--r--lib/libc/inttypes/imaxabs.c2
-rw-r--r--lib/libc/inttypes/imaxdiv.c4
-rw-r--r--lib/libc/inttypes/strtoimax.c8
-rw-r--r--lib/libc/inttypes/strtoumax.c4
-rw-r--r--lib/libc/libc.abin1354228 -> 1354072 bytes
-rw-r--r--lib/libc/libgen/basename.c8
-rw-r--r--lib/libc/libgen/dirname.c8
-rw-r--r--lib/libc/mman/mlock.c6
-rw-r--r--lib/libc/mman/mlockall.c5
-rw-r--r--lib/libc/mman/mmap.c7
-rw-r--r--lib/libc/mman/mprotect.c6
-rw-r--r--lib/libc/mman/msync.c6
-rw-r--r--lib/libc/mman/munlock.c6
-rw-r--r--lib/libc/mman/munlockall.c5
-rw-r--r--lib/libc/mman/munmap.c7
-rw-r--r--lib/libc/mman/posix_madvise.c6
-rw-r--r--lib/libc/msg/msgctl.c7
-rw-r--r--lib/libc/poll/poll.c6
-rw-r--r--lib/libc/poll/ppoll.c9
-rw-r--r--lib/libc/pwd/getgrgid.c7
-rw-r--r--lib/libc/pwd/getgrgid_r.c13
-rw-r--r--lib/libc/select/pselect.c8
-rw-r--r--lib/libc/select/select.c6
-rw-r--r--lib/libc/sem/semctl.c12
-rw-r--r--lib/libc/sem/semget.c7
-rw-r--r--lib/libc/sem/semop.c6
-rw-r--r--lib/libc/setjmp/siglongjmp.c2
-rw-r--r--lib/libc/signal/kill.c7
-rw-r--r--lib/libc/signal/killpg.c6
-rw-r--r--lib/libc/signal/psiginfo.c2
-rw-r--r--lib/libc/signal/psignal.c6
-rw-r--r--lib/libc/signal/pthread_kill.c9
-rw-r--r--lib/libc/signal/pthread_sigmask.c14
-rw-r--r--lib/libc/signal/raise.c4
-rw-r--r--lib/libc/signal/sig2str.c8
-rw-r--r--lib/libc/signal/sigaction.c6
-rw-r--r--lib/libc/signal/sigaddset.c2
-rw-r--r--lib/libc/signal/sigemptyset.c2
-rw-r--r--lib/libc/signal/sigismember.c2
-rw-r--r--lib/libc/signal/sigpending.c6
-rw-r--r--lib/libc/signal/sigprocmask.c6
-rw-r--r--lib/libc/signal/sigqueue.c4
-rw-r--r--lib/libc/signal/sigsuspend.c6
-rw-r--r--lib/libc/signal/sigtimedwait.c8
-rw-r--r--lib/libc/signal/sigwait.c2
-rw-r--r--lib/libc/signal/sigwaitinfo.c2
-rw-r--r--lib/libc/signal/str2sig.c12
-rw-r--r--lib/libc/socket/accept.c6
-rw-r--r--lib/libc/socket/accept4.c6
-rw-r--r--lib/libc/socket/bind.c6
-rw-r--r--lib/libc/socket/connect.c6
-rw-r--r--lib/libc/socket/getpeername.c6
-rw-r--r--lib/libc/socket/getsockname.c6
-rw-r--r--lib/libc/socket/getsockopt.c6
-rw-r--r--lib/libc/socket/listen.c6
-rw-r--r--lib/libc/socket/recv.c7
-rw-r--r--lib/libc/socket/recvfrom.c7
-rw-r--r--lib/libc/socket/recvmsg.c7
-rw-r--r--lib/libc/socket/send.c7
-rw-r--r--lib/libc/socket/sendmsg.c7
-rw-r--r--lib/libc/socket/sendto.c7
-rw-r--r--lib/libc/socket/setsockopt.c6
-rw-r--r--lib/libc/socket/shutdown.c4
-rw-r--r--lib/libc/socket/sockatmark.c6
-rw-r--r--lib/libc/socket/socket.c4
-rw-r--r--lib/libc/socket/socketpair.c4
-rw-r--r--lib/libc/stat/chmod.c7
-rw-r--r--lib/libc/stat/fchmod.c7
-rw-r--r--lib/libc/stat/fchmodat.c7
-rw-r--r--lib/libc/stat/fstat.c4
-rw-r--r--lib/libc/stat/fstatat.c12
-rw-r--r--lib/libc/stat/futimens.c4
-rw-r--r--lib/libc/stat/lstat.c4
-rw-r--r--lib/libc/stat/mkdir.c8
-rw-r--r--lib/libc/stat/mkdirat.c8
-rw-r--r--lib/libc/stat/mkfifo.c3
-rw-r--r--lib/libc/stat/mkfifoat.c3
-rw-r--r--lib/libc/stat/mknod.c9
-rw-r--r--lib/libc/stat/mknodat.c7
-rw-r--r--lib/libc/stat/stat.c4
-rw-r--r--lib/libc/stat/umask.c7
-rw-r--r--lib/libc/stat/utimensat.c6
-rw-r--r--lib/libc/statvfs/fstatvfs.c8
-rw-r--r--lib/libc/statvfs/statvfs.c8
-rw-r--r--lib/libc/stdio/asprintf.c4
-rw-r--r--lib/libc/stdio/clearerr.c9
-rw-r--r--lib/libc/stdio/dprintf.c4
-rw-r--r--lib/libc/stdio/dtoa.c36
-rw-r--r--lib/libc/stdio/fclose.c8
-rw-r--r--lib/libc/stdio/fdopen.c34
-rw-r--r--lib/libc/stdio/feof.c10
-rw-r--r--lib/libc/stdio/ferror.c11
-rw-r--r--lib/libc/stdio/fflush.c64
-rw-r--r--lib/libc/stdio/fgetc.c2
-rw-r--r--lib/libc/stdio/fgets.c6
-rw-r--r--lib/libc/stdio/fileno.c14
-rw-r--r--lib/libc/stdio/fmemopen.c39
-rw-r--r--lib/libc/stdio/fopen.c43
-rw-r--r--lib/libc/stdio/fprintf.c4
-rw-r--r--lib/libc/stdio/fputc.c21
-rw-r--r--lib/libc/stdio/fputs.c4
-rw-r--r--lib/libc/stdio/fread.c37
-rw-r--r--lib/libc/stdio/fseek.c29
-rw-r--r--lib/libc/stdio/ftell.c7
-rw-r--r--lib/libc/stdio/ftello.c6
-rw-r--r--lib/libc/stdio/fwrite.c100
-rw-r--r--lib/libc/stdio/getc.c4
-rw-r--r--lib/libc/stdio/getchar.c4
-rw-r--r--lib/libc/stdio/pclose.c8
-rw-r--r--lib/libc/stdio/perror.c10
-rw-r--r--lib/libc/stdio/popen.c14
-rw-r--r--lib/libc/stdio/printf.c4
-rw-r--r--lib/libc/stdio/putc.c4
-rw-r--r--lib/libc/stdio/putchar.c4
-rw-r--r--lib/libc/stdio/puts.c4
-rw-r--r--lib/libc/stdio/remove.c9
-rw-r--r--lib/libc/stdio/rename.c4
-rw-r--r--lib/libc/stdio/renameat.c4
-rw-r--r--lib/libc/stdio/rewind.c2
-rw-r--r--lib/libc/stdio/setbuf.c3
-rw-r--r--lib/libc/stdio/setvbuf.c16
-rw-r--r--lib/libc/stdio/snprintf.c4
-rw-r--r--lib/libc/stdio/sprintf.c5
-rw-r--r--lib/libc/stdio/stderr.c8
-rw-r--r--lib/libc/stdio/stdin.c9
-rw-r--r--lib/libc/stdio/stdout.c13
-rw-r--r--lib/libc/stdio/vasprintf.c6
-rw-r--r--lib/libc/stdio/vdprintf.c16
-rw-r--r--lib/libc/stdio/vfprintf.c20
-rw-r--r--lib/libc/stdio/vprintf.c2
-rw-r--r--lib/libc/stdio/vsnprintf.c53
-rw-r--r--lib/libc/stdio/vsprintf.c3
-rw-r--r--lib/libc/stdlib/exit.c22
-rw-r--r--lib/libc/string/memccpy.c2
-rw-r--r--lib/libc/string/memchr.c2
-rw-r--r--lib/libc/string/memcmp.c2
-rw-r--r--lib/libc/string/memcpy.c6
-rw-r--r--lib/libc/string/memmem.c2
-rw-r--r--lib/libc/string/memmove.c4
-rw-r--r--lib/libc/string/memset.c2
-rw-r--r--lib/libc/string/stpcpy.c2
-rw-r--r--lib/libc/string/stpncpy.c2
-rw-r--r--lib/libc/string/strchr.c2
-rw-r--r--lib/libc/string/strcmp.c2
-rw-r--r--lib/libc/string/strcoll.c8
-rw-r--r--lib/libc/string/strcspn.c2
-rw-r--r--lib/libc/string/strdup.c4
-rw-r--r--lib/libc/string/strerror.c11
-rw-r--r--lib/libc/string/strlcat.c2
-rw-r--r--lib/libc/string/strlcpy.c2
-rw-r--r--lib/libc/string/strlen.c2
-rw-r--r--lib/libc/string/strncat.c2
-rw-r--r--lib/libc/string/strncmp.c2
-rw-r--r--lib/libc/string/strncpy.c2
-rw-r--r--lib/libc/string/strndup.c4
-rw-r--r--lib/libc/string/strnlen.c2
-rw-r--r--lib/libc/string/strpbrk.c2
-rw-r--r--lib/libc/string/strrchr.c2
-rw-r--r--lib/libc/string/strspn.c3
-rw-r--r--lib/libc/string/strstr.c2
-rw-r--r--lib/libc/string/strtok.c3
-rw-r--r--lib/libc/string/strtok_r.c2
-rw-r--r--lib/libc/string/strxfrm.c8
-rw-r--r--lib/libc/strings/strcasecmp.c7
-rw-r--r--lib/libc/strings/strncasecmp.c9
-rw-r--r--lib/libc/sys/ioctl.c6
-rw-r--r--lib/libc/sys/mount.c6
-rw-r--r--lib/libc/sys/umount.c4
-rw-r--r--lib/libc/sys/umount2.c4
-rw-r--r--lib/libc/syslog/closelog.c2
-rw-r--r--lib/libc/syslog/openlog.c2
-rw-r--r--lib/libc/syslog/setlogmask.c2
-rw-r--r--lib/libc/uio/readv.c16
-rw-r--r--lib/libc/uio/writev.c13
-rw-r--r--lib/libc/unistd/_Fork.c8
-rw-r--r--lib/libc/unistd/_exit.c4
-rw-r--r--lib/libc/unistd/access.c4
-rw-r--r--lib/libc/unistd/alarm.c4
-rw-r--r--lib/libc/unistd/chdir.c4
-rw-r--r--lib/libc/unistd/chown.c6
-rw-r--r--lib/libc/unistd/close.c4
-rw-r--r--lib/libc/unistd/dup.c4
-rw-r--r--lib/libc/unistd/dup2.c4
-rw-r--r--lib/libc/unistd/dup3.c4
-rw-r--r--lib/libc/unistd/execl.c6
-rw-r--r--lib/libc/unistd/execlp.c5
-rw-r--r--lib/libc/unistd/execv.c6
-rw-r--r--lib/libc/unistd/execve.c4
-rw-r--r--lib/libc/unistd/execvp.c12
-rw-r--r--lib/libc/unistd/faccessat.c4
-rw-r--r--lib/libc/unistd/fchdir.c4
-rw-r--r--lib/libc/unistd/fchown.c6
-rw-r--r--lib/libc/unistd/fchownat.c6
-rw-r--r--lib/libc/unistd/fdatasync.c4
-rw-r--r--lib/libc/unistd/fork.c2
-rw-r--r--lib/libc/unistd/fsync.c4
-rw-r--r--lib/libc/unistd/ftruncate.c6
-rw-r--r--lib/libc/unistd/getcwd.c6
-rw-r--r--lib/libc/unistd/getegid.c6
-rw-r--r--lib/libc/unistd/getentropy.c3
-rw-r--r--lib/libc/unistd/geteuid.c6
-rw-r--r--lib/libc/unistd/getgid.c6
-rw-r--r--lib/libc/unistd/getgroups.c6
-rw-r--r--lib/libc/unistd/gethostid.c1
-rw-r--r--lib/libc/unistd/gethostname.c3
-rw-r--r--lib/libc/unistd/getlogin.c1
-rw-r--r--lib/libc/unistd/getlogin_r.c3
-rw-r--r--lib/libc/unistd/getopt.c7
-rw-r--r--lib/libc/unistd/getpgid.c6
-rw-r--r--lib/libc/unistd/getpid.c6
-rw-r--r--lib/libc/unistd/getppid.c6
-rw-r--r--lib/libc/unistd/getresgid.c6
-rw-r--r--lib/libc/unistd/getresuid.c6
-rw-r--r--lib/libc/unistd/getsid.c6
-rw-r--r--lib/libc/unistd/getuid.c6
-rw-r--r--lib/libc/unistd/isatty.c10
-rw-r--r--lib/libc/unistd/lchown.c6
-rw-r--r--lib/libc/unistd/link.c6
-rw-r--r--lib/libc/unistd/linkat.c6
-rw-r--r--lib/libc/unistd/lockf.c3
-rw-r--r--lib/libc/unistd/lseek.c6
-rw-r--r--lib/libc/unistd/nice.c3
-rw-r--r--lib/libc/unistd/pause.c4
-rw-r--r--lib/libc/unistd/pipe.c4
-rw-r--r--lib/libc/unistd/pipe2.c4
-rw-r--r--lib/libc/unistd/posix_close.c6
-rw-r--r--lib/libc/unistd/pread.c4
-rw-r--r--lib/libc/unistd/pwrite.c4
-rw-r--r--lib/libc/unistd/read.c6
-rw-r--r--lib/libc/unistd/readlink.c6
-rw-r--r--lib/libc/unistd/readlinkat.c6
-rw-r--r--lib/libc/unistd/rmdir.c4
-rw-r--r--lib/libc/unistd/setegid.c6
-rw-r--r--lib/libc/unistd/seteuid.c6
-rw-r--r--lib/libc/unistd/setgid.c6
-rw-r--r--lib/libc/unistd/setpgid.c6
-rw-r--r--lib/libc/unistd/setregid.c6
-rw-r--r--lib/libc/unistd/setresgid.c6
-rw-r--r--lib/libc/unistd/setresuid.c6
-rw-r--r--lib/libc/unistd/setreuid.c6
-rw-r--r--lib/libc/unistd/setsid.c6
-rw-r--r--lib/libc/unistd/setuid.c6
-rw-r--r--lib/libc/unistd/sleep.c4
-rw-r--r--lib/libc/unistd/swab.c2
-rw-r--r--lib/libc/unistd/symlink.c4
-rw-r--r--lib/libc/unistd/symlinkat.c4
-rw-r--r--lib/libc/unistd/sync.c4
-rw-r--r--lib/libc/unistd/truncate.c6
-rw-r--r--lib/libc/unistd/unlink.c4
-rw-r--r--lib/libc/unistd/unlinkat.c4
-rw-r--r--lib/libc/unistd/write.c6
-rw-r--r--lib/libc/utsname/uname.c6
-rw-r--r--lib/libc/wait/wait.c7
-rw-r--r--lib/libc/wait/waitid.c8
-rw-r--r--lib/libc/wait/waitpid.c7
312 files changed, 1264 insertions, 886 deletions
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
index 49fadae3..55b3b5a6 100644
--- a/lib/libc/libc.a
+++ b/lib/libc/libc.a
Binary files differ
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)
{