clean up stdio_impl.h
this header evolved to facilitate the extremely lazy practice of
omitting explicit includes of the necessary headers in individual
stdio source files; not only was this sloppy, but it also increased
build time.
now, stdio_impl.h is only including the headers it needs for its own
use; any further headers needed by source files are included directly
where needed.
diff --git a/src/internal/floatscan.c b/src/internal/floatscan.c
index 0825121..f6e331d 100644
--- a/src/internal/floatscan.c
+++ b/src/internal/floatscan.c
@@ -4,6 +4,7 @@
#include <float.h>
#include <limits.h>
#include <errno.h>
+#include <ctype.h>
#include "shgetc.h"
#include "floatscan.h"
diff --git a/src/internal/intscan.c b/src/internal/intscan.c
index 178cdf0..69350ef 100644
--- a/src/internal/intscan.c
+++ b/src/internal/intscan.c
@@ -1,5 +1,6 @@
#include <limits.h>
#include <errno.h>
+#include <ctype.h>
#include "shgetc.h"
/* Lookup table for digit values. -1==255>=36 -> invalid */
diff --git a/src/internal/stdio_impl.h b/src/internal/stdio_impl.h
index e9045f2..c9d20fa 100644
--- a/src/internal/stdio_impl.h
+++ b/src/internal/stdio_impl.h
@@ -2,23 +2,6 @@
#define _STDIO_IMPL_H
#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <stdarg.h>
-#include <string.h>
-#include <inttypes.h>
-#include <wchar.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <errno.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-#include <ctype.h>
-#include <sys/wait.h>
-#include <math.h>
-#include <float.h>
-#include <sys/uio.h>
#include "syscall.h"
#include "libc.h"
diff --git a/src/stdio/__fdopen.c b/src/stdio/__fdopen.c
index df6ed71..59690f6 100644
--- a/src/stdio/__fdopen.c
+++ b/src/stdio/__fdopen.c
@@ -1,4 +1,10 @@
#include "stdio_impl.h"
+#include <stdlib.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
FILE *__fdopen(int fd, const char *mode)
{
diff --git a/src/stdio/__fopen_rb_ca.c b/src/stdio/__fopen_rb_ca.c
index a1b1b3b..9202c8c 100644
--- a/src/stdio/__fopen_rb_ca.c
+++ b/src/stdio/__fopen_rb_ca.c
@@ -1,4 +1,6 @@
#include "stdio_impl.h"
+#include <fcntl.h>
+#include <string.h>
FILE *__fopen_rb_ca(const char *filename, FILE *f, unsigned char *buf, size_t len)
{
diff --git a/src/stdio/__stdio_read.c b/src/stdio/__stdio_read.c
index c99ca9a..05e56f9 100644
--- a/src/stdio/__stdio_read.c
+++ b/src/stdio/__stdio_read.c
@@ -1,4 +1,5 @@
#include "stdio_impl.h"
+#include <sys/uio.h>
#include <pthread.h>
static void cleanup(void *p)
diff --git a/src/stdio/__stdio_write.c b/src/stdio/__stdio_write.c
index cef7bbd..e52e91a 100644
--- a/src/stdio/__stdio_write.c
+++ b/src/stdio/__stdio_write.c
@@ -1,4 +1,5 @@
#include "stdio_impl.h"
+#include <sys/uio.h>
#include <pthread.h>
static void cleanup(void *p)
diff --git a/src/stdio/__stdout_write.c b/src/stdio/__stdout_write.c
index 0cf7123..200fe2c 100644
--- a/src/stdio/__stdout_write.c
+++ b/src/stdio/__stdout_write.c
@@ -1,4 +1,6 @@
#include "stdio_impl.h"
+#include <termios.h>
+#include <sys/ioctl.h>
size_t __stdout_write(FILE *f, const unsigned char *buf, size_t len)
{
diff --git a/src/stdio/__string_read.c b/src/stdio/__string_read.c
index de002fc..7b50a7e 100644
--- a/src/stdio/__string_read.c
+++ b/src/stdio/__string_read.c
@@ -1,4 +1,5 @@
#include "stdio_impl.h"
+#include <string.h>
size_t __string_read(FILE *f, unsigned char *buf, size_t len)
{
diff --git a/src/stdio/fgetln.c b/src/stdio/fgetln.c
index 06b8883..a2e4bd3 100644
--- a/src/stdio/fgetln.c
+++ b/src/stdio/fgetln.c
@@ -1,4 +1,5 @@
#include "stdio_impl.h"
+#include <string.h>
char *fgetln(FILE *f, size_t *plen)
{
diff --git a/src/stdio/fgets.c b/src/stdio/fgets.c
index ee0ac30..b01a418 100644
--- a/src/stdio/fgets.c
+++ b/src/stdio/fgets.c
@@ -1,4 +1,5 @@
#include "stdio_impl.h"
+#include <string.h>
#define MIN(a,b) ((a)<(b) ? (a) : (b))
diff --git a/src/stdio/fgetwc.c b/src/stdio/fgetwc.c
index 6f9f9ec..8626d54 100644
--- a/src/stdio/fgetwc.c
+++ b/src/stdio/fgetwc.c
@@ -1,4 +1,6 @@
#include "stdio_impl.h"
+#include <wchar.h>
+#include <errno.h>
wint_t __fgetwc_unlocked(FILE *f)
{
diff --git a/src/stdio/fgetws.c b/src/stdio/fgetws.c
index fab9bd0..195cb43 100644
--- a/src/stdio/fgetws.c
+++ b/src/stdio/fgetws.c
@@ -1,4 +1,5 @@
#include "stdio_impl.h"
+#include <wchar.h>
wint_t __fgetwc_unlocked(FILE *);
diff --git a/src/stdio/fmemopen.c b/src/stdio/fmemopen.c
index 770fd99..91d52bc 100644
--- a/src/stdio/fmemopen.c
+++ b/src/stdio/fmemopen.c
@@ -1,4 +1,7 @@
#include "stdio_impl.h"
+#include <errno.h>
+#include <string.h>
+#include <inttypes.h>
struct cookie {
size_t pos, len, size;
diff --git a/src/stdio/fopen.c b/src/stdio/fopen.c
index c741aed..da17ce8 100644
--- a/src/stdio/fopen.c
+++ b/src/stdio/fopen.c
@@ -1,4 +1,7 @@
#include "stdio_impl.h"
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
FILE *fopen(const char *restrict filename, const char *restrict mode)
{
diff --git a/src/stdio/fputs.c b/src/stdio/fputs.c
index b41bc8c..1112b19 100644
--- a/src/stdio/fputs.c
+++ b/src/stdio/fputs.c
@@ -1,4 +1,5 @@
#include "stdio_impl.h"
+#include <string.h>
int fputs(const char *restrict s, FILE *restrict f)
{
diff --git a/src/stdio/fputwc.c b/src/stdio/fputwc.c
index 45ea8c2..7b621dd 100644
--- a/src/stdio/fputwc.c
+++ b/src/stdio/fputwc.c
@@ -1,4 +1,7 @@
#include "stdio_impl.h"
+#include <wchar.h>
+#include <limits.h>
+#include <ctype.h>
wint_t __fputwc_unlocked(wchar_t c, FILE *f)
{
diff --git a/src/stdio/fputws.c b/src/stdio/fputws.c
index 0b593c0..5723cbc 100644
--- a/src/stdio/fputws.c
+++ b/src/stdio/fputws.c
@@ -1,4 +1,5 @@
#include "stdio_impl.h"
+#include <wchar.h>
int fputws(const wchar_t *restrict ws, FILE *restrict f)
{
diff --git a/src/stdio/fread.c b/src/stdio/fread.c
index 3f31af8..c461256 100644
--- a/src/stdio/fread.c
+++ b/src/stdio/fread.c
@@ -1,4 +1,5 @@
#include "stdio_impl.h"
+#include <string.h>
#define MIN(a,b) ((a)<(b) ? (a) : (b))
diff --git a/src/stdio/freopen.c b/src/stdio/freopen.c
index 7ae116d..6c1b575 100644
--- a/src/stdio/freopen.c
+++ b/src/stdio/freopen.c
@@ -1,4 +1,5 @@
#include "stdio_impl.h"
+#include <fcntl.h>
/* The basic idea of this implementation is to open a new FILE,
* hack the necessary parts of the new FILE into the old one, then
diff --git a/src/stdio/ftell.c b/src/stdio/ftell.c
index 3904a1d..82371e3 100644
--- a/src/stdio/ftell.c
+++ b/src/stdio/ftell.c
@@ -1,4 +1,6 @@
#include "stdio_impl.h"
+#include <limits.h>
+#include <errno.h>
off_t __ftello_unlocked(FILE *f)
{
diff --git a/src/stdio/fwrite.c b/src/stdio/fwrite.c
index 8027b30..d5f6542 100644
--- a/src/stdio/fwrite.c
+++ b/src/stdio/fwrite.c
@@ -1,4 +1,5 @@
#include "stdio_impl.h"
+#include <string.h>
size_t __fwritex(const unsigned char *restrict s, size_t l, FILE *restrict f)
{
diff --git a/src/stdio/getdelim.c b/src/stdio/getdelim.c
index 5015c3a..26093a6 100644
--- a/src/stdio/getdelim.c
+++ b/src/stdio/getdelim.c
@@ -1,4 +1,7 @@
#include "stdio_impl.h"
+#include <string.h>
+#include <inttypes.h>
+#include <errno.h>
#define MIN(a,b) ((a)<(b) ? (a) : (b))
diff --git a/src/stdio/gets.c b/src/stdio/gets.c
index 24319eb..6c4645e 100644
--- a/src/stdio/gets.c
+++ b/src/stdio/gets.c
@@ -1,4 +1,6 @@
#include "stdio_impl.h"
+#include <limits.h>
+#include <string.h>
char *gets(char *s)
{
diff --git a/src/stdio/getwc.c b/src/stdio/getwc.c
index a2818bc..a5008f0 100644
--- a/src/stdio/getwc.c
+++ b/src/stdio/getwc.c
@@ -1,4 +1,5 @@
#include "stdio_impl.h"
+#include <wchar.h>
wint_t getwc(FILE *f)
{
diff --git a/src/stdio/getwchar.c b/src/stdio/getwchar.c
index 2295bd4..bd89e0e 100644
--- a/src/stdio/getwchar.c
+++ b/src/stdio/getwchar.c
@@ -1,4 +1,5 @@
#include "stdio_impl.h"
+#include <wchar.h>
wint_t getwchar(void)
{
diff --git a/src/stdio/open_memstream.c b/src/stdio/open_memstream.c
index 687e818..c7330ab 100644
--- a/src/stdio/open_memstream.c
+++ b/src/stdio/open_memstream.c
@@ -1,4 +1,7 @@
#include "stdio_impl.h"
+#include <errno.h>
+#include <limits.h>
+#include <string.h>
struct cookie {
char **bufp;
diff --git a/src/stdio/open_wmemstream.c b/src/stdio/open_wmemstream.c
index a830b14..2fe504c 100644
--- a/src/stdio/open_wmemstream.c
+++ b/src/stdio/open_wmemstream.c
@@ -1,4 +1,8 @@
#include "stdio_impl.h"
+#include <wchar.h>
+#include <errno.h>
+#include <limits.h>
+#include <string.h>
struct cookie {
wchar_t **bufp;
diff --git a/src/stdio/pclose.c b/src/stdio/pclose.c
index 7fb76ed..080a426 100644
--- a/src/stdio/pclose.c
+++ b/src/stdio/pclose.c
@@ -1,5 +1,6 @@
#include "stdio_impl.h"
-#include "syscall.h"
+#include <errno.h>
+#include <unistd.h>
int pclose(FILE *f)
{
diff --git a/src/stdio/putwc.c b/src/stdio/putwc.c
index 80b54a4..4bb7473 100644
--- a/src/stdio/putwc.c
+++ b/src/stdio/putwc.c
@@ -1,4 +1,5 @@
#include "stdio_impl.h"
+#include <wchar.h>
wint_t putwc(wchar_t c, FILE *f)
{
diff --git a/src/stdio/putwchar.c b/src/stdio/putwchar.c
index 3aacc1c..b249c4a 100644
--- a/src/stdio/putwchar.c
+++ b/src/stdio/putwchar.c
@@ -1,4 +1,5 @@
#include "stdio_impl.h"
+#include <wchar.h>
wint_t putwchar(wchar_t c)
{
diff --git a/src/stdio/ungetwc.c b/src/stdio/ungetwc.c
index 5282fee..8cc85a6 100644
--- a/src/stdio/ungetwc.c
+++ b/src/stdio/ungetwc.c
@@ -1,4 +1,8 @@
#include "stdio_impl.h"
+#include <wchar.h>
+#include <limits.h>
+#include <ctype.h>
+#include <string.h>
wint_t ungetwc(wint_t c, FILE *f)
{
diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
index 4a2752b..1e7e6a4 100644
--- a/src/stdio/vfprintf.c
+++ b/src/stdio/vfprintf.c
@@ -1,4 +1,13 @@
#include "stdio_impl.h"
+#include <errno.h>
+#include <ctype.h>
+#include <limits.h>
+#include <string.h>
+#include <stdarg.h>
+#include <wchar.h>
+#include <inttypes.h>
+#include <math.h>
+#include <float.h>
/* Some useful macros */
diff --git a/src/stdio/vfscanf.c b/src/stdio/vfscanf.c
index 54d0849..fe071e9 100644
--- a/src/stdio/vfscanf.c
+++ b/src/stdio/vfscanf.c
@@ -1,4 +1,3 @@
-#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
@@ -9,6 +8,7 @@
#include <errno.h>
#include <math.h>
#include <float.h>
+#include <inttypes.h>
#include "stdio_impl.h"
#include "shgetc.h"
diff --git a/src/stdio/vfwprintf.c b/src/stdio/vfwprintf.c
index a42ba19..eb07931 100644
--- a/src/stdio/vfwprintf.c
+++ b/src/stdio/vfwprintf.c
@@ -1,4 +1,11 @@
#include "stdio_impl.h"
+#include <errno.h>
+#include <ctype.h>
+#include <limits.h>
+#include <string.h>
+#include <stdarg.h>
+#include <wchar.h>
+#include <inttypes.h>
/* Convenient bit representation for modifier flags, which all fall
* within 31 codepoints of the space character. */
diff --git a/src/stdio/vsnprintf.c b/src/stdio/vsnprintf.c
index 6f19b02..be2c44e 100644
--- a/src/stdio/vsnprintf.c
+++ b/src/stdio/vsnprintf.c
@@ -1,4 +1,8 @@
#include "stdio_impl.h"
+#include <limits.h>
+#include <string.h>
+#include <errno.h>
+#include <stdint.h>
static size_t sn_write(FILE *f, const unsigned char *s, size_t l)
{
diff --git a/src/stdio/vswprintf.c b/src/stdio/vswprintf.c
index f3d4fec..7d237ba 100644
--- a/src/stdio/vswprintf.c
+++ b/src/stdio/vswprintf.c
@@ -1,4 +1,9 @@
#include "stdio_impl.h"
+#include <limits.h>
+#include <string.h>
+#include <errno.h>
+#include <stdint.h>
+#include <wchar.h>
struct cookie {
wchar_t *ws;
diff --git a/src/stdio/vswscanf.c b/src/stdio/vswscanf.c
index a205200..7a2f7c7 100644
--- a/src/stdio/vswscanf.c
+++ b/src/stdio/vswscanf.c
@@ -1,4 +1,5 @@
#include "stdio_impl.h"
+#include <wchar.h>
static size_t wstring_read(FILE *f, unsigned char *buf, size_t len)
{
diff --git a/src/stdlib/strtol.c b/src/stdlib/strtol.c
index 23a2f3b..7ee8879 100644
--- a/src/stdlib/strtol.c
+++ b/src/stdlib/strtol.c
@@ -1,6 +1,9 @@
#include "stdio_impl.h"
#include "intscan.h"
#include "shgetc.h"
+#include <inttypes.h>
+#include <limits.h>
+#include <ctype.h>
static unsigned long long strtox(const char *s, char **p, int base, unsigned long long lim)
{
diff --git a/src/stdlib/wcstod.c b/src/stdlib/wcstod.c
index 03670b0..83f308d 100644
--- a/src/stdlib/wcstod.c
+++ b/src/stdlib/wcstod.c
@@ -1,6 +1,7 @@
#include "shgetc.h"
#include "floatscan.h"
#include "stdio_impl.h"
+#include <wctype.h>
/* This read function heavily cheats. It knows:
* (1) len will always be 1
diff --git a/src/stdlib/wcstol.c b/src/stdlib/wcstol.c
index 3d7c97d..4443f57 100644
--- a/src/stdlib/wcstol.c
+++ b/src/stdlib/wcstol.c
@@ -1,6 +1,10 @@
#include "stdio_impl.h"
#include "intscan.h"
#include "shgetc.h"
+#include <inttypes.h>
+#include <limits.h>
+#include <wctype.h>
+#include <wchar.h>
/* This read function heavily cheats. It knows:
* (1) len will always be 1