unified-libc.c (4658B)
1 /* unified-libc.c — single translation unit gathering every vendored 2 * mes-libc .c plus boot2-syscall.c. The host preprocessor flattens 3 * the whole thing to libc.flat.c, which cc.scm compiles to libc.P1pp. 4 * 5 * Order matters in a few specific places: 6 * 1. boot2-syscall.c declares the extern sys_* P1pp labels and 7 * defines _read / _write / _open3 / close / lseek / brk / unlink / 8 * _exit. It comes early so later layers see the prototypes. 9 * 2. mes/globals.c defines errno / __stdin etc. as tentative 10 * definitions; mes/mes_open.c later assigns them initial values. 11 * Tentative-then-initialized is a standard C resolution; cc.scm 12 * follows the C linkage rule (commit 6488cca). 13 * 3. linux/malloc.c provides the allocator and the __brk pointer 14 * that posix/sbrk.c re-exports. 15 * 16 * Everything else is order-independent — each mes .c is a self-contained 17 * function or two with its own header includes. 18 */ 19 20 #include <mes/lib.h> 21 22 /* ---- low-level: P1pp syscall wrappers + thin posix glue --------- */ 23 #include "boot2-syscall.c" 24 25 /* ---- ctype ------------------------------------------------------ */ 26 #include "ctype/isalnum.c" 27 #include "ctype/isalpha.c" 28 #include "ctype/isascii.c" 29 #include "ctype/iscntrl.c" 30 #include "ctype/isdigit.c" 31 #include "ctype/isgraph.c" 32 #include "ctype/islower.c" 33 #include "ctype/isnumber.c" 34 #include "ctype/isprint.c" 35 #include "ctype/ispunct.c" 36 #include "ctype/isspace.c" 37 #include "ctype/isupper.c" 38 #include "ctype/isxdigit.c" 39 #include "ctype/tolower.c" 40 #include "ctype/toupper.c" 41 42 /* ---- string ----------------------------------------------------- */ 43 /* memcpy/memmove/memset/memcmp are compiler-builtin runtime supplied 44 by libp1pp (see P1/P1pp.P1pp). Omit mes-libc's copies so the 45 symbols are not duplicated at hex2++ link time. */ 46 #include "string/memchr.c" 47 #include "string/memmem.c" 48 #include "string/strcat.c" 49 #include "string/strchr.c" 50 #include "string/strcmp.c" 51 #include "string/strcpy.c" 52 #include "string/strcspn.c" 53 #include "string/strdup.c" 54 #include "string/strerror.c" 55 #include "string/strlen.c" 56 #include "string/strncat.c" 57 #include "string/strncmp.c" 58 #include "string/strncpy.c" 59 #include "string/strpbrk.c" 60 #include "string/strrchr.c" 61 #include "string/strspn.c" 62 #include "string/strstr.c" 63 #include "string/strupr.c" 64 65 /* ---- mes runtime ------------------------------------------------ */ 66 #include "mes/globals.c" 67 #include "mes/cast.c" 68 #include "mes/__assert_fail.c" 69 #include "mes/abtol.c" 70 #include "mes/dtoab.c" 71 #include "mes/eputc.c" 72 #include "mes/eputs.c" 73 #include "mes/fdgetc.c" 74 #include "mes/fdgets.c" 75 #include "mes/fdputc.c" 76 #include "mes/fdputs.c" 77 #include "mes/fdungetc.c" 78 #include "mes/__buffered_read.c" 79 #include "mes/__init_io.c" 80 #include "mes/__mes_debug.c" 81 #include "mes/itoa.c" 82 #include "mes/ltoa.c" 83 #include "mes/ltoab.c" 84 #include "mes/mes_open.c" 85 #include "mes/ntoab.c" 86 #include "mes/oputc.c" 87 #include "mes/oputs.c" 88 #include "mes/search-path.c" 89 #include "mes/ultoa.c" 90 #include "mes/utoa.c" 91 92 /* ---- stdlib ----------------------------------------------------- */ 93 #include "stdlib/__exit.c" 94 #include "stdlib/abort.c" 95 #include "stdlib/atoi.c" 96 #include "stdlib/atol.c" 97 #include "stdlib/calloc.c" 98 #include "stdlib/exit.c" 99 #include "stdlib/free.c" 100 #include "stdlib/puts.c" 101 #include "stdlib/qsort.c" 102 #include "stdlib/realloc.c" 103 #include "stdlib/strtof.c" 104 #include "stdlib/strtol.c" 105 #include "stdlib/strtoll.c" 106 #include "stdlib/strtoul.c" 107 #include "stdlib/strtoull.c" 108 109 /* ---- linux (allocator only; the rest replaced by boot2-syscall.c) */ 110 #include "linux/malloc.c" 111 112 /* ---- posix ------------------------------------------------------ */ 113 #include "posix/buffered-read.c" 114 #include "posix/execvp.c" 115 #include "posix/getcwd.c" 116 #include "posix/getenv.c" 117 #include "posix/open.c" 118 #include "posix/sbrk.c" 119 #include "posix/write.c" 120 121 /* ---- stdio ------------------------------------------------------ */ 122 #include "stdio/clearerr.c" 123 #include "stdio/fclose.c" 124 #include "stdio/fdopen.c" 125 #include "stdio/feof.c" 126 #include "stdio/ferror.c" 127 #include "stdio/fflush.c" 128 #include "stdio/fgetc.c" 129 #include "stdio/fgets.c" 130 #include "stdio/fileno.c" 131 #include "stdio/fopen.c" 132 #include "stdio/fprintf.c" 133 #include "stdio/fputc.c" 134 #include "stdio/fputs.c" 135 #include "stdio/fread.c" 136 #include "stdio/fseek.c" 137 #include "stdio/ftell.c" 138 #include "stdio/fwrite.c" 139 #include "stdio/getc.c" 140 #include "stdio/perror.c" 141 #include "stdio/printf.c" 142 #include "stdio/putc.c" 143 #include "stdio/remove.c" 144 #include "stdio/snprintf.c" 145 #include "stdio/sprintf.c" 146 #include "stdio/ungetc.c" 147 #include "stdio/vfprintf.c" 148 #include "stdio/vprintf.c" 149 #include "stdio/vsnprintf.c" 150 #include "stdio/vsprintf.c"