Browse Source

overhaul internally-public declarations using wrapper headers

commits leading up to this one have moved the vast majority of
libc-internal interface declarations to appropriate internal headers,
allowing them to be type-checked and setting the stage to limit their
visibility. the ones that have not yet been moved are mostly
namespace-protected aliases for standard/public interfaces, which
exist to facilitate implementing plain C functions in terms of POSIX
functionality, or C or POSIX functionality in terms of extensions that
are not standardized. some don't quite fit this description, but are
"internally public" interfacs between subsystems of libc.

rather than create a number of newly-named headers to declare these
functions, and having to add explicit include directives for them to
every source file where they're needed, I have introduced a method of
wrapping the corresponding public headers.

parallel to the public headers in $(srcdir)/include, we now have
wrappers in $(srcdir)/src/include that come earlier in the include
path order. they include the public header they're wrapping, then add
declarations for namespace-protected versions of the same interfaces
and any "internally public" interfaces for the subsystem they
correspond to.

along these lines, the wrapper for features.h is now responsible for
the definition of the hidden, weak, and weak_alias macros. this means
source files will no longer need to include any special headers to
access these features.

over time, it is my expectation that the scope of what is "internally
public" will expand, reducing the number of source files which need to
include *_impl.h and related headers down to those which are actually
implementing the corresponding subsystems, not just using them.
Rich Felker 5 years ago
parent
commit
13d1afa46f
92 changed files with 200 additions and 192 deletions
  1. 1 1
      Makefile
  2. 0 2
      ldso/dynlink.c
  3. 0 1
      src/conf/sysconf.c
  4. 0 2
      src/crypt/crypt.c
  5. 0 8
      src/crypt/crypt_r.c
  6. 1 2
      src/env/__libc_start_main.c
  7. 1 0
      src/env/clearenv.c
  8. 1 2
      src/env/getenv.c
  9. 1 2
      src/env/putenv.c
  10. 0 3
      src/env/setenv.c
  11. 1 2
      src/env/unsetenv.c
  12. 8 0
      src/include/arpa/inet.h
  13. 14 0
      src/include/crypt.h
  14. 11 0
      src/include/features.h
  15. 8 0
      src/include/langinfo.h
  16. 22 0
      src/include/pthread.h
  17. 12 0
      src/include/resolv.h
  18. 14 0
      src/include/signal.h
  19. 11 0
      src/include/stdlib.h
  20. 11 0
      src/include/string.h
  21. 20 0
      src/include/sys/mman.h
  22. 8 0
      src/include/sys/sysinfo.h
  23. 8 0
      src/include/sys/time.h
  24. 14 0
      src/include/time.h
  25. 12 0
      src/include/unistd.h
  26. 4 9
      src/internal/libc.h
  27. 1 5
      src/internal/malloc_impl.h
  28. 1 8
      src/internal/pthread_impl.h
  29. 0 2
      src/linux/utimes.c
  30. 1 3
      src/locale/dcngettext.c
  31. 1 4
      src/locale/locale_map.c
  32. 0 2
      src/locale/setlocale.c
  33. 0 2
      src/misc/ptsname.c
  34. 0 2
      src/mman/shm_open.c
  35. 1 4
      src/network/getnameinfo.c
  36. 0 2
      src/network/inet_addr.c
  37. 0 2
      src/network/lookup_ipliteral.c
  38. 1 3
      src/network/lookup_name.c
  39. 0 3
      src/network/res_query.c
  40. 0 2
      src/network/res_send.c
  41. 0 2
      src/process/posix_spawn.c
  42. 0 2
      src/process/posix_spawnp.c
  43. 0 2
      src/signal/signal.c
  44. 1 2
      src/stdio/freopen.c
  45. 1 2
      src/stdio/tempnam.c
  46. 1 2
      src/stdio/tmpfile.c
  47. 1 2
      src/stdio/tmpnam.c
  48. 0 2
      src/string/strchr.c
  49. 0 2
      src/string/strcpy.c
  50. 0 2
      src/string/strcspn.c
  51. 0 2
      src/string/strncpy.c
  52. 0 2
      src/string/strrchr.c
  53. 0 2
      src/temp/__randname.c
  54. 0 2
      src/temp/mkdtemp.c
  55. 0 2
      src/temp/mkostemp.c
  56. 0 2
      src/temp/mkostemps.c
  57. 0 2
      src/temp/mkstemp.c
  58. 0 2
      src/temp/mkstemps.c
  59. 0 2
      src/temp/mktemp.c
  60. 0 3
      src/thread/__timedwait.c
  61. 1 2
      src/thread/call_once.c
  62. 0 2
      src/thread/cnd_broadcast.c
  63. 0 2
      src/thread/cnd_signal.c
  64. 0 2
      src/thread/cnd_timedwait.c
  65. 0 2
      src/thread/mtx_timedlock.c
  66. 0 2
      src/thread/mtx_trylock.c
  67. 0 2
      src/thread/mtx_unlock.c
  68. 0 2
      src/thread/pthread_cond_broadcast.c
  69. 0 2
      src/thread/pthread_cond_signal.c
  70. 0 5
      src/thread/pthread_cond_timedwait.c
  71. 0 4
      src/thread/pthread_create.c
  72. 0 2
      src/thread/pthread_detach.c
  73. 0 4
      src/thread/pthread_join.c
  74. 0 2
      src/thread/pthread_mutex_lock.c
  75. 0 2
      src/thread/pthread_mutex_timedlock.c
  76. 0 2
      src/thread/sem_open.c
  77. 0 2
      src/thread/thrd_create.c
  78. 2 3
      src/thread/thrd_exit.c
  79. 1 2
      src/thread/thrd_join.c
  80. 1 2
      src/thread/tss_create.c
  81. 1 2
      src/thread/tss_delete.c
  82. 0 2
      src/time/__map_file.c
  83. 1 2
      src/time/__tz.c
  84. 0 2
      src/time/asctime.c
  85. 0 2
      src/time/asctime_r.c
  86. 0 2
      src/time/clock.c
  87. 0 2
      src/time/gmtime.c
  88. 0 2
      src/time/localtime.c
  89. 0 4
      src/time/strftime.c
  90. 0 2
      src/time/time.c
  91. 0 1
      src/time/time_impl.h
  92. 0 2
      src/time/timespec_get.c

+ 1 - 1
Makefile

@@ -46,7 +46,7 @@ CFLAGS_AUTO = -Os -pipe
 CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc 
 
 CFLAGS_ALL = $(CFLAGS_C99FSE)
-CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I$(srcdir)/arch/$(ARCH) -I$(srcdir)/arch/generic -Iobj/src/internal -I$(srcdir)/src/internal -Iobj/include -I$(srcdir)/include
+CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I$(srcdir)/arch/$(ARCH) -I$(srcdir)/arch/generic -Iobj/src/internal -I$(srcdir)/src/include -I$(srcdir)/src/internal -Iobj/include -I$(srcdir)/include
 CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS_AUTO) $(CFLAGS)
 
 LDFLAGS_ALL = $(LDFLAGS_AUTO) $(LDFLAGS)

+ 0 - 2
ldso/dynlink.c

@@ -96,8 +96,6 @@ struct symdef {
 	struct dso *dso;
 };
 
-void __init_libc(char **, char *);
-
 static struct builtin_tls {
 	char c;
 	struct pthread pt;

+ 0 - 1
src/conf/sysconf.c

@@ -204,7 +204,6 @@ long sysconf(int name)
 	case JT_PHYS_PAGES & 255:
 	case JT_AVPHYS_PAGES & 255: ;
 		unsigned long long mem;
-		int __lsysinfo(struct sysinfo *);
 		struct sysinfo si;
 		__lsysinfo(&si);
 		if (!si.mem_unit) si.mem_unit = 1;

+ 0 - 2
src/crypt/crypt.c

@@ -1,8 +1,6 @@
 #include <unistd.h>
 #include <crypt.h>
 
-char *__crypt_r(const char *, const char *, struct crypt_data *);
-
 char *crypt(const char *key, const char *salt)
 {
 	/* This buffer is sufficiently large for all

+ 0 - 8
src/crypt/crypt_r.c

@@ -1,14 +1,6 @@
 #include <crypt.h>
 #include "libc.h"
 
-struct crypt_data;
-
-char *__crypt_des(const char *, const char *, char *);
-char *__crypt_md5(const char *, const char *, char *);
-char *__crypt_blowfish(const char *, const char *, char *);
-char *__crypt_sha256(const char *, const char *, char *);
-char *__crypt_sha512(const char *, const char *, char *);
-
 char *__crypt_r(const char *key, const char *salt, struct crypt_data *data)
 {
 	/* Per the crypt_r API, the caller has provided a pointer to

+ 1 - 2
src/env/__libc_start_main.c

@@ -2,12 +2,11 @@
 #include <poll.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <unistd.h>
 #include "syscall.h"
 #include "atomic.h"
 #include "libc.h"
 
-void __init_tls(size_t *);
-
 static void dummy(void) {}
 weak_alias(dummy, _init);
 

+ 1 - 0
src/env/clearenv.c

@@ -1,5 +1,6 @@
 #define _GNU_SOURCE
 #include <stdlib.h>
+#include <unistd.h>
 #include "libc.h"
 
 static void dummy(char *old, char *new) {}

+ 1 - 2
src/env/getenv.c

@@ -1,9 +1,8 @@
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include "libc.h"
 
-char *__strchrnul(const char *, int);
-
 char *getenv(const char *name)
 {
 	size_t l = __strchrnul(name, '=') - name;

+ 1 - 2
src/env/putenv.c

@@ -1,9 +1,8 @@
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include "libc.h"
 
-char *__strchrnul(const char *, int);
-
 static void dummy(char *old, char *new) {}
 weak_alias(dummy, __env_rm_add);
 

+ 0 - 3
src/env/setenv.c

@@ -2,9 +2,6 @@
 #include <string.h>
 #include <errno.h>
 
-char *__strchrnul(const char *, int);
-int __putenv(char *, size_t, char *);
-
 void __env_rm_add(char *old, char *new)
 {
 	static char **env_alloced;

+ 1 - 2
src/env/unsetenv.c

@@ -1,10 +1,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <unistd.h>
 #include "libc.h"
 
-char *__strchrnul(const char *, int);
-
 static void dummy(char *old, char *new) {}
 weak_alias(dummy, __env_rm_add);
 

+ 8 - 0
src/include/arpa/inet.h

@@ -0,0 +1,8 @@
+#ifndef ARPA_INET_H
+#define ARPA_INET_H
+
+#include "../../../include/arpa/inet.h"
+
+int __inet_aton(const char *, struct in_addr *);
+
+#endif

+ 14 - 0
src/include/crypt.h

@@ -0,0 +1,14 @@
+#ifndef CRYPT_H
+#define CRYPT_H
+
+#include "../../include/crypt.h"
+
+char *__crypt_r(const char *, const char *, struct crypt_data *);
+
+char *__crypt_des(const char *, const char *, char *);
+char *__crypt_md5(const char *, const char *, char *);
+char *__crypt_blowfish(const char *, const char *, char *);
+char *__crypt_sha256(const char *, const char *, char *);
+char *__crypt_sha512(const char *, const char *, char *);
+
+#endif

+ 11 - 0
src/include/features.h

@@ -0,0 +1,11 @@
+#ifndef FEATURES_H
+#define FEATURES_H
+
+#include "../../include/features.h"
+
+#define weak __attribute__((__weak__))
+#define hidden __attribute__((__visibility__("hidden")))
+#define weak_alias(old, new) \
+	extern __typeof(old) new __attribute__((__weak__, __alias__(#old)))
+
+#endif

+ 8 - 0
src/include/langinfo.h

@@ -0,0 +1,8 @@
+#ifndef LANGINFO_H
+#define LANGINFO_H
+
+#include "../../include/langinfo.h"
+
+char *__nl_langinfo_l(nl_item, locale_t);
+
+#endif

+ 22 - 0
src/include/pthread.h

@@ -0,0 +1,22 @@
+#ifndef PTHREAD_H
+#define PTHREAD_H
+
+#include "../../include/pthread.h"
+
+int __pthread_once(pthread_once_t *, void (*)(void));
+void __pthread_testcancel(void);
+int __pthread_setcancelstate(int, int *);
+int __pthread_create(pthread_t *restrict, const pthread_attr_t *restrict, void *(*)(void *), void *restrict);
+_Noreturn void __pthread_exit(void *);
+int __pthread_join(pthread_t, void **);
+int __pthread_mutex_lock(pthread_mutex_t *);
+int __pthread_mutex_trylock(pthread_mutex_t *);
+int __pthread_mutex_trylock_owner(pthread_mutex_t *);
+int __pthread_mutex_timedlock(pthread_mutex_t *restrict, const struct timespec *restrict);
+int __pthread_mutex_unlock(pthread_mutex_t *);
+int __private_cond_signal(pthread_cond_t *, int);
+int __pthread_cond_timedwait(pthread_cond_t *restrict, pthread_mutex_t *restrict, const struct timespec *restrict);
+int __pthread_key_create(pthread_key_t *, void (*)(void *));
+int __pthread_key_delete(pthread_key_t);
+
+#endif

+ 12 - 0
src/include/resolv.h

@@ -0,0 +1,12 @@
+#ifndef RESOLV_H
+#define RESOLV_H
+
+#include "../../include/resolv.h"
+
+int __dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int);
+
+int __res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int);
+int __res_send(const unsigned char *, int, unsigned char *, int);
+int __res_msend(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int);
+
+#endif

+ 14 - 0
src/include/signal.h

@@ -0,0 +1,14 @@
+#ifndef SIGNAL_H
+#define SIGNAL_H
+
+#include "../../include/signal.h"
+
+int __sigaction(int, const struct sigaction *, struct sigaction *);
+
+void __block_all_sigs(void *);
+void __block_app_sigs(void *);
+void __restore_sigs(void *);
+
+void __get_handler_set(sigset_t *);
+
+#endif

+ 11 - 0
src/include/stdlib.h

@@ -0,0 +1,11 @@
+#ifndef STDLIB_H
+#define STDLIB_H
+
+#include "../../include/stdlib.h"
+
+int __putenv(char *, size_t, char *);
+int __mkostemps(char *, int, int);
+int __ptsname_r(int, char *, size_t);
+char *__randname(char *);
+
+#endif

+ 11 - 0
src/include/string.h

@@ -0,0 +1,11 @@
+#ifndef STRING_H
+#define STRING_H
+
+#include "../../include/string.h"
+
+void *__memrchr(const void *, int, size_t);
+char *__stpcpy(char *, const char *);
+char *__stpncpy(char *, const char *, size_t);
+char *__strchrnul(const char *, int);
+
+#endif

+ 20 - 0
src/include/sys/mman.h

@@ -0,0 +1,20 @@
+#ifndef SYS_MMAN_H
+#define SYS_MMAN_H
+
+#include "../../../include/sys/mman.h"
+
+void __vm_wait(void);
+void __vm_lock(void);
+void __vm_unlock(void);
+
+void *__mmap(void *, size_t, int, int, int, off_t);
+int __munmap(void *, size_t);
+void *__mremap(void *, size_t, size_t, int, ...);
+int __madvise(void *, size_t, int);
+int __mprotect(void *, size_t, int);
+
+const unsigned char *__map_file(const char *, size_t *);
+
+char *__shm_mapname(const char *, char *);
+
+#endif

+ 8 - 0
src/include/sys/sysinfo.h

@@ -0,0 +1,8 @@
+#ifndef SYS_SYSINFO_H
+#define SYS_SYSINFO_H
+
+#include "../../../include/sys/sysinfo.h"
+
+int __lsysinfo(struct sysinfo *);
+
+#endif

+ 8 - 0
src/include/sys/time.h

@@ -0,0 +1,8 @@
+#ifndef SYS_TIME_H
+#define SYS_TIME_H
+
+#include "../../../include/sys/time.h"
+
+int __futimesat(int, const char *, const struct timeval [2]);
+
+#endif

+ 14 - 0
src/include/time.h

@@ -0,0 +1,14 @@
+#ifndef TIME_H
+#define TIME_H
+
+#include "../../include/time.h"
+
+int __clock_gettime(clockid_t, struct timespec *);
+
+char *__asctime_r(const struct tm *, char *);
+struct tm *__gmtime_r(const time_t *restrict, struct tm *restrict);
+struct tm *__localtime_r(const time_t *restrict, struct tm *restrict);
+
+size_t __strftime_l(char *restrict, size_t, const char *restrict, const struct tm *restrict, locale_t);
+
+#endif

+ 12 - 0
src/include/unistd.h

@@ -0,0 +1,12 @@
+#ifndef UNISTD_H
+#define UNISTD_H
+
+#include "../../include/unistd.h"
+
+extern char **__environ;
+
+int __dup3(int, int, int);
+int __mkostemps(char *, int, int);
+int __execvpe(const char *, char *const *, char *const *);
+
+#endif

+ 4 - 9
src/internal/libc.h

@@ -33,12 +33,13 @@ struct __libc {
 #define PAGE_SIZE libc.page_size
 #endif
 
-#define weak __attribute__((__weak__))
-#define hidden __attribute__((__visibility__("hidden")))
-
 extern hidden struct __libc __libc;
 #define libc __libc
 
+void __init_libc(char **, char *);
+void __init_tls(size_t *);
+void __libc_start_init(void);
+
 extern hidden size_t __hwcap;
 extern hidden size_t __sysinfo;
 extern char *__progname, *__progname_full;
@@ -56,12 +57,6 @@ hidden void __unlockfile(FILE *);
 void __synccall(void (*)(void *), void *);
 int __setxid(int, int, int, int);
 
-extern char **__environ;
-
-#undef weak_alias
-#define weak_alias(old, new) \
-	extern __typeof(old) new __attribute__((__weak__, __alias__(#old)))
-
 #undef LFS64_2
 #define LFS64_2(x, y) weak_alias(x, y)
 

+ 1 - 5
src/internal/malloc_impl.h

@@ -2,11 +2,7 @@
 #define MALLOC_IMPL_H
 
 #include "libc.h"
-
-void *__mmap(void *, size_t, int, int, int, off_t);
-int __munmap(void *, size_t);
-void *__mremap(void *, size_t, size_t, int, ...);
-int __madvise(void *, size_t, int);
+#include <sys/mman.h>
 
 void *__expand_heap(size_t *);
 

+ 1 - 8
src/internal/pthread_impl.h

@@ -5,6 +5,7 @@
 #include <signal.h>
 #include <errno.h>
 #include <limits.h>
+#include <sys/mman.h>
 #include "libc.h"
 #include "syscall.h"
 #include "atomic.h"
@@ -146,10 +147,6 @@ hidden int __set_thread_area(void *);
 int __libc_sigaction(int, const struct sigaction *, struct sigaction *);
 void __unmapself(void *, size_t);
 
-void __vm_wait(void);
-void __vm_lock(void);
-void __vm_unlock(void);
-
 int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int);
 int __timedwait_cp(volatile int *, int, clockid_t, const struct timespec *, int);
 void __wait(volatile int *, volatile int *, int, int);
@@ -171,10 +168,6 @@ void __acquire_ptc(void);
 void __release_ptc(void);
 void __inhibit_ptc(void);
 
-void __block_all_sigs(void *);
-void __block_app_sigs(void *);
-void __restore_sigs(void *);
-
 #define DEFAULT_STACK_SIZE 81920
 #define DEFAULT_GUARD_SIZE 4096
 

+ 0 - 2
src/linux/utimes.c

@@ -2,8 +2,6 @@
 #include "fcntl.h"
 #include "syscall.h"
 
-int __futimesat(int, const char *, const struct timeval [2]);
-
 int utimes(const char *path, const struct timeval times[2])
 {
 	return __futimesat(AT_FDCWD, path, times);

+ 1 - 3
src/locale/dcngettext.c

@@ -4,6 +4,7 @@
 #include <errno.h>
 #include <limits.h>
 #include <sys/stat.h>
+#include <sys/mman.h>
 #include <ctype.h>
 #include "locale_impl.h"
 #include "libc.h"
@@ -113,9 +114,6 @@ static char *dummy_gettextdomain()
 
 weak_alias(dummy_gettextdomain, __gettextdomain);
 
-const unsigned char *__map_file(const char *, size_t *);
-int __munmap(void *, size_t);
-
 char *dcngettext(const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n, int category)
 {
 	static struct msgcat *volatile cats;

+ 1 - 4
src/locale/locale_map.c

@@ -1,5 +1,6 @@
 #include <locale.h>
 #include <string.h>
+#include <sys/mman.h>
 #include "locale_impl.h"
 #include "libc.h"
 #include "atomic.h"
@@ -11,10 +12,6 @@ const char *__lctrans_impl(const char *msg, const struct __locale_map *lm)
 	return trans ? trans : msg;
 }
 
-const unsigned char *__map_file(const char *, size_t *);
-int __munmap(void *, size_t);
-char *__strchrnul(const char *, int);
-
 static const char envvars[][12] = {
 	"LC_CTYPE",
 	"LC_NUMERIC",

+ 0 - 2
src/locale/setlocale.c

@@ -17,8 +17,6 @@ static char *setlocale_one_unlocked(int cat, const char *name)
 	return lm ? (char *)lm->name : "C";
 }
 
-char *__strchrnul(const char *, int);
-
 char *setlocale(int cat, const char *name)
 {
 	static volatile int lock[1];

+ 0 - 2
src/misc/ptsname.c

@@ -1,8 +1,6 @@
 #include <stdlib.h>
 #include <errno.h>
 
-int __ptsname_r(int, char *, size_t);
-
 char *ptsname(int fd)
 {
 	static char buf[9 + sizeof(int)*3 + 1];

+ 0 - 2
src/mman/shm_open.c

@@ -6,8 +6,6 @@
 #include <limits.h>
 #include <pthread.h>
 
-char *__strchrnul(const char *, int);
-
 char *__shm_mapname(const char *name, char *buf)
 {
 	char *p;

+ 1 - 4
src/network/getnameinfo.c

@@ -7,13 +7,10 @@
 #include <arpa/inet.h>
 #include <net/if.h>
 #include <ctype.h>
+#include <resolv.h>
 #include "lookup.h"
 #include "stdio_impl.h"
 
-int __dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int);
-int __res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int);
-int __res_send(const unsigned char *, int, unsigned char *, int);
-
 #define PTR_MAX (64 + sizeof ".in-addr.arpa")
 #define RR_PTR 12
 

+ 0 - 2
src/network/inet_addr.c

@@ -2,8 +2,6 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
-int __inet_aton(const char *, struct in_addr *);
-
 in_addr_t inet_addr(const char *p)
 {
 	struct in_addr a;

+ 0 - 2
src/network/lookup_ipliteral.c

@@ -9,8 +9,6 @@
 #include <ctype.h>
 #include "lookup.h"
 
-int __inet_aton(const char *, struct in_addr *);
-
 int __lookup_ipliteral(struct address buf[static 1], const char *name, int family)
 {
 	struct in_addr a4;

+ 1 - 3
src/network/lookup_name.c

@@ -10,6 +10,7 @@
 #include <unistd.h>
 #include <pthread.h>
 #include <errno.h>
+#include <resolv.h>
 #include "lookup.h"
 #include "stdio_impl.h"
 #include "syscall.h"
@@ -98,9 +99,6 @@ struct dpc_ctx {
 	int cnt;
 };
 
-int __dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int);
-int __res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int);
-
 #define RR_A 1
 #define RR_CNAME 5
 #define RR_AAAA 28

+ 0 - 3
src/network/res_query.c

@@ -2,9 +2,6 @@
 #include <netdb.h>
 #include "libc.h"
 
-int __res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int);
-int __res_send(const unsigned char *, int, unsigned char *, int);
-
 int __res_query(const char *name, int class, int type, unsigned char *dest, int len)
 {
 	unsigned char q[280];

+ 0 - 2
src/network/res_send.c

@@ -1,8 +1,6 @@
 #include <resolv.h>
 #include "libc.h"
 
-int __res_msend(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int);
-
 int __res_send(const unsigned char *msg, int msglen, unsigned char *answer, int anslen)
 {
 	int r = __res_msend(1, &msg, &msglen, &answer, &anslen, anslen);

+ 0 - 2
src/process/posix_spawn.c

@@ -19,8 +19,6 @@ struct args {
 	char *const *argv, *const *envp;
 };
 
-void __get_handler_set(sigset_t *);
-
 static int __sys_dup2(int old, int new)
 {
 #ifdef SYS_dup2

+ 0 - 2
src/process/posix_spawnp.c

@@ -1,8 +1,6 @@
 #include <spawn.h>
 #include <unistd.h>
 
-int __execvpe(const char *, char *const *, char *const *);
-
 int posix_spawnp(pid_t *restrict res, const char *restrict file,
 	const posix_spawn_file_actions_t *fa,
 	const posix_spawnattr_t *restrict attr,

+ 0 - 2
src/signal/signal.c

@@ -2,8 +2,6 @@
 #include "syscall.h"
 #include "libc.h"
 
-int __sigaction(int, const struct sigaction *, struct sigaction *);
-
 void (*signal(int sig, void (*func)(int)))(int)
 {
 	struct sigaction sa_old, sa = { .sa_handler = func, .sa_flags = SA_RESTART };

+ 1 - 2
src/stdio/freopen.c

@@ -1,5 +1,6 @@
 #include "stdio_impl.h"
 #include <fcntl.h>
+#include <unistd.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
@@ -9,8 +10,6 @@
  * lock, via flockfile or otherwise, when freopen is called, and in that
  * case, freopen cannot act until the lock is released. */
 
-int __dup3(int, int, int);
-
 FILE *freopen(const char *restrict filename, const char *restrict mode, FILE *restrict f)
 {
 	int fl = __fmodeflags(mode);

+ 1 - 2
src/stdio/tempnam.c

@@ -4,12 +4,11 @@
 #include <sys/stat.h>
 #include <limits.h>
 #include <string.h>
+#include <stdlib.h>
 #include "syscall.h"
 
 #define MAXTRIES 100
 
-char *__randname(char *);
-
 char *tempnam(const char *dir, const char *pfx)
 {
 	char s[PATH_MAX];

+ 1 - 2
src/stdio/tmpfile.c

@@ -1,11 +1,10 @@
 #include <stdio.h>
 #include <fcntl.h>
+#include <stdlib.h>
 #include "stdio_impl.h"
 
 #define MAXTRIES 100
 
-char *__randname(char *);
-
 FILE *tmpfile(void)
 {
 	char s[] = "/tmp/tmpfile_XXXXXX";

+ 1 - 2
src/stdio/tmpnam.c

@@ -3,12 +3,11 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <string.h>
+#include <stdlib.h>
 #include "syscall.h"
 
 #define MAXTRIES 100
 
-char *__randname(char *);
-
 char *tmpnam(char *buf)
 {
 	static char internal[L_tmpnam];

+ 0 - 2
src/string/strchr.c

@@ -1,7 +1,5 @@
 #include <string.h>
 
-char *__strchrnul(const char *, int);
-
 char *strchr(const char *s, int c)
 {
 	char *r = __strchrnul(s, c);

+ 0 - 2
src/string/strcpy.c

@@ -1,7 +1,5 @@
 #include <string.h>
 
-char *__stpcpy(char *, const char *);
-
 char *strcpy(char *restrict dest, const char *restrict src)
 {
 	__stpcpy(dest, src);

+ 0 - 2
src/string/strcspn.c

@@ -3,8 +3,6 @@
 #define BITOP(a,b,op) \
  ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a))))
 
-char *__strchrnul(const char *, int);
-
 size_t strcspn(const char *s, const char *c)
 {
 	const char *a = s;

+ 0 - 2
src/string/strncpy.c

@@ -1,7 +1,5 @@
 #include <string.h>
 
-char *__stpncpy(char *, const char *, size_t);
-
 char *strncpy(char *restrict d, const char *restrict s, size_t n)
 {
 	__stpncpy(d, s, n);

+ 0 - 2
src/string/strrchr.c

@@ -1,7 +1,5 @@
 #include <string.h>
 
-void *__memrchr(const void *, int, size_t);
-
 char *strrchr(const char *s, int c)
 {
 	return __memrchr(s, c, strlen(s) + 1);

+ 0 - 2
src/temp/__randname.c

@@ -1,8 +1,6 @@
 #include <time.h>
 #include <stdint.h>
 
-int __clock_gettime(clockid_t, struct timespec *);
-
 /* This assumes that a check for the
    template size has already been made */
 char *__randname(char *template)

+ 0 - 2
src/temp/mkdtemp.c

@@ -3,8 +3,6 @@
 #include <errno.h>
 #include <sys/stat.h>
 
-char *__randname(char *);
-
 char *mkdtemp(char *template)
 {
 	size_t l = strlen(template);

+ 0 - 2
src/temp/mkostemp.c

@@ -2,8 +2,6 @@
 #include <stdlib.h>
 #include "libc.h"
 
-int __mkostemps(char *, int, int);
-
 int mkostemp(char *template, int flags)
 {
 	return __mkostemps(template, 0, flags);

+ 0 - 2
src/temp/mkostemps.c

@@ -6,8 +6,6 @@
 #include <errno.h>
 #include "libc.h"
 
-char *__randname(char *);
-
 int __mkostemps(char *template, int len, int flags)
 {
 	size_t l = strlen(template);

+ 0 - 2
src/temp/mkstemp.c

@@ -1,8 +1,6 @@
 #include <stdlib.h>
 #include "libc.h"
 
-int __mkostemps(char *, int, int);
-
 int mkstemp(char *template)
 {
 	return __mkostemps(template, 0, 0);

+ 0 - 2
src/temp/mkstemps.c

@@ -2,8 +2,6 @@
 #include <stdlib.h>
 #include "libc.h"
 
-int __mkostemps(char *, int, int);
-
 int mkstemps(char *template, int len)
 {
 	return __mkostemps(template, len, 0);

+ 0 - 2
src/temp/mktemp.c

@@ -4,8 +4,6 @@
 #include <errno.h>
 #include <sys/stat.h>
 
-char *__randname(char *);
-
 char *mktemp(char *template)
 {
 	size_t l = strlen(template);

+ 0 - 3
src/thread/__timedwait.c

@@ -5,9 +5,6 @@
 #include "syscall.h"
 #include "pthread_impl.h"
 
-int __pthread_setcancelstate(int, int *);
-int __clock_gettime(clockid_t, struct timespec *);
-
 int __timedwait_cp(volatile int *addr, int val,
 	clockid_t clk, const struct timespec *at, int priv)
 {

+ 1 - 2
src/thread/call_once.c

@@ -1,6 +1,5 @@
 #include <threads.h>
-
-int __pthread_once(once_flag *, void (*)(void));
+#include <pthread.h>
 
 void call_once(once_flag *flag, void (*func)(void))
 {

+ 0 - 2
src/thread/cnd_broadcast.c

@@ -1,8 +1,6 @@
 #include <threads.h>
 #include <pthread.h>
 
-int __private_cond_signal(pthread_cond_t *, int);
-
 int cnd_broadcast(cnd_t *c)
 {
 	/* This internal function never fails, and always returns zero,

+ 0 - 2
src/thread/cnd_signal.c

@@ -1,8 +1,6 @@
 #include <threads.h>
 #include <pthread.h>
 
-int __private_cond_signal(pthread_cond_t *, int);
-
 int cnd_signal(cnd_t *c)
 {
 	/* This internal function never fails, and always returns zero,

+ 0 - 2
src/thread/cnd_timedwait.c

@@ -2,8 +2,6 @@
 #include <pthread.h>
 #include <errno.h>
 
-int __pthread_cond_timedwait(pthread_cond_t *restrict, pthread_mutex_t *restrict, const struct timespec *restrict);
-
 int cnd_timedwait(cnd_t *restrict c, mtx_t *restrict m, const struct timespec *restrict ts)
 {
 	int ret = __pthread_cond_timedwait((pthread_cond_t *)c, (pthread_mutex_t *)m, ts);

+ 0 - 2
src/thread/mtx_timedlock.c

@@ -2,8 +2,6 @@
 #include <pthread.h>
 #include <errno.h>
 
-int __pthread_mutex_timedlock(pthread_mutex_t *restrict, const struct timespec *restrict);
-
 int mtx_timedlock(mtx_t *restrict m, const struct timespec *restrict ts)
 {
 	int ret = __pthread_mutex_timedlock((pthread_mutex_t *)m, ts);

+ 0 - 2
src/thread/mtx_trylock.c

@@ -1,8 +1,6 @@
 #include "pthread_impl.h"
 #include <threads.h>
 
-int __pthread_mutex_trylock(pthread_mutex_t *);
-
 int mtx_trylock(mtx_t *m)
 {
 	if (m->_m_type == PTHREAD_MUTEX_NORMAL)

+ 0 - 2
src/thread/mtx_unlock.c

@@ -1,8 +1,6 @@
 #include <threads.h>
 #include <pthread.h>
 
-int __pthread_mutex_unlock(pthread_mutex_t *);
-
 int mtx_unlock(mtx_t *mtx)
 {
 	/* The only cases where pthread_mutex_unlock can return an

+ 0 - 2
src/thread/pthread_cond_broadcast.c

@@ -1,7 +1,5 @@
 #include "pthread_impl.h"
 
-int __private_cond_signal(pthread_cond_t *, int);
-
 int pthread_cond_broadcast(pthread_cond_t *c)
 {
 	if (!c->_c_shared) return __private_cond_signal(c, -1);

+ 0 - 2
src/thread/pthread_cond_signal.c

@@ -1,7 +1,5 @@
 #include "pthread_impl.h"
 
-int __private_cond_signal(pthread_cond_t *, int);
-
 int pthread_cond_signal(pthread_cond_t *c)
 {
 	if (!c->_c_shared) return __private_cond_signal(c, 1);

+ 0 - 5
src/thread/pthread_cond_timedwait.c

@@ -1,10 +1,5 @@
 #include "pthread_impl.h"
 
-void __pthread_testcancel(void);
-int __pthread_mutex_lock(pthread_mutex_t *);
-int __pthread_mutex_unlock(pthread_mutex_t *);
-int __pthread_setcancelstate(int, int *);
-
 /*
  * struct waiter
  *

+ 0 - 4
src/thread/pthread_create.c

@@ -6,10 +6,6 @@
 #include <string.h>
 #include <stddef.h>
 
-void *__mmap(void *, size_t, int, int, int, off_t);
-int __munmap(void *, size_t);
-int __mprotect(void *, size_t, int);
-
 static void dummy_0()
 {
 }

+ 0 - 2
src/thread/pthread_detach.c

@@ -1,8 +1,6 @@
 #include "pthread_impl.h"
 #include <threads.h>
 
-int __pthread_join(pthread_t, void **);
-
 static int __pthread_detach(pthread_t t)
 {
 	/* If the cas fails, detach state is either already-detached

+ 0 - 4
src/thread/pthread_join.c

@@ -1,10 +1,6 @@
 #include "pthread_impl.h"
 #include <sys/mman.h>
 
-int __munmap(void *, size_t);
-void __pthread_testcancel(void);
-int __pthread_setcancelstate(int, int *);
-
 static int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec *at)
 {
 	int state, cs, r = 0;

+ 0 - 2
src/thread/pthread_mutex_lock.c

@@ -1,7 +1,5 @@
 #include "pthread_impl.h"
 
-int __pthread_mutex_timedlock(pthread_mutex_t *restrict, const struct timespec *restrict);
-
 int __pthread_mutex_lock(pthread_mutex_t *m)
 {
 	if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL

+ 0 - 2
src/thread/pthread_mutex_timedlock.c

@@ -1,7 +1,5 @@
 #include "pthread_impl.h"
 
-int __pthread_mutex_trylock(pthread_mutex_t *);
-
 int __pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec *restrict at)
 {
 	if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL

+ 0 - 2
src/thread/sem_open.c

@@ -13,8 +13,6 @@
 #include <pthread.h>
 #include "libc.h"
 
-char *__shm_mapname(const char *, char *);
-
 static struct {
 	ino_t ino;
 	sem_t *sem;

+ 0 - 2
src/thread/thrd_create.c

@@ -1,8 +1,6 @@
 #include "pthread_impl.h"
 #include <threads.h>
 
-int __pthread_create(pthread_t *restrict, const pthread_attr_t *restrict, void *(*)(void *), void *restrict);
-
 int thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
 {
 	int ret = __pthread_create(thr, __ATTRP_C11_THREAD, (void *(*)(void *))func, arg);

+ 2 - 3
src/thread/thrd_exit.c

@@ -1,7 +1,6 @@
-#include "pthread_impl.h"
 #include <threads.h>
-
-_Noreturn void __pthread_exit(void *);
+#include <pthread.h>
+#include <stdint.h>
 
 _Noreturn void thrd_exit(int result)
 {

+ 1 - 2
src/thread/thrd_join.c

@@ -1,7 +1,6 @@
 #include <stdint.h>
 #include <threads.h>
-
-int __pthread_join(thrd_t, void**);
+#include <pthread.h>
 
 int thrd_join(thrd_t t, int *res)
 {

+ 1 - 2
src/thread/tss_create.c

@@ -1,6 +1,5 @@
 #include <threads.h>
-
-int __pthread_key_create(tss_t *, void (*)(void *));
+#include <pthread.h>
 
 int tss_create(tss_t *tss, tss_dtor_t dtor)
 {

+ 1 - 2
src/thread/tss_delete.c

@@ -1,6 +1,5 @@
 #include <threads.h>
-
-int __pthread_key_delete(tss_t k);
+#include <pthread.h>
 
 void tss_delete(tss_t key)
 {

+ 0 - 2
src/time/__map_file.c

@@ -3,8 +3,6 @@
 #include <sys/stat.h>
 #include "syscall.h"
 
-void *__mmap(void *, size_t, int, int, int, off_t);
-
 const char unsigned *__map_file(const char *pathname, size_t *size)
 {
 	struct stat st;

+ 1 - 2
src/time/__tz.c

@@ -3,6 +3,7 @@
 #include <limits.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/mman.h>
 #include "libc.h"
 
 long  __timezone = 0;
@@ -113,8 +114,6 @@ static size_t zi_dotprod(const unsigned char *z, const unsigned char *v, size_t
 	return y;
 }
 
-int __munmap(void *, size_t);
-
 static void do_tzset()
 {
 	char buf[NAME_MAX+25], *pathname=buf+24;

+ 0 - 2
src/time/asctime.c

@@ -1,7 +1,5 @@
 #include <time.h>
 
-char *__asctime_r(const struct tm *, char *);
-
 char *asctime(const struct tm *tm)
 {
 	static char buf[26];

+ 0 - 2
src/time/asctime_r.c

@@ -5,8 +5,6 @@
 #include "atomic.h"
 #include "libc.h"
 
-char *__nl_langinfo_l(nl_item, locale_t);
-
 char *__asctime_r(const struct tm *restrict tm, char *restrict buf)
 {
 	if (snprintf(buf, 26, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",

+ 0 - 2
src/time/clock.c

@@ -1,8 +1,6 @@
 #include <time.h>
 #include <limits.h>
 
-int __clock_gettime(clockid_t, struct timespec *);
-
 clock_t clock()
 {
 	struct timespec ts;

+ 0 - 2
src/time/gmtime.c

@@ -1,8 +1,6 @@
 #include "time_impl.h"
 #include <errno.h>
 
-struct tm *__gmtime_r(const time_t *restrict, struct tm *restrict);
-
 struct tm *gmtime(const time_t *t)
 {
 	static struct tm tm;

+ 0 - 2
src/time/localtime.c

@@ -1,7 +1,5 @@
 #include "time_impl.h"
 
-struct tm *__localtime_r(const time_t *restrict, struct tm *restrict);
-
 struct tm *localtime(const time_t *t)
 {
 	static struct tm tm;

+ 0 - 4
src/time/strftime.c

@@ -9,8 +9,6 @@
 #include "libc.h"
 #include "time_impl.h"
 
-char *__nl_langinfo_l(nl_item, locale_t);
-
 static int is_leap(int y)
 {
 	/* Avoid overflow */
@@ -45,8 +43,6 @@ static int week_num(const struct tm *tm)
 	return val;
 }
 
-size_t __strftime_l(char *restrict, size_t, const char *restrict, const struct tm *restrict, locale_t);
-
 const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *tm, locale_t loc, int pad)
 {
 	nl_item item;

+ 0 - 2
src/time/time.c

@@ -1,8 +1,6 @@
 #include <time.h>
 #include "syscall.h"
 
-int __clock_gettime(clockid_t, struct timespec *);
-
 time_t time(time_t *t)
 {
 	struct timespec ts;

+ 0 - 1
src/time/time_impl.h

@@ -7,5 +7,4 @@ long long __tm_to_secs(const struct tm *);
 const char *__tm_to_tzname(const struct tm *);
 int __secs_to_tm(long long, struct tm *);
 void __secs_to_zone(long long, int, int *, long *, long *, const char **);
-const unsigned char *__map_file(const char *, size_t *);
 const char *__strftime_fmt_1(char (*)[100], size_t *, int, const struct tm *, locale_t, int);

+ 0 - 2
src/time/timespec_get.c

@@ -1,7 +1,5 @@
 #include <time.h>
 
-int __clock_gettime(clockid_t, struct timespec *);
-
 /* There is no other implemented value than TIME_UTC; all other values
  * are considered erroneous. */
 int timespec_get(struct timespec * ts, int base)