boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

commit c7d6dc60f8453a4d4fc5384c29030d5b23c8c438
parent a661617c6f3c8f260539fe2c8c85a94b5b95e7cf
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Wed, 29 Apr 2026 11:02:04 -0700

vendor/mes-libc

Diffstat:
Avendor/mes-libc/LICENSE | 674+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/ctype/isalnum.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/ctype/isalpha.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/ctype/isascii.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/ctype/iscntrl.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/ctype/isdigit.c | 28++++++++++++++++++++++++++++
Avendor/mes-libc/ctype/isgraph.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/ctype/islower.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/ctype/isnumber.c | 34++++++++++++++++++++++++++++++++++
Avendor/mes-libc/ctype/isprint.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/ctype/ispunct.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/ctype/isspace.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/ctype/isupper.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/ctype/isxdigit.c | 28++++++++++++++++++++++++++++
Avendor/mes-libc/ctype/tolower.c | 29+++++++++++++++++++++++++++++
Avendor/mes-libc/ctype/toupper.c | 29+++++++++++++++++++++++++++++
Avendor/mes-libc/include/alloca.h | 44++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/ar.h | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/argz.h | 40++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/assert.h | 35+++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/ctype.h | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/dirent.h | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/dirstream.h | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/dlfcn.h | 44++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/endian.h | 36++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/errno.h | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/fcntl.h | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/features.h | 28++++++++++++++++++++++++++++
Avendor/mes-libc/include/float.h | 34++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/getopt.h | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/gnu/hurd-types.h | 393+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/gnu/hurd.h | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/gnu/syscall.h | 144+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/gnu/x86/kernel-stat.h | 30++++++++++++++++++++++++++++++
Avendor/mes-libc/include/gnu/x86/signal.h | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/grp.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/inttypes.h | 34++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/libgen.h | 34++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/limits.h | 40++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/linux/SYSCALLS | 111+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/linux/arm/kernel-stat.h | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/linux/arm/signal.h | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/linux/arm/syscall.h | 122+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/linux/m2/kernel-stat.h | 47+++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/linux/riscv32/kernel-stat.h | 46++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/linux/riscv64/kernel-stat.h | 48++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/linux/riscv64/signal.h | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/linux/riscv64/syscall.h | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/linux/syscall.h | 33+++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/linux/x86/kernel-stat.h | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/linux/x86/signal.h | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/linux/x86/syscall.h | 124+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/linux/x86_64/kernel-stat.h | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/linux/x86_64/signal.h | 102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/linux/x86_64/syscall.h | 104+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/locale.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/m2/types.h | 145+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/mach/mach-init.h | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/math.h | 43+++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/memory.h | 36++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/mes/builtins.h | 211+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/mes/cc.h | 42++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/mes/config.h | 3+++
Avendor/mes-libc/include/mes/constants.h | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/mes/lib-cc.h | 29+++++++++++++++++++++++++++++
Avendor/mes-libc/include/mes/lib-mini.h | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/mes/lib.h | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/mes/mes.h | 213+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/mes/mescc-builtins.h | 40++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/mes/symbols.h | 141+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/pwd.h | 46++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/setjmp.h | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/signal.h | 193+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/stdarg.h | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/stdbool.h | 36++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/stddef.h | 47+++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/stdint.h | 126+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/stdio.h | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/stdlib.h | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/stdnoreturn.h | 34++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/string.h | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/strings.h | 28++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/cdefs.h | 28++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/dir.h | 32++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/file.h | 32++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/ioctl.h | 41+++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/mman.h | 43+++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/param.h | 31+++++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/resource.h | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/select.h | 30++++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/stat.h | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/time.h | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/timeb.h | 28++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/times.h | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/types.h | 174+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/ucontext.h | 28++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/user.h | 111+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/utsname.h | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/sys/wait.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/termio.h | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/time.h | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/include/unistd.h | 110+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/linux/malloc.c | 44++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/lispcc-syscall.c | 248+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/__assert_fail.c | 48++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/__buffered_read.c | 109+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/__init_io.c | 30++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/__mes_debug.c | 36++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/abtol.c | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/cast.c | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/dtoab.c | 46++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/eputc.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/mes/eputs.c | 30++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/fdgetc.c | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/fdgets.c | 40++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/fdputc.c | 29+++++++++++++++++++++++++++++
Avendor/mes-libc/mes/fdputs.c | 30++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/fdungetc.c | 37+++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/globals.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/mes/itoa.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/mes/ltoa.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/mes/ltoab.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/mes/mes_open.c | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/ntoab.c | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/oputc.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/mes/oputs.c | 30++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/search-path.c | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/mes/ultoa.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/mes/utoa.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/patches/lib-mes-debug-proto.after | 2++
Avendor/mes-libc/patches/lib-mes-debug-proto.before | 2++
Avendor/mes-libc/patches/libmini-write-proto.after | 1+
Avendor/mes-libc/patches/libmini-write-proto.before | 1+
Avendor/mes-libc/patches/libmini-write-proto2.after | 1+
Avendor/mes-libc/patches/libmini-write-proto2.before | 1+
Avendor/mes-libc/patches/malloc-max-align.after | 5+++++
Avendor/mes-libc/patches/malloc-max-align.before | 5+++++
Avendor/mes-libc/patches/strstr-drop-mman.after | 2++
Avendor/mes-libc/patches/strstr-drop-mman.before | 3+++
Avendor/mes-libc/posix/buffered-read.c | 48++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/posix/execvp.c | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/posix/getcwd.c | 33+++++++++++++++++++++++++++++++++
Avendor/mes-libc/posix/getenv.c | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/posix/open.c | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/posix/sbrk.c | 36++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/posix/write.c | 41+++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/clearerr.c | 29+++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/fclose.c | 29+++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/fdopen.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/stdio/feof.c | 30++++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/ferror.c | 30++++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/fflush.c | 32++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/fgetc.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/stdio/fgets.c | 28++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/fileno.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/stdio/fopen.c | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/fprintf.c | 33+++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/fputc.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/stdio/fputs.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/stdio/fread.c | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/fseek.c | 41+++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/ftell.c | 29+++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/fwrite.c | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/getc.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/stdio/perror.c | 30++++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/printf.c | 39+++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/putc.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/stdio/remove.c | 34++++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/snprintf.c | 39+++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/sprintf.c | 39+++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/ungetc.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/stdio/vfprintf.c | 252+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/vprintf.c | 29+++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/vsnprintf.c | 275+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdio/vsprintf.c | 28++++++++++++++++++++++++++++
Avendor/mes-libc/stdlib/__exit.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/stdlib/abort.c | 32++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdlib/atoi.c | 28++++++++++++++++++++++++++++
Avendor/mes-libc/stdlib/atol.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/stdlib/calloc.c | 31+++++++++++++++++++++++++++++++
Avendor/mes-libc/stdlib/exit.c | 35+++++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdlib/free.c | 26++++++++++++++++++++++++++
Avendor/mes-libc/stdlib/puts.c | 28++++++++++++++++++++++++++++
Avendor/mes-libc/stdlib/qsort.c | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdlib/realloc.c | 34++++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdlib/strtof.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/stdlib/strtol.c | 40++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/stdlib/strtoll.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/stdlib/strtoul.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/stdlib/strtoull.c | 27+++++++++++++++++++++++++++
Avendor/mes-libc/string/memchr.c | 37+++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/memcmp.c | 40++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/memcpy.c | 44++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/memmem.c | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/memmove.c | 33+++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/memset.c | 40++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/strcat.c | 31+++++++++++++++++++++++++++++++
Avendor/mes-libc/string/strchr.c | 34++++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/strcmp.c | 33+++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/strcpy.c | 37+++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/strcspn.c | 33+++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/strdup.c | 32++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/strerror.c | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/strlen.c | 32++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/strncat.c | 33+++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/strncmp.c | 37+++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/strncpy.c | 36++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/strpbrk.c | 33+++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/strrchr.c | 40++++++++++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/strspn.c | 33+++++++++++++++++++++++++++++++++
Avendor/mes-libc/string/strstr.c | 29+++++++++++++++++++++++++++++
Avendor/mes-libc/string/strupr.c | 34++++++++++++++++++++++++++++++++++
Avendor/mes-libc/unified-libc.c | 151++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
213 files changed, 12029 insertions(+), 0 deletions(-)

diff --git a/vendor/mes-libc/LICENSE b/vendor/mes-libc/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<https://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<https://www.gnu.org/licenses/why-not-lgpl.html>. diff --git a/vendor/mes-libc/ctype/isalnum.c b/vendor/mes-libc/ctype/isalnum.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <ctype.h> + +int +isalnum (int c) +{ + return isdigit (c) || isalpha (c); +} diff --git a/vendor/mes-libc/ctype/isalpha.c b/vendor/mes-libc/ctype/isalpha.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <ctype.h> + +int +isalpha (int c) +{ + return islower (c) || isupper (c); +} diff --git a/vendor/mes-libc/ctype/isascii.c b/vendor/mes-libc/ctype/isascii.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <ctype.h> + +int +isascii (int c) +{ + return c >= 0 && c <= 127; +} diff --git a/vendor/mes-libc/ctype/iscntrl.c b/vendor/mes-libc/ctype/iscntrl.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <ctype.h> + +int +iscntrl (int c) +{ + return c >= 0 && c < 32; +} diff --git a/vendor/mes-libc/ctype/isdigit.c b/vendor/mes-libc/ctype/isdigit.c @@ -0,0 +1,28 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2023 Rick Masters <grick23@gmail.com> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> + +int +isdigit (int c) +{ + return c >= '0' && c <= '9'; +} diff --git a/vendor/mes-libc/ctype/isgraph.c b/vendor/mes-libc/ctype/isgraph.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <ctype.h> + +int +isgraph (int c) +{ + return c > 32 && c < 127; +} diff --git a/vendor/mes-libc/ctype/islower.c b/vendor/mes-libc/ctype/islower.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <ctype.h> + +int +islower (int c) +{ + return c >= 'a' && c <= 'z'; +} diff --git a/vendor/mes-libc/ctype/isnumber.c b/vendor/mes-libc/ctype/isnumber.c @@ -0,0 +1,34 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <ctype.h> + +int +isnumber (int c, int base) +{ + if (base == 2) + return (c >= '0') && (c <= '1'); + if (base == 8) + return (c >= '0') && (c <= '7'); + if (base == 10) + return isdigit (c); + if (base == 16) + return isxdigit (c); +} diff --git a/vendor/mes-libc/ctype/isprint.c b/vendor/mes-libc/ctype/isprint.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <ctype.h> + +int +isprint (int c) +{ + return c >= 32 && c < 127; +} diff --git a/vendor/mes-libc/ctype/ispunct.c b/vendor/mes-libc/ctype/ispunct.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <ctype.h> + +int +ispunct (int c) +{ + return isprint (c) && !isspace (c) && !isalnum (c); +} diff --git a/vendor/mes-libc/ctype/isspace.c b/vendor/mes-libc/ctype/isspace.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> + +int +isspace (int c) +{ + return (c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r' || c == ' '); +} diff --git a/vendor/mes-libc/ctype/isupper.c b/vendor/mes-libc/ctype/isupper.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <ctype.h> + +int +isupper (int c) +{ + return c >= 'A' && c <= 'Z'; +} diff --git a/vendor/mes-libc/ctype/isxdigit.c b/vendor/mes-libc/ctype/isxdigit.c @@ -0,0 +1,28 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <ctype.h> + +int +isxdigit (int c) +{ + return isdigit (c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); +} diff --git a/vendor/mes-libc/ctype/tolower.c b/vendor/mes-libc/ctype/tolower.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <ctype.h> + +int +tolower (int c) +{ + if (isupper (c)) + return c + ('a' - 'A'); + return c; +} diff --git a/vendor/mes-libc/ctype/toupper.c b/vendor/mes-libc/ctype/toupper.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <ctype.h> + +int +toupper (int c) +{ + if (islower (c)) + return c - ('a' - 'A'); + return c; +} diff --git a/vendor/mes-libc/include/alloca.h b/vendor/mes-libc/include/alloca.h @@ -0,0 +1,44 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_ALLOCA_H +#define __MES_ALLOCA_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_ALLOCA_H +#include_next <alloca.h> + +#else // ! SYSTEM_LIBC + +#include <sys/types.h> + +#if _ALLOCA_UNSIGNED +void *alloca (unsigned size); +#elif _ALLOCA_CHAR +char *alloca (int); +#else +void *alloca (size_t size); +#endif + +#endif // ! SYSTEM_LIBC + +#endif // __MES_ALLOCA_H diff --git a/vendor/mes-libc/include/ar.h b/vendor/mes-libc/include/ar.h @@ -0,0 +1,56 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright (C) 1996 Free Software Foundation, Inc. + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_AR_H +#define __MES_AR_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_AR_H +#include_next <ar.h> + +#else // ! SYSTEM_LIBC + +// Taken from GNU C Library 2.2.5 + +/* Archive files start with the ARMAG identifying string. Then follows a + `struct ar_hdr', and as many bytes of member file data as its `ar_size' + member indicates, for each member file. */ + +#define ARMAG "!<arch>\n" /* String that begins an archive file. */ +#define SARMAG 8 /* Size of that string. */ + +#define ARFMAG "`\n" /* String in ar_fmag at end of each header. */ + +struct ar_hdr +{ + char ar_name[16]; /* Member file name, sometimes / terminated. */ + char ar_date[12]; /* File date, decimal seconds since Epoch. */ + char ar_uid[6], ar_gid[6]; /* User and group IDs, in ASCII decimal. */ + char ar_mode[8]; /* File mode, in ASCII octal. */ + char ar_size[10]; /* File size, in ASCII decimal. */ + char ar_fmag[2]; /* Always contains ARFMAG. */ +}; + +#endif // ! SYSTEM_LIBC + +#endif // __MES_ARGZ_H diff --git a/vendor/mes-libc/include/argz.h b/vendor/mes-libc/include/argz.h @@ -0,0 +1,40 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_ARGZ_H +#define __MES_ARGZ_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_ARGZ_H +#include_next <argz.h> + +#else // ! SYSTEM_LIBC + +#include <mes/lib-mini.h> + +size_t __argz_count (char const *argz, size_t len); +void __argz_extract (char const *argz, size_t len, char **argv); +size_t __argz_extract_count (char const *argz, size_t len, char **argv); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_ARGZ_H diff --git a/vendor/mes-libc/include/assert.h b/vendor/mes-libc/include/assert.h @@ -0,0 +1,35 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_ASSERT_H +#define __MES_ASSERT_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_ASSERT_H +#include_next <assert.h> +#else // ! SYSTEM_LIBC +#define assert(x) ((x) ? (void)0 : __assert_fail (#x, 0, 0, 0)) +void __assert_fail (char const *s, char const *file, unsigned line, + char const *function); +#endif // ! SYSTEM_LIBC + +#endif // __MES_ASSERT_H diff --git a/vendor/mes-libc/include/ctype.h b/vendor/mes-libc/include/ctype.h @@ -0,0 +1,51 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_CTYPE_H +#define __MES_CTYPE_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_CTYPE_H +#include_next <ctype.h> + +#else // ! SYSTEM_LIBC +#include <endian.h> + +int isalnum (int c); +int isalpha (int c); +int isascii (int c); +int iscntrl (int c); +int isdigit (int c); +int isgraph (int c); +int islower (int c); +int isnumber (int c, int base); +int isprint (int c); +int ispunct (int c); +int isspace (int c); +int isupper (int c); +int isxdigit (int c); +int tolower (int c); +int toupper (int c); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_CTYPE_H diff --git a/vendor/mes-libc/include/dirent.h b/vendor/mes-libc/include/dirent.h @@ -0,0 +1,87 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright (C) 1991, 1992 Free Software Foundation, Inc. + * Copyright © 2018,2024 Janneke Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2024 Andrius Štikonas <andrius@stikonas.eu> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __MES_DIRENT_H +#define __MES_DIRENT_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_DIRENT_H +#include_next <dirent.h> + +#else // ! SYSTEM_LIBC + +#include <arch/syscall.h> +#include <dirstream.h> + +// Taken from GNU C Library 1.06.4, 2.2.5 + +/* + * POSIX Standard: 5.1.2 Directory Operations <dirent.h> + */ + +#include <stddef.h> + +int __getdirentries (int filedes, char *buffer, size_t nbytes, off_t * basep); + +// FIXME move to include/<kernel>/<arch>/dirent.h? +struct dirent +{ + ino_t d_ino; +#if defined (SYS_getdents64) && (__SIZEOF_LONG__ == 4 || __arm__ || __i386__) + // FIXME: redefine ino_t to ino64_t instead? + int d_ino_h; +#endif + off_t d_off; +#if defined (SYS_getdents64) && (__SIZEOF_LONG__ == 4 || __arm__ || __i386__) + // FIXME: redefine off_t to off64_t instead? + int d_off_h; +#endif + unsigned short int d_reclen; +#if defined (SYS_getdents64) + unsigned char d_type; +#endif + char d_name[256]; +}; + +/* Open a directory stream on NAME. + Return a DIR stream on the directory, or NULL if it could not be opened. */ +DIR *opendir (char const *name); + +/* Close the directory stream DIRP. + Return 0 if successful, -1 if not. */ +int closedir (DIR * dirp); + +/* Read a directory entry from DIRP. + Return a pointer to a `struct dirent' describing the entry, + or NULL for EOF or error. The storage returned may be overwritten + by a later readdir call on the same DIR stream. */ +struct dirent *readdir (DIR * dirp); + +/* Rewind DIRP to the beginning of the directory. */ +extern void rewinddir (DIR * dirp); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_DIRENT_H diff --git a/vendor/mes-libc/include/dirstream.h b/vendor/mes-libc/include/dirstream.h @@ -0,0 +1,55 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + *Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc. + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __MES_DIRSTREAM_H +#define __MES_DIRSTREAM_H 1 + +#if SYSTEM_LIBC && HAVE_DIRSTREAM_H +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_DIRSTREAM_H +#include_next <dirstream.h> + +#else // ! SYSTEM_LIBC + +#include <sys/types.h> + +// Taken from GNU C Library 2.2.5 + +/* Directory stream type. */ +struct __dirstream +{ + int fd; /* File descriptor. */ + + char *data; /* Directory block. */ + size_t allocation; /* Space allocated for the block. */ + size_t size; /* Total valid data in the block. */ + size_t offset; /* Current offset into the block. */ + + off_t filepos; /* Position of next entry to read. */ +}; + +typedef struct __dirstream DIR; + +#endif // ! SYSTEM_LIBC + +#endif // __MES_DIRSTREAM_H diff --git a/vendor/mes-libc/include/dlfcn.h b/vendor/mes-libc/include/dlfcn.h @@ -0,0 +1,44 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_DLFCN_H +#define __MES_DLFCN_H 1 + +#if SYSTEM_LIBC +#undef __MES_DLFCN_H +#include_next <dlfcn.h> + +#else // ! SYSTEM_LIBC + +#define RTLD_LAZY 0x00001 +#define RTLD_NOW 0x00002 +#define RTLD_BINDING_MASK 0x3 +#define RTLD_NOLOAD 0x00004 +#define RTLD_DEEPBIND 0x00008 +#define RTLD_GLOBAL 0x00100 +#define RTLD_LOCAL 0 +#define RTLD_NODELETE 0x01000 +#define RTLD_DEFAULT 0 + +void *dlopen (char const *filename, int flags); +int dlclose (void *handle); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_DLFCN_H diff --git a/vendor/mes-libc/include/endian.h b/vendor/mes-libc/include/endian.h @@ -0,0 +1,36 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_ENDIAN_H +#define __MES_ENDIAN_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_ENDIAN_H +#include_next <endian.h> + +#else // ! SYSTEM_LIBC +#define __LITTLE_ENDIAN 1234 +#define __BIG_ENDIAN 4321 +#define __BYTE_ORDER __LITTLE_ENDIAN +#endif // ! SYSTEM_LIBC + +#endif // __MES_ENDIAN_H diff --git a/vendor/mes-libc/include/errno.h b/vendor/mes-libc/include/errno.h @@ -0,0 +1,71 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_ERRNO_H +#define __MES_ERRNO_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_ERRNO_H +#include_next <errno.h> +#else // ! SYSTEM_LIBC + +#ifndef __MES_ERRNO_T +#define __MES_ERRNO_T 1 +typedef int error_t; +#endif // !__MES_ERRNO_T + +extern int errno; +#define ENOENT 2 +#define EINTR 4 +#define EIO 5 +#define ENXIO 6 +#define E2BIG 7 +#define ENOEXEC 8 +#define EBADF 9 +#define ECHILD 10 +#define EAGAIN 11 +#define ENOMEM 12 +#define EACCES 13 +#define EEXIST 17 +#define EXDEV 18 +#define ENOTDIR 20 +#define EISDIR 21 +#define EINVAL 22 +#define EMFILE 24 +#define ENOSPC 28 +#define ESPIPE 29 +#define EPIPE 32 +#define ERANGE 34 + +#define ENAMETOOLONG 36 +#define ENOSYS 38 +#define ELOOP 40 + +#if !__MESC__ && ! __M2__ +//extern char const *const sys_errlist[]; +extern char *sys_errlist[]; +extern int sys_nerr; +#endif // !__MESC__ + +#endif // ! SYSTEM_LIBC + +#endif // __MES_ERRNO_H diff --git a/vendor/mes-libc/include/fcntl.h b/vendor/mes-libc/include/fcntl.h @@ -0,0 +1,87 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com> + * Copyright © 2023 Emily Trau <emily@downunderctf.com> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_FCNTL_H +#define __MES_FCNTL_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_FCNTL_H +#include_next <fcntl.h> + +#else // ! SYSTEM_LIBC + +// *INDENT-OFF* +#if __linux__ +#define O_RDONLY 0 +#define O_WRONLY 1 +#define O_RDWR 2 +#define O_CREAT 0x40 +#define O_EXCL 0x80 +#define O_TRUNC 0x200 +#define O_APPEND 0x400 + +#ifdef __arm__ +#define O_DIRECTORY 0x4000 +#define O_TMPFILE 0x404000 +#else +#define O_DIRECTORY 0x10000 +#define O_TMPFILE 0x410000 +#endif + +#define AT_FDCWD -100 +#define AT_SYMLINK_NOFOLLOW 0x100 +#define AT_REMOVEDIR 0x200 + +#elif __GNU__ +#define O_RDONLY 1 +#define O_WRONLY 2 +#define O_RDWR 3 +#define O_CREAT 0x10 +#define O_APPEND 0x100 +#define O_TRUNC 0x10000 +#else +#error platform not supported +#endif +// *INDENT-ON* + +#define FD_CLOEXEC 1 + +#define F_DUPFD 0 +#define F_GETFD 1 +#define F_SETFD 2 +#define F_GETFL 3 +#define F_SETFL 4 + +#define creat(file_name, mode) open (file_name, O_WRONLY | O_CREAT | O_TRUNC, mode) +int dup (int old); +int dup2 (int old, int new); + +#if !__M2__ +int fcntl (int filedes, int command, ...); +int open (char const *s, int flags, ...); +#endif + +#endif // ! SYSTEM_LIBC + +#endif // __MES_FCNTL_H diff --git a/vendor/mes-libc/include/features.h b/vendor/mes-libc/include/features.h @@ -0,0 +1,28 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_FEATURES_H +#define __MES_FEATURES_H 1 + +#if SYSTEM_LIBC +#undef __MES_FEATURES_H +#include_next <features.h> +#endif // (SYSTEM_LIBC) + +#endif // __MES_FEATURES_H diff --git a/vendor/mes-libc/include/float.h b/vendor/mes-libc/include/float.h @@ -0,0 +1,34 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_FLOAT_H +#define __MES_FLOAT_H 1 + +#if SYSTEM_LIBC +#undef __MES_FLOAT_H +#include_next <float.h> +#else // ! SYSTEM_LIBC + +#define MIN_EXP -1021 +#define DBL_MIN_EXP -1021 +#define LDBL_MIN_EXP -1021 + +#endif // ! SYSTEM_LIBC + +#endif // __MES_FLOAT_H diff --git a/vendor/mes-libc/include/getopt.h b/vendor/mes-libc/include/getopt.h @@ -0,0 +1,62 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_GETOPT_H +#define __MES_GETOPT_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_GETOPT_H +#include_next <getopt.h> + +#else // ! SYSTEM_LIBC +#include <endian.h> +int isdigit (int); +int isxdigit (int); + +char *optarg; +int optind; +int opterr; +struct option +{ + char const *name; + int has_arg; + int *flag; + int val; +}; + +enum _argtype +{ + no_argument, + required_argument, + optional_argument +}; + +int getopt (int argc, char *const *argv, char const *options); +int getopt_long (int argc, char *const *argv, char const *options, + struct option const *long_options, int *opt_index); +int getopt_long_only (int argc, char *const *argv, char const *options, + struct option const *long_options, int *opt_index); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_GETOPT_H diff --git a/vendor/mes-libc/include/gnu/hurd-types.h b/vendor/mes-libc/include/gnu/hurd-types.h @@ -0,0 +1,393 @@ +/* C declarations for Hurd server interfaces + Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2001, 2002, + 2010 Free Software Foundation, Inc. + +This file is part of the GNU Hurd. + +The GNU Hurd is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +The GNU Hurd is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the GNU Hurd; see the file COPYING. If not, write to +the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#ifndef _HURD_TYPES_H +#define _HURD_TYPES_H + +#ifndef _FILE_OFFSET_BITS +#define _FILE_OFFSET_BITS 32 +#endif + +#include <time.h> /* For struct timespec. */ +#include <mach/std_types.h> /* For mach_port_t et al. */ +#include <mach/message.h> /* For mach_msg_id_t et al. */ +#include <sys/types.h> /* For pid_t and uid_t. */ + +/* A string identifying this release of the GNU Hurd. Our + interpretation of the term "release" is that it refers to a set of + server interface definitions. A "version" in Posix terminology is + a distribution of the Hurd; there may be more than one distribution + without changing the release number. */ +#define HURD_RELEASE "0.0" + + +/* Simple type declarations */ + +/* These types identify certain kinds of ports used by the Hurd. */ +typedef mach_port_t file_t; +typedef mach_port_t fsys_t; +typedef mach_port_t io_t; +typedef mach_port_t process_t; +typedef mach_port_t auth_t; +typedef mach_port_t socket_t; +typedef mach_port_t pf_t; /* Protocol family */ +typedef mach_port_t addr_port_t; +typedef mach_port_t startup_t; +typedef mach_port_t fs_notify_t; +typedef mach_port_t exec_startup_t; +typedef mach_port_t interrupt_t; +typedef mach_port_t proccoll_t; +typedef mach_port_t ctty_t; + +#include <errno.h> /* Defines `error_t'. */ + +/* These names exist only because of MiG deficiencies. + You should not use them in C source; use the normal C types instead. */ +typedef char *data_t; +typedef const char *const_data_t; +typedef char string_t [1024]; +typedef int *intarray_t; +typedef const int *const_intarray_t; +typedef int *fd_mask_t; +typedef const int *const_fd_mask_t; +typedef mach_port_t *portarray_t; +typedef const mach_port_t *const_portarray_t; +typedef pid_t *pidarray_t; +typedef const pid_t *const_pidarray_t; +typedef uid_t *idarray_t; +typedef const uid_t *const_idarray_t; +#if 0 +typedef __loff_t *off_array_t; +typedef const __loff_t *const_off_array_t; +#endif +typedef struct rusage rusage_t; +typedef struct flock flock_t; +typedef struct utsname utsname_t; +#if _FILE_OFFSET_BITS == 64 +typedef struct stat io_statbuf_t; +typedef struct statfs fsys_statfsbuf_t; +#else +typedef struct stat64 io_statbuf_t; +typedef struct statfs64 fsys_statfsbuf_t; +#endif +typedef struct timespec timespec_t; + + +/* Parameters and flags in RPC calls */ + +/* Many such parameters and flags are also defined in various libc + headers. */ + +/* Bits for flags in fs.defs:file_exec_paths and exec.defs:exec_* calls: */ +#define EXEC_NEWTASK 0x00000001 /* Create new task; kill old one. */ +#define EXEC_SECURE 0x00000002 /* Use secure values of portarray, etc. */ +#define EXEC_DEFAULTS 0x00000004 /* Use defaults for unspecified ports. */ +#define EXEC_SIGTRAP 0x00000008 /* Simulate SIGTRAP on startup. */ +/* This flag is passed through by the exec server but not examined by it. */ +#define EXEC_STACK_ARGS 0x00000010 /* Use arguments from stack, not RPC. */ + +/* Bits for flags in fs.defs:file_set_translator call: */ +#define FS_TRANS_FORCE 0x00000001 /* Must use translator(no sht circuit) */ +#define FS_TRANS_EXCL 0x00000002 /* Don't do it if already translated. */ +#define FS_TRANS_SET 0x00000004 /* Set or clear translator */ +#define FS_TRANS_ORPHAN 0x00000008 /* Orphan the active translator. */ + +/* Values for retry field in fs.defs:dir_lookup call: */ +enum retry_type +{ + FS_RETRY_NORMAL = 1, /* Retry normally if retry_name is not null. */ + FS_RETRY_REAUTH = 2, /* Retry after reauthenticating retry port. + Even if the retry name is null, a retry + is still necessary with this code after the + reauthentication is complete. */ + FS_RETRY_MAGICAL = 3, /* Retry string is magical. */ + /* "tty" means controlling tty; + + "fd/%u" means file descriptor N; + + "machtype/..." means replace `machtype' with the numbers in decimal + returned by the user's kernel as the cpu_type (N) and + cpu_subtype (M) (producing N/M/...) and then retry + as for FS_RETRY_NORMAL. + + "/..." means retry "...", but starting from the users root directory. + + "pid/..." means replace `pid' with the PID of the current process in %u + format and then retry as for FS_RETRY_NORMAL. + */ +}; +typedef enum retry_type retry_type; + +/* Types for fs_notify.defs:dir_changed call: */ +enum dir_changed_type +{ + DIR_CHANGED_NULL, /* Always sent first for sync. */ + DIR_CHANGED_NEW, /* Specified name has been added. */ + DIR_CHANGED_UNLINK, /* Specified name has been removed. */ + DIR_CHANGED_RENUMBER, /* Name has been the target of rename. */ +}; +typedef enum dir_changed_type dir_changed_type_t; + +/* Types for fs_notify.defs:file_changed call: */ +enum file_changed_type +{ + FILE_CHANGED_NULL, /* Always sent first for sync. */ + FILE_CHANGED_WRITE, /* File data has been written. */ + FILE_CHANGED_EXTEND, /* File has grown. */ + FILE_CHANGED_TRUNCATE, /* File has been truncated. */ + FILE_CHANGED_META, /* Stat information has changed, and none + of the previous three apply. Not sent + for changes in node times. */ +}; +typedef enum file_changed_type file_changed_type_t; + +/* Select types for io.defs:io_select call: */ +#define SELECT_READ 0x00000001 +#define SELECT_WRITE 0x00000002 +#define SELECT_URG 0x00000004 + +/* Flags for fsys.defs:fsys_goaway. Also, these flags are sent as the + oldtrans_flags in fs.defs:file_set_translator to describe how to + terminate the old translator. */ +#define FSYS_GOAWAY_NOWAIT 0x00000001 /* Return immediately. */ +#define FSYS_GOAWAY_NOSYNC 0x00000002 /* Don't update physical media. */ +#define FSYS_GOAWAY_FORCE 0x00000004 /* Go away despite current users. */ +#define FSYS_GOAWAY_UNLINK 0x00000008 /* Go away only if non-directory. */ +#define FSYS_GOAWAY_RECURSE 0x00000010 /* Shutdown children too. */ + +/* Types of ports the terminal driver can run on top of; + used in term.defs:term_get_bottom_type. */ +enum term_bottom_type +{ + TERM_ON_MACHDEV, + TERM_ON_HURDIO, + TERM_ON_MASTERPTY, +}; + +/* Types of storage, as returned by file_get_storage_info. + + STORAGE_DEVICE is a mach device_t (for random access devices) + STORAGE_HURD_FILE is a hurd file_t (as if a file were mapped) + STORAGE_TASK is a task_t (the storage is in the vm of the task) + STORAGE_MEMORY is a memory object port + STORAGE_ZERO is a fixed-size constant source of zeros + STORAGE_INTERLEAVE is a set of other storage types interleaved at a fixed + interval + STORAGE_CONCAT is a set of other storage types concatenated end-to-end + STORAGE_LAYER is a set of storage types, representing the same address + range; all will be written too, and will be read in turn until one + succeeds + STORAGE_REMAP is a layer on top of another store that remaps its blocks + STORAGE_COPY is a memory snapshot of another store + STORAGE_NETWORK means that the file is stored elsewhere on the + network; all the remaining fields contan type-specific information. + STORAGE_OTHER means none of these apply; and should be used when no + meaningful answer can be given + + The vectors returned by file_get_storage_info encode each of the above + (note that the first int is always the storage type). There are four: + ports, ints, offsets (off_t), and data (char); each type of store uses the + following entries in each vector: + + -type- -ports- -ints- -offsets- -data- -kids- + device DEVICE TY, FL, BS, NR, NL, ML NR * (OFFS, LEN) NL + ML - + file FILE TY, FL, BS, NR, NL, ML NR * (OFFS, LEN) NL + ML - + memory MEMOBJ TY, FL, BS, NR, NL, ML NR * (OFFS, LEN) NL + ML - + task TASK TY, FL, BS, NR, NL, ML NR * (OFFS, LEN) NL + ML - + (the data for the above is a name (incl '\0') and a misc data block) + null - TY, FL SIZE - - + (BS is 1) + ileave - TY, FL, IL, NC - - NC + (BS is the LCM of its children; SIZE is the minimum of theirs * IL) + concat - TY, FL, NC - - NC + (BS is the LCM of its children; SIZE is the sum of theirs) + layer - TY, FL, NC - - NC + (BS is the LCM of its children; SIZE is the minimum of theirs) + remap - TY, FL, NR NR * (OFFS, LEN) - 1 + (BS and SIZE are that of the child) + copy - TY, FL, SIZE - DATA - + (DATA is preceded by padding to the next page boundary, and is + SIZE bytes long itself) + + For ileave, concat, and layer, the children are encoded following the parent. + The first int must always be TY. + + key: TY = type code, FL = flags, BS = block size, NR = num runs, + NL = name len, ML = misc len, NC = num children, + IL = interleave (bytes), SIZE = Size of storage (blocks), + LEN = run length (blocks), OFFS = run offset (blocks), + + The NR * (OFFS, LEN) offsets for some of the types is the set of block + ranges in the underlying address space that, concatenated, make up the + contents of the storage -- for instance, doing file_get_storage_info on a + file may return storage of type STORAGE_DEVICE, and the accompanying block + ranges are the set of blocks on the given device that correspond to that + file. Any OFFS == -1 designates a hole in the address range. Note that + the total size (SIZE) for these types is the sum of their LEN's. + + The optional NAME returned by some types (if NL != 0) is a type specific + name for the same object referenced by the port also returned. E.g.: + device -- The mach device name + file -- The file name (unreliable, as the root may not be the same) + task -- The pid + Unless it is MACH_PORT_NULL, the port should generally be used instead of + trying to regenerate it from the associated name, which is intended more for + printing messages, etc. */ +enum file_storage_class +{ + STORAGE_OTHER, + STORAGE_DEVICE, + STORAGE_HURD_FILE, + STORAGE_NETWORK, + STORAGE_MEMORY, + STORAGE_TASK, + STORAGE_ZERO, + STORAGE_CONCAT, + STORAGE_INTERLEAVE, + STORAGE_LAYER, + STORAGE_REMAP, + STORAGE_COPY, +}; + +/* Flags for the flags word returned by some types . */ +#define STORAGE_MUTATED 0x00000001 /* data as stored is munged from file */ + +/* Data types */ + +#include <mach/task_info.h> +#include <mach/thread_info.h> +#ifndef THREAD_SCHED_INFO +#include <mach/policy.h> +#endif + +/* Flags sent in proc_getprocinfo request. */ +#define PI_FETCH_TASKINFO 0x0001 +#define PI_FETCH_TASKEVENTS 0x0020 +#define PI_FETCH_THREADS 0x0002 +#define PI_FETCH_THREAD_BASIC 0x0004 +#define PI_FETCH_THREAD_SCHED 0x0008 +#define PI_FETCH_THREAD_WAITS 0x0010 + +struct procinfo +{ + int state; + uid_t owner; + pid_t ppid; + pid_t pgrp; + pid_t session; + pid_t logincollection; + int exitstatus; + int sigcode; + + int nthreads; /* size of pi_threadinfos */ + + struct task_basic_info taskinfo; + struct task_events_info taskevents; +#ifdef TASK_SCHED_TIMESHARE_INFO + struct policy_timeshare_base timeshare_base_info; +#endif + struct + { + int died; /* this thread died in the middle of call */ + mach_msg_id_t rpc_block; /* thread is blocked on this RPC */ + struct thread_basic_info pis_bi; +#ifdef THREAD_SCHED_INFO + struct thread_sched_info pis_si; +#else + struct policy_infos pis_pi; +#endif + } threadinfos[0]; +}; +typedef int *procinfo_t; +typedef const int *const_procinfo_t; + +/* Bits in struct procinfo state: */ +#define PI_STOPPED 0x00000001 /* Proc server thinks is stopped. */ +#define PI_EXECED 0x00000002 /* Has called proc_exec. */ +#define PI_WAITING 0x00000004 /* Process is waiting for child to exit */ +#define PI_ORPHAN 0x00000008 /* Process group is orphaned. */ +#define PI_NOMSG 0x00000010 /* Process has no message port. */ +#define PI_SESSLD 0x00000020 /* Session leader. */ +#define PI_NOTOWNED 0x0000040 /* Process has no owner. */ +#define PI_NOPARENT 0x0000080 /* Hasn't identified a parent. */ +#define PI_ZOMBIE 0x00000100 /* Has no associated task. */ +#define PI_TRACED 0x00000200 /* Process is being traced */ +#define PI_GETMSG 0x00000400 /* Process is blocked in proc_getmsgport. */ +#define PI_LOGINLD 0x00000800 /* Process is leader of login collection */ + + +/* Conventions */ + + +/* st_fstype in struct stat and fsys_stb_type in fsys_statfsbuf is one of: */ +#define FSTYPE_UFS 0x00000000 /* 4.x BSD Fast File System */ +#define FSTYPE_NFS 0x00000001 /* Network File System ala Sun */ +#define FSTYPE_GFS 0x00000002 /* GNU file system */ +#define FSTYPE_LFS 0x00000003 /* Logging File System ala Sprite */ +#define FSTYPE_SYSV 0x00000004 /* Old U*x filesystem ala System V */ +#define FSTYPE_FTP 0x00000005 /* Transparent FTP */ +#define FSTYPE_TAR 0x00000006 /* Transparent TAR */ +#define FSTYPE_AR 0x00000007 /* Transparent AR */ +#define FSTYPE_CPIO 0x00000008 /* Transparent CPIO */ +#define FSTYPE_MSLOSS 0x00000009 /* MS-DOS */ +#define FSTYPE_CPM 0x0000000a /* CP/M */ +#define FSTYPE_HFS 0x0000000b /* Don't ask */ +#define FSTYPE_DTFS 0x0000000c /* used by desktop to provide more info */ +#define FSTYPE_GRFS 0x0000000d /* GNU Remote File System */ +#define FSTYPE_TERM 0x0000000e /* GNU Terminal driver */ +#define FSTYPE_DEV 0x0000000f /* GNU Special file server */ +#define FSTYPE_PROC 0x00000010 /* /proc filesystem ala Version 9 */ +#define FSTYPE_IFSOCK 0x00000011 /* PF_LOCAL socket naming point */ +#define FSTYPE_AFS 0x00000012 /* Andrew File System 3.xx */ +#define FSTYPE_DFS 0x00000013 /* Distributed File Sys (OSF) == AFS 4.xx */ +#define FSTYPE_PROC9 0x00000014 /* /proc filesystem ala Plan 9 */ +#define FSTYPE_SOCKET 0x00000015 /* io_t that isn't a file but a socket */ +#define FSTYPE_MISC 0x00000016 /* generic trivfs server */ +#define FSTYPE_EXT2FS 0x00000017 /* Linux filesystem by Remy Card */ +#define FSTYPE_HTTP 0x00000018 /* Transparent HTTP */ +#define FSTYPE_MEMFS 0x00000019 /* In-core filesystem */ +#define FSTYPE_ISO9660 0x0000001a /* ISO9660 */ + +/* Standard port assignments for file_exec_paths and exec_* */ +enum + { + INIT_PORT_CWDIR, + INIT_PORT_CRDIR, + INIT_PORT_AUTH, + INIT_PORT_PROC, + INIT_PORT_CTTYID, + /* If MACH_PORT_NULL is given for the bootstrap port, + the bootstrap port of the old task is used. */ + INIT_PORT_BOOTSTRAP, + INIT_PORT_MAX + }; + +/* Standard ints for file_exec_paths and exec_* */ +enum + { + INIT_UMASK, + INIT_SIGMASK, + INIT_SIGIGN, + INIT_SIGPENDING, + INIT_TRACEMASK, + INIT_INT_MAX, + }; + +#endif // _HURD_TYPES_H diff --git a/vendor/mes-libc/include/gnu/hurd.h b/vendor/mes-libc/include/gnu/hurd.h @@ -0,0 +1,90 @@ +/* + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019,2024 Janneke Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __MES_GNU_HURD_H +#define __MES_GNU_HURD_H + +#define _GNU_SOURCE 1 +#define __USE_GNU 1 + +#include <errno.h> +#include <sys/types.h> + +#ifndef _BITS_TYPES_H +#ifndef _LOFF_T +#define _LOFF_T +typedef off64_t loff_t; +#endif +#endif + +#include <mach/mach_types.h> +#include <mach/message.h> +#include <mach/port.h> + +struct hurd_startup_data + { + int flags; + + mach_port_t *dtable; + mach_msg_type_number_t dtable_count; + + char *argp; + int arg_size; + + char *envp; + int env_size; + + mach_port_t *portarray; + mach_msg_type_number_t portarray_count; + + int *intarray; + mach_msg_type_number_t intarray_count; + + vm_address_t stack_base; + vm_size_t stack_count; + + vm_address_t phdr; + vm_size_t phdr_count; + + vm_address_t user_entry; + }; + +#define _HURD_DTABLE_MAX 1024 +extern mach_port_t _hurd_dtable[_HURD_DTABLE_MAX]; +extern int _hurd_dtable_count; +extern struct hurd_startup_data _hurd_startup_data; + +#define _HURD_ARGV_MAX 1000 +#define _HURD_ENVV_MAX 1000 +extern size_t __argc; +extern char *__argv[_HURD_ARGV_MAX]; +extern char *__envv[_HURD_ENVV_MAX]; + +mach_port_t fd_get (int filedes); +error_t fd_write (mach_port_t port, void const *buffer, size_t *size, loff_t offset); +error_t fd_read (mach_port_t port, void *buffer, size_t *size, loff_t offset); + +#include <sys/stat.h> +#include <gnu/hurd-types.h> + +kern_return_t __dir_lookup (file_t start_dir, string_t file_name, int flags, mode_t mode, retry_type *do_retry, string_t retry_name, mach_port_t *port); +mach_port_t __mach_reply_port (); + +#endif // __MES_GNU_HURD_H diff --git a/vendor/mes-libc/include/gnu/syscall.h b/vendor/mes-libc/include/gnu/syscall.h @@ -0,0 +1,144 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019,2024 Janneke Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __MES_GNU_SYSCALL_H +#define __MES_GNU_SYSCALL_H + +#define _GNU_SOURCE 1 +#define __USE_GNU 1 + +#include <mach/mach_types.h> +#include <mach/port.h> +#include <mach/message.h> +#include <gnu/hurd.h> +#include <gnu/hurd-types.h> + +// mach/mach.defs +enum + { + SYS__task_terminate = 2008, + SYS__vm_allocate = 2021, + SYS__vm_statistics = 2030, + SYS__task_get_special_port = 2058, + }; + +// hurd/fsys.defs +enum + { + SYS__dir_lookup = 20018, + }; + +// hurd/io.defs +enum + { + SYS__io_write = 21000, + SYS__io_read, + }; + +// hurd/process.defs +enum + { + SYS__proc_mark_exit = 24025, + }; + +// hurd/startup.defs +enum + { + SYS__exec_startup_get_info = 30500, + }; + +extern mach_msg_type_t mach_msg_type_int32; +extern mach_msg_type_t mach_msg_type_int64; +extern mach_msg_type_long_t mach_msg_type_pointer; + +struct mach_msg +{ + mach_msg_header_t header; +}; + +struct mach_msg_1 +{ + mach_msg_header_t header; + mach_msg_type_t type_one; int one; +}; + +struct mach_msg_2 +{ + mach_msg_header_t header; + mach_msg_type_t type_one; int one; + mach_msg_type_t type_two; int two; +}; + +struct mach_msg_loff_int +{ + mach_msg_header_t header; + mach_msg_type_t type_one; loff_t one; + mach_msg_type_t type_two; int two; +}; + +struct mach_msg_startup_info +{ + mach_msg_header_t header; + mach_msg_type_t RetCodeType; + kern_return_t RetCode; + mach_msg_type_t user_entryType; + vm_address_t user_entry; + mach_msg_type_t phdrType; + vm_address_t phdr; + mach_msg_type_t phdr_sizeType; + vm_size_t phdr_size; + mach_msg_type_t stack_baseType; + vm_address_t stack_base; + mach_msg_type_t stack_sizeType; + vm_size_t stack_size; + mach_msg_type_t flagsType; + int flags; + mach_msg_type_long_t argvType; + char *argv; + mach_msg_type_long_t envpType; + char *envp; + mach_msg_type_long_t dtableType; + mach_port_t *dtable; + mach_msg_type_long_t portarrayType; + mach_port_t *portarray; + mach_msg_type_long_t intarrayType; + int *intarray; +}; + +kern_return_t __syscall (mach_port_t port, int sys_call); +kern_return_t __syscall2 (mach_port_t port, int sys_call, int one, int two); +kern_return_t __syscall_get (mach_port_t port, int sys_call, mach_msg_header_t *message, size_t size); +kern_return_t __syscall_put (mach_port_t port, int sys_call, mach_msg_header_t *message, size_t size); + +// mach.defs +kern_return_t __task_terminate (mach_port_t task); +kern_return_t __task_get_special_port (mach_port_t task, int which, mach_port_t *port); +kern_return_t __vm_allocate (mach_port_t task, vm_address_t *address, vm_size_t size, boolean_t anywhere); +kern_return_t __vm_statistics (mach_port_t task, vm_statistics_data_t *vm_stats); + +// process.defs +kern_return_t __proc_mark_exit (mach_port_t process, int one, int two); +kern_return_t __exec_startup_get_data (mach_port_t bootstrap, struct hurd_startup_data *data); + +// io.c +kern_return_t __io_read (io_t io, data_t *data, size_t *read, loff_t offset, vm_size_t size); +kern_return_t __io_write (io_t io_object, const_data_t data, size_t size, loff_t offset, vm_size_t *wrote); + +#endif // __MES_GNU_SYSCALL_H diff --git a/vendor/mes-libc/include/gnu/x86/kernel-stat.h b/vendor/mes-libc/include/gnu/x86/kernel-stat.h @@ -0,0 +1,30 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2022,2024 Janneke Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_GNU_X86_KERNEL_STAT_H +#define __MES_GNU_X86_KERNEL_STAT_H 1 + +#include <arch/syscall.h> + +struct stat +{ + mode_t st_mode; +}; + +#endif // __MES_GNU_X86_KERNEL_STAT_H diff --git a/vendor/mes-libc/include/gnu/x86/signal.h b/vendor/mes-libc/include/gnu/x86/signal.h @@ -0,0 +1,90 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#define EBX 0 +#define ECX 1 +#define EDX 2 +#define ESI 3 +#define EDI 4 +#define EBP 5 +#define EAX 6 +#define DS 7 +#define ES 8 +#define FS 9 +#define GS 10 +#define ORIG_EAX 11 +#define EIP 12 +#define CS 13 +#define EFL 14 +#define UESP 15 +#define SS 16 +#define FRAME_SIZE 17 + +/* Type for general register. */ +typedef int greg_t; + +/* Number of general registers. */ +#define NGREG 19 + +/* Container for all general registers. */ +typedef greg_t gregset_t[NGREG]; + +/* Definitions taken from the kernel headers. */ +struct _libc_fpreg +{ + unsigned short int significand[4]; + unsigned short int exponent; +}; + +struct _libc_fpstate +{ + unsigned long int cw; + unsigned long int sw; + unsigned long int tag; + unsigned long int ipoff; + unsigned long int cssel; + unsigned long int dataoff; + unsigned long int datasel; + struct _libc_fpreg _st[8]; + unsigned long int status; +}; + +/* Structure to describe FPU registers. */ +typedef struct _libc_fpstate *fpregset_t; + +typedef struct +{ + gregset_t gregs; + /* Due to Linux's history we have to use a pointer here. The SysV/i386 + ABI requires a struct with the values. */ + fpregset_t fpregs; + unsigned long int oldmask; + unsigned long int cr2; +} mcontext_t; + +/* Userlevel context. */ +typedef struct ucontext +{ + unsigned long int uc_flags; + struct ucontext *uc_link; + stack_t uc_stack; + mcontext_t uc_mcontext; + sigset_t uc_sigmask; + struct _libc_fpstate __fpregs_mem; +} ucontext_t; diff --git a/vendor/mes-libc/include/grp.h b/vendor/mes-libc/include/grp.h @@ -0,0 +1,45 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_GRP_H +#define __MES_GRP_H 1 + +#if SYSTEM_LIBC +#undef __MES_GRP_H +#include_next <grp.h> +#else // ! SYSTEM_LIBC + +#include <sys/types.h> + +struct group +{ + char *gr_name; + gid_t gr_gid; + char **gr_mem; +}; + +struct group *getgrent (void); +void endgrent (void); +void setgrent (void); +struct group *getgrgid (gid_t gid); +struct group *getgrnam (char const *name); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_GRP_H diff --git a/vendor/mes-libc/include/inttypes.h b/vendor/mes-libc/include/inttypes.h @@ -0,0 +1,34 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_INTTYPES_H +#define __MES_INTTYPES_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_INTTYPES_H +#include_next <inttypes.h> +#else // ! SYSTEM_LIBC + +#include <stdint.h> +#endif // ! SYSTEM_LIBC + +#endif // __MES_INTTYPES_H diff --git a/vendor/mes-libc/include/libgen.h b/vendor/mes-libc/include/libgen.h @@ -0,0 +1,34 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_LIBGEN_H +#define __MES_LIBGEN_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_LIBGEN_H +#include_next <libgen.h> + +#else // ! SYSTEM_LIBC +char *dirname (char *); +#endif // ! SYSTEM_LIBC + +#endif // __MES_LIBGEN_H diff --git a/vendor/mes-libc/include/limits.h b/vendor/mes-libc/include/limits.h @@ -0,0 +1,40 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_LIMITS_H +#define __MES_LIMITS_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_LIMITS_H +#include_next <limits.h> + +#else // ! SYSTEM_LIBC + +#include <stdint.h> + +#define NAME_MAX 255 +#define PATH_MAX 512 +#define _POSIX_OPEN_MAX 16 + +#endif // ! SYSTEM_LIBC + +#endif // __MES_LIMITS_H diff --git a/vendor/mes-libc/include/linux/SYSCALLS b/vendor/mes-libc/include/linux/SYSCALLS @@ -0,0 +1,111 @@ +#+COMMENT: -*- org -*- +#+TITLE: Linux System Calls + +|---------------+----------+-----+--------+-----+---------| +| name | old | x86 | x86_64 | arm | riscv64 | +|---------------+----------+-----+--------+-----+---------| +| libc-mini | | | | | | +|---------------+----------+-----+--------+-----+---------| +| exit | | 1 | 60 | 1 | 1 | +| write | | 4 | 1 | 4 | 4 | +|---------------+----------+-----+--------+-----+---------| +| libc | | | | | | +|---------------+----------+-----+--------+-----+---------| +| fork | | 2 | 57 | 2 | 2 | +| read | | 3 | 0 | 3 | 3 | +| open | | 5 | 2 | 5 | 5 | +| waitpid | | 7 | | | | +| wait4 | waitpid | 114 | 61 | 114 | 114 | +| execve | | 11 | 59 | 11 | 11 | +| chmod | | 15 | 90 | 15 | 15 | +| access | | 33 | 21 | 33 | 33 | +| brk | | 45 | 12 | 45 | 45 | +| ioctl | | 54 | 16 | 54 | 54 | +| fsync | | 118 | 74 | 118 | 118 | +| getcwd | | 183 | 79 | 183 | 183 | +| dup | | 41 | 32 | 41 | 41 | +| dup2 | | 63 | 33 | 63 | 63 | +| unlink | | 10 | 87 | 10 | 10 | +| gettimeofday | time | 78 | 96 | 78 | 78 | +| clock_gettime | | 265 | 228 | 263 | 260 | +| time | | 13 | 201 | 13 | | +|---------------+----------+-----+--------+-----+---------| +| libc+tcc | | | | | | +|---------------+----------+-----+--------+-----+---------| +| close | | 6 | 3 | 6 | 6 | +| lseek | | 19 | 8 | 19 | 19 | +| rmdir | | 40 | 84 | 40 | 40 | +| stat | | 106 | 4 | 106 | 106 | +|---------------+----------+-----+--------+-----+---------| +| libc+GNU | | | | | | +|---------------+----------+-----+--------+-----+---------| +| chdir | | 12 | 80 | 12 | 12 | +| link | | 9 | 86 | 9 | 9 | +| getpid | | 20 | 39 | 20 | 20 | +| getuid | | 24 | 102 | 24 | 199 | +| kill | | 37 | 62 | 37 | 37 | +| rename | | 38 | 82 | 38 | 38 | +| mkdir | | 39 | 83 | 39 | 39 | +| pipe | | 42 | 22 | 42 | 42 | +| getgid | | 47 | 104 | 47 | 200 | +| signal | | 48 | | | 48 | +| sigaction | | 67 | | 67 | 67 | +| rt_sigaction | | 174 | 13 | 174 | 174 | +| signal | | 48 | | | 48 | +| fcntl | | 55 | 72 | 55 | 55 | +| getrusage | | 77 | 98 | 77 | 77 | +| lstat | | 107 | 6 | 107 | 107 | +| setitimer | | 104 | 38 | 104 | 104 | +| fstat | | 108 | 5 | 108 | 108 | +| nanosleep | | 162 | 35 | 162 | 162 | +| getdents | | 141 | 78 | 141 | 141 | +|---------------+----------+-----+--------+-----+---------| +| GNU+bash | | | | | | +|---------------+----------+-----+--------+-----+---------| +| setuid | | 23 | 105 | 23 | 213 | +| geteuid | | 49 | 107 | 49 | 201 | +| getegid | | 50 | 108 | 50 | 202 | +| setgid | | 46 | 106 | 46 | 214 | +| getppid | | 64 | 110 | 64 | 64 | +|---------------+----------+-----+--------+-----+---------| +| GNU+make | | | | | | +|---------------+----------+-----+--------+-----+---------| +| sigprocmask | | 126 | | 126 | 126 | +|---------------+----------+-----+--------+-----+---------| +| GNU+tar | | | | | | +|---------------+----------+-----+--------+-----+---------| +| symlink | | 83 | 88 | 83 | 83 | +| readlink | | 85 | 89 | 85 | 85 | +| mknod | | 14 | 133 | 14 | 14 | +|---------------+----------+-----+--------+-----+---------| +| new | | | | | | +|---------------+----------+-----+--------+-----+---------| +| clone | fork | 120 | 56 | 120 | 120 | +| getdents64 | getdents | 220 | 217 | 217 | 220 | +| openat | open | 295 | 257 | 322 | 288 | +| mkdirat | mkdir | 296 | 258 | 323 | 289 | +| mknodat | mknod | 297 | 259 | 324 | 290 | +| unlinkat | rmdir | 301 | 263 | 328 | 294 | +| unlinkat | unlink | 301 | 263 | 328 | 294 | +| renameat | rename | 302 | 264 | 329 | 295 | +| linkat | link | 303 | 265 | 330 | 296 | +| symlinkat | symlink | 304 | 266 | 331 | 297 | +| readlinkat | readlink | 305 | 267 | 332 | 298 | +| fchmodat | chmod | 306 | 268 | 333 | 299 | +| faccessat | access | 307 | 269 | 334 | 300 | +| dup3 | dup2 | 330 | 292 | 358 | 326 | +| pipe2 | pipe | 331 | 293 | 359 | 325 | +|---------------+----------+-----+--------+-----+---------| + +* Sources + +https://github.com/torvalds/linux/blob/v4.19/arch/arm/tools/syscall.tbl +https://github.com/torvalds/linux/blob/v4.19/arch/x86/entry/syscalls/syscall_32.tbl +https://github.com/torvalds/linux/blob/v4.19/arch/x86/entry/syscalls/syscall_64.tbl + +* Legalese +Copyright © 2022 Jan (janneke) Nieuwenhuizen <[[mailto:janneke@gnu.org][janneke@gnu.org]]> + + Copying and distribution of this file, with or without modification, + are permitted in any medium without royalty provided the copyright + notice and this notice are preserved. diff --git a/vendor/mes-libc/include/linux/arm/kernel-stat.h b/vendor/mes-libc/include/linux/arm/kernel-stat.h @@ -0,0 +1,79 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_LINUX_ARM_KERNEL_STAT_H +#define __MES_LINUX_ARM_KERNEL_STAT_H 1 + +// https://github.com/torvalds/linux/blob/master/arch/arm/include/uapi/asm/stat.h + +#include <arch/syscall.h> + +#if __SIZEOF_LONG_LONG__ != 8 + +// *INDENT-OFF* +struct stat +{ + unsigned long st_dev; + unsigned long st_ino; + unsigned short st_mode; + unsigned short st_nlink; + unsigned short st_uid; + unsigned short st_gid; + unsigned long st_rdev; + unsigned long st_size; + unsigned long st_blksize; + unsigned long st_blocks; + unsigned long st_atime; + unsigned long st_atime_usec; + unsigned long st_mtime; + unsigned long st_mtime_usec; + unsigned long st_ctime; + unsigned long st_ctime_usec; + unsigned long __pad0; + unsigned long __pad1; +}; + +#else // __SIZEOF_LONG_LONG__ == 8 + +struct stat +{ + unsigned long long st_dev; + unsigned char __pad0[4]; + unsigned long __st_ino; + unsigned int st_mode; + unsigned int st_nlink; + unsigned long st_uid; + unsigned long st_gid; + unsigned long long st_rdev; + unsigned char __pad3[4]; + long long st_size; + unsigned long st_blksize; + unsigned long long st_blocks; + unsigned long st_atime; + unsigned long st_atime_nsec; + unsigned long st_mtime; + unsigned int st_mtime_nsec; + unsigned long st_ctime; + unsigned long st_ctime_nsec; + unsigned long long st_ino; +}; + +#endif // __SIZEOF_LONG_LONG__ == 8 + +#endif // __MES_LINUX_ARM_KERNEL_STAT_H diff --git a/vendor/mes-libc/include/linux/arm/signal.h b/vendor/mes-libc/include/linux/arm/signal.h @@ -0,0 +1,51 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2024 Ekaitz Zarraga <ekaitz@elenq.tech> + * Copyright © 2024 Janneke Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +// Taken from musl libc (4a16ddf5) + +typedef int greg_t; +typedef int gregset_t[18]; +typedef struct sigcontext +{ + unsigned long trap_no, error_code, oldmask; + unsigned long arm_r0, arm_r1, arm_r2, arm_r3; + unsigned long arm_r4, arm_r5, arm_r6, arm_r7; + unsigned long arm_r8, arm_r9, arm_r10, arm_fp; + unsigned long arm_ip, arm_sp, arm_lr, arm_pc; + unsigned long arm_cpsr, fault_address; +} mcontext_t; + +struct sigaltstack +{ + void *ss_sp; + int ss_flags; + size_t ss_size; +}; + +typedef struct __ucontext +{ + unsigned long uc_flags; + struct __ucontext *uc_link; + stack_t uc_stack; + mcontext_t uc_mcontext; + sigset_t uc_sigmask; + unsigned long long uc_regspace[64]; +} ucontext_t; diff --git a/vendor/mes-libc/include/linux/arm/syscall.h b/vendor/mes-libc/include/linux/arm/syscall.h @@ -0,0 +1,122 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2022,2024 Janneke Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +/* Commentary: + * See https://github.com/torvalds/linux/blob/v4.19/arch/arm/tools/syscall.tbl + * https://github.com/torvalds/linux/raw/v4.19/arch/arm/tools/syscall.tbl + * + * Code: + */ +#ifndef __MES_LINUX_ARM_SYSCALL_H +#define __MES_LINUX_ARM_SYSCALL_H 1 + +/* libc-mini */ +#ifndef SYS_exit +#define SYS_exit 0x01 +#endif +#ifndef SYS_write +#define SYS_write 0x04 +#endif + +/* libc */ +#define SYS_fork 0x02 +#define SYS_read 0x03 +#define SYS_open 0x05 +//#define SYS_waitpid +#define SYS_wait4 0x72 +#define SYS_execve 0x0b +#define SYS_chmod 0x0f +#define SYS_access 0x21 +#define SYS_brk 0x2d +#define SYS_ioctl 0x36 +#define SYS_fsync 0x76 +#define SYS_getcwd 0xb7 +#define SYS_dup 0x29 +#define SYS_dup2 0x3f +#define SYS_unlink 0x0a +#define SYS_gettimeofday 0x4e +#define SYS_clock_gettime 0x107 +#define SYS_newuname 0x7a + +/* libc+tcc */ +#define SYS_close 0x06 +#define SYS_lseek 0x13 +#define SYS_rmdir 0x28 +#define SYS_stat 0x6a + +/* libc+gnu */ +#define SYS_chdir 0x0c +#define SYS_link 0x09 +#define SYS_getpid 0x14 +#define SYS_getuid 0x18 +#define SYS_kill 0x25 +#define SYS_rename 0x26 +#define SYS_mkdir 0x27 +#define SYS_pipe 0x2a +#define SYS_getgid 0x2f +#define SYS_rt_sigaction 0xae +#define SYS_rt_sigreturn 0xad +#define SYS_fcntl 0x37 +#define SYS_getrusage 0x4d +#define SYS_lstat 0x6b +#define SYS_setitimer 0x68 +#define SYS_fstat 0x6c +#define SYS_nanosleep 0xa2 +#define SYS_getdents 0x8d + +/* bash */ +#define SYS_setuid 0x17 +#define SYS_setgid 0x2e +#define SYS_geteuid 0x31 +#define SYS_getegid 0x32 +#define SYS_getppid 0x40 + +/* make+WITH_GLIBC */ +#define SYS_rt_sigprocmask 0xaf + +/* tar */ +#define SYS_symlink 0x53 +#define SYS_readlink 0x55 +#define SYS_mknod 0x0e + +/* gash */ +#define SYS_umask 0x3c +#define SYS_utimensat 0x15c + +#if __SIZEOF_LONG_LONG__ == 8 + +#define SYS_stat64 0xc3 +#define SYS_lstat64 0xc4 +#define SYS_fstat64 0xc5 +#define SYS_fcntl64 0xdd +#define SYS_getdents64 0xdc + +#undef SYS_stat +#define SYS_stat SYS_stat64 + +#undef SYS_lstat +#define SYS_lstat SYS_lstat64 + +#undef SYS_fstat +#define SYS_fstat SYS_fstat64 + +#endif // __SIZEOF_LONG_LONG__ == 8 + +#endif /* __MES_LINUX_ARM_SYSCALL_H */ diff --git a/vendor/mes-libc/include/linux/m2/kernel-stat.h b/vendor/mes-libc/include/linux/m2/kernel-stat.h @@ -0,0 +1,47 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __LINUX_M2_KERNEL_STAT_H +#define __LINUX_M2_KERNEL_STAT_H + +/* https://github.com/torvalds/linux/blob/master/arch/x86/include/uapi/asm/stat.h */ + +/* *INDENT-OFF* */ +struct stat +{ + unsigned st_dev; + unsigned st_ino; + char st_mode[2]; + char st_nlink[2]; + char st_uid[2]; + char st_gid[2]; + unsigned st_rdev; + unsigned st_size; + unsigned st_blksize; + unsigned st_blocks; + unsigned st_atime; + unsigned st_atime_usec; + unsigned st_mtime; + unsigned st_mtime_usec; + unsigned st_ctime; + unsigned st_ctime_usec; + unsigned __pad0; + unsigned __pad1; +}; +#endif /* __LINUX_M2_KERNEL_STAT_H */ diff --git a/vendor/mes-libc/include/linux/riscv32/kernel-stat.h b/vendor/mes-libc/include/linux/riscv32/kernel-stat.h @@ -0,0 +1,46 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_LINUX_RISCV32_KERNEL_STAT_H +#define __MES_LINUX_RISCV32_KERNEL_STAT_H 1 + +// *INDENT-OFF* +struct stat +{ + unsigned long st_dev; + unsigned long st_ino; + unsigned short st_mode; + unsigned short st_nlink; + unsigned short st_uid; + unsigned short st_gid; + unsigned long st_rdev; + long st_size; /* Linux: unsigned long; glibc: off_t (i.e. signed) */ + unsigned long st_blksize; + unsigned long st_blocks; + time_t st_atime; /* Linux: unsigned long; glibc: time_t */ + unsigned long st_atime_usec; + time_t st_mtime; /* Linux: unsigned long; glibc: time_t */ + unsigned long st_mtime_usec; + time_t st_ctime; /* Linux: unsigned long; glibc: time_t */ + unsigned long st_ctime_usec; + unsigned long __foo0; + unsigned long __foo1; +}; + +#endif // __MES_LINUX_RISCV32_KERNEL_STAT_H diff --git a/vendor/mes-libc/include/linux/riscv64/kernel-stat.h b/vendor/mes-libc/include/linux/riscv64/kernel-stat.h @@ -0,0 +1,48 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com> + * Copyright © 2024 Ekaitz Zarraga <ekaitz@elenq.tech> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_LINUX_RISCV64_KERNEL_STAT_H +#define __MES_LINUX_RISCV64_KERNEL_STAT_H 1 + +// *INDENT-OFF* +struct stat +{ + unsigned long st_dev; + unsigned long st_ino; + unsigned int st_mode; + unsigned int st_nlink; + unsigned int st_uid; + unsigned int st_gid; + unsigned long st_rdev; + unsigned long __pad; + long st_size; + int st_blksize; + int __pad2; + unsigned long st_blocks; + time_t st_atime; + unsigned long st_atime_usec; + time_t st_mtime; + unsigned long st_mtime_usec; + time_t st_ctime; + unsigned long st_ctime_usec; + unsigned long __foo0; +}; + +#endif // __MES_LINUX_RISCV64_KERNEL_STAT_H diff --git a/vendor/mes-libc/include/linux/riscv64/signal.h b/vendor/mes-libc/include/linux/riscv64/signal.h @@ -0,0 +1,89 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2024 Ekaitz Zarraga <ekaitz@elenq.tech> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +// Taken from musl libc (4a16ddf5) + +#define REG_PC 0 +#define REG_RA 1 +#define REG_SP 2 +#define REG_TP 4 +#define REG_S0 8 +#define REG_A0 10 + +typedef unsigned long __riscv_mc_gp_state[32]; + +struct __riscv_mc_f_ext_state +{ + unsigned int __f[32]; + unsigned int __fcsr; +}; + +struct __riscv_mc_d_ext_state +{ + unsigned long long __f[32]; + unsigned int __fcsr; +}; + +struct __riscv_mc_q_ext_state +{ + unsigned long long __f[64]; // __attribute__((aligned(16))) + unsigned int __fcsr; + unsigned int __reserved[3]; +}; + +union __riscv_mc_fp_state +{ + struct __riscv_mc_f_ext_state __f; + struct __riscv_mc_d_ext_state __d; + struct __riscv_mc_q_ext_state __q; +}; + +typedef struct mcontext_t +{ + __riscv_mc_gp_state __gregs; + union __riscv_mc_fp_state __fpregs; +} mcontext_t; + +typedef unsigned long greg_t; +typedef unsigned long gregset_t[32]; +typedef union __riscv_mc_fp_state fpregset_t; + +struct sigcontext +{ + gregset_t gregs; + fpregset_t fpregs; +}; + +struct sigaltstack +{ + void *ss_sp; + int ss_flags; + size_t ss_size; +}; + +typedef struct __ucontext +{ + unsigned long uc_flags; + struct __ucontext *uc_link; + stack_t uc_stack; + sigset_t uc_sigmask; + mcontext_t uc_mcontext; +} ucontext_t; + diff --git a/vendor/mes-libc/include/linux/riscv64/syscall.h b/vendor/mes-libc/include/linux/riscv64/syscall.h @@ -0,0 +1,106 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com> + * Copyright © 2023 Andrius Štikonas <andrius@stikonas.eu> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_LINUX_RISCV_SYSCALL_H +#define __MES_LINUX_RISCV_SYSCALL_H 1 + +/** RISC-V uses the asm-generic syscalls (asm-generic/unistd.h) with the + following configuration for 64-bit: + * #define __ARCH_WANT_NEW_STAT + * #define __ARCH_WANT_SET_GET_RLIMIT + * #define __ARCH_WANT_SYS_CLONE3 + */ + +#define MAKESTRING(s) #s +#define MAKESTRING2(s) MAKESTRING (rd_a7 ! ## s addi) +#define RISCV_SYSCALL(s) MAKESTRING2 (s) + +// libc-mini +#ifndef SYS_exit +#define SYS_exit 93 +#endif +#ifndef SYS_write +#define SYS_write 64 +#endif + +// libc +#define SYS_clone 220 +#define SYS_read 63 +#define SYS_openat 56 +#define SYS_wait4 260 +#define SYS_execve 221 +#define SYS_fchmodat 53 +#define SYS_faccessat 48 +#define SYS_brk 214 +#define SYS_ioctl 29 +#define SYS_fsync 82 +#define SYS_newuname 160 + +// libc+tcc +#define SYS_close 57 +#define SYS_lseek 62 +#define SYS_unlinkat 35 +#define SYS_gettimeofday 169 +#define SYS_getcwd 17 + +// libc+gnu + +#define SYS_chdir 49 +#define SYS_linkat 37 +#define SYS_getpid 172 +#define SYS_getuid 174 +#define SYS_kill 129 +#define SYS_renameat2 276 +#define SYS_mkdirat 34 +#define SYS_dup 23 +#define SYS_pipe2 59 +#define SYS_getgid 176 +#define SYS_rt_sigaction 134 +#define SYS_fcntl 25 +#define SYS_dup3 24 +#define SYS_getrusage 165 +#define SYS_newfstatat 79 +#define SYS_setitimer 103 +#define SYS_fstat 80 +#define SYS_nanosleep 101 +#define SYS_getdents64 61 +#define SYS_clock_gettime 113 + +// bash +#define SYS_setuid 146 +#define SYS_geteuid 175 +#define SYS_getegid 177 +#define SYS_setgid 144 +#define SYS_getppid 173 + +// make+POSIX +#define SYS_rt_sigprocmask 135 + +// tar +#define SYS_symlinkat 36 +#define SYS_readlinkat 78 +#define SYS_mknodat 33 + +/* gash */ +#define SYS_umask 166 +#define SYS_utimensat 88 + +#endif // __MES_LINUX_RISCV_SYSCALL_H diff --git a/vendor/mes-libc/include/linux/syscall.h b/vendor/mes-libc/include/linux/syscall.h @@ -0,0 +1,33 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __MES_SYSCALL_H +#define __MES_SYSCALL_H + +long _sys_call (long sys_call); +long _sys_call1 (long sys_call, long one); +long _sys_call2 (long sys_call, long one, long two); +long _sys_call3 (long sys_call, long one, long two, long three); +long _sys_call4 (long sys_call, long one, long two, long three, long four); +long _sys_call5 (long sys_call, long one, long two, long three, long four, long five); +long _sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six); + +#endif //__MES_SYSCALL_H diff --git a/vendor/mes-libc/include/linux/x86/kernel-stat.h b/vendor/mes-libc/include/linux/x86/kernel-stat.h @@ -0,0 +1,79 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_LINUX_X86_KERNEL_STAT_H +#define __MES_LINUX_X86_KERNEL_STAT_H 1 + +// https://github.com/torvalds/linux/blob/master/arch/x86/include/uapi/asm/stat.h + +#include <arch/syscall.h> + +#if __SIZEOF_LONG_LONG__ != 8 + +// *INDENT-OFF* +struct stat +{ + unsigned long st_dev; + unsigned long st_ino; + unsigned short st_mode; + unsigned short st_nlink; + unsigned short st_uid; + unsigned short st_gid; + unsigned long st_rdev; + unsigned long st_size; + unsigned long st_blksize; + unsigned long st_blocks; + unsigned long st_atime; + unsigned long st_atime_usec; + unsigned long st_mtime; + unsigned long st_mtime_usec; + unsigned long st_ctime; + unsigned long st_ctime_usec; + unsigned long __pad0; + unsigned long __pad1; +}; + +#else // __SIZEOF_LONG_LONG__ == 8 + +struct stat +{ + unsigned long long st_dev; + unsigned char __pad0[4]; + unsigned long __st_ino; + unsigned int st_mode; + unsigned int st_nlink; + unsigned long st_uid; + unsigned long st_gid; + unsigned long long st_rdev; + unsigned char __pad3[4]; + long long st_size; + unsigned long st_blksize; + unsigned long long st_blocks; + unsigned long st_atime; + unsigned long st_atime_nsec; + unsigned long st_mtime; + unsigned int st_mtime_nsec; + unsigned long st_ctime; + unsigned long st_ctime_nsec; + unsigned long long st_ino; +}; + +#endif // __SIZEOF_LONG_LONG__ == 8 + +#endif // __MES_LINUX_X86_KERNEL_STAT_H diff --git a/vendor/mes-libc/include/linux/x86/signal.h b/vendor/mes-libc/include/linux/x86/signal.h @@ -0,0 +1,90 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#define EBX 0 +#define ECX 1 +#define EDX 2 +#define ESI 3 +#define EDI 4 +#define EBP 5 +#define EAX 6 +#define DS 7 +#define ES 8 +#define FS 9 +#define GS 10 +#define ORIG_EAX 11 +#define EIP 12 +#define CS 13 +#define EFL 14 +#define UESP 15 +#define SS 16 +#define FRAME_SIZE 17 + +/* Type for general register. */ +typedef int greg_t; + +/* Number of general registers. */ +#define NGREG 19 + +/* Container for all general registers. */ +typedef greg_t gregset_t[NGREG]; + +/* Definitions taken from the kernel headers. */ +struct _libc_fpreg +{ + unsigned short int significand[4]; + unsigned short int exponent; +}; + +struct _libc_fpstate +{ + unsigned long int cw; + unsigned long int sw; + unsigned long int tag; + unsigned long int ipoff; + unsigned long int cssel; + unsigned long int dataoff; + unsigned long int datasel; + struct _libc_fpreg _st[8]; + unsigned long int status; +}; + +/* Structure to describe FPU registers. */ +typedef struct _libc_fpstate *fpregset_t; + +typedef struct +{ + gregset_t gregs; + /* Due to Linux's history we have to use a pointer here. The SysV/i386 + ABI requires a struct with the values. */ + fpregset_t fpregs; + unsigned long int oldmask; + unsigned long int cr2; +} mcontext_t; + +/* Userlevel context. */ +typedef struct ucontext +{ + unsigned long int uc_flags; + struct ucontext *uc_link; + stack_t uc_stack; + mcontext_t uc_mcontext; + sigset_t uc_sigmask; + struct _libc_fpstate __fpregs_mem; +} ucontext_t; diff --git a/vendor/mes-libc/include/linux/x86/syscall.h b/vendor/mes-libc/include/linux/x86/syscall.h @@ -0,0 +1,124 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2022,2024 Janneke Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +/* Commentary: + * See https://github.com/torvalds/linux/blob/v4.19/arch/x86/entry/syscalls/syscall_32.tbl + * https://github.com/torvalds/linux/raw/v4.19/arch/x86/entry/syscalls/syscall_32.tbl + * + * Code: + */ +#ifndef __MES_LINUX_X86_SYSCALL_H +#define __MES_LINUX_X86_SYSCALL_H 1 + +/* libc-mini */ +#ifndef SYS_exit +#define SYS_exit 0x01 +#endif +#ifndef SYS_write +#define SYS_write 0x04 +#endif + +/* libc */ +#define SYS_fork 0x02 +#define SYS_read 0x03 +#define SYS_open 0x05 +#define SYS_waitpid 0x07 +#define SYS_wait4 0x72 +#define SYS_execve 0x0b +#define SYS_chmod 0x0f +#define SYS_access 0x21 +#define SYS_brk 0x2d +#define SYS_ioctl 0x36 +#define SYS_fsync 0x76 +#define SYS_getcwd 0xb7 +#define SYS_dup 0x29 +#define SYS_dup2 0x3f +#define SYS_unlink 0x0a +#define SYS_gettimeofday 0x4e +#define SYS_clock_gettime 0x109 +#define SYS_time 0x0d +#define SYS_newuname 0x7a + +/* libc+tcc */ +#define SYS_close 0x06 +#define SYS_lseek 0x13 +#define SYS_rmdir 0x28 +#define SYS_stat 0x6a + +/* libc+gnu */ +#define SYS_chdir 0x0c +#define SYS_link 0x09 +#define SYS_getpid 0x14 +#define SYS_getuid 0x18 +#define SYS_kill 0x25 +#define SYS_rename 0x26 +#define SYS_mkdir 0x27 +#define SYS_pipe 0x2a +#define SYS_getgid 0x2f +#define SYS_signal 0x30 +#define SYS_sigaction 0x43 +#define SYS_rt_sigaction 0xae +#define SYS_signal 0x30 +#define SYS_fcntl 0x37 +#define SYS_getrusage 0x4d +#define SYS_lstat 0x6b +#define SYS_setitimer 0x68 +#define SYS_fstat 0x6c +#define SYS_nanosleep 0xa2 +#define SYS_getdents 0x8d + +/* bash */ +#define SYS_setuid 0x17 +#define SYS_geteuid 0x31 +#define SYS_getegid 0x32 +#define SYS_setgid 0x3e +#define SYS_getppid 0x40 + +/* make+POSIX */ +#define SYS_sigprocmask 0x7e + +/* tar */ +#define SYS_symlink 0x53 +#define SYS_readlink 0x55 +#define SYS_mknod 0x0e + +/* gash */ +#define SYS_umask 0x3c +#define SYS_utimensat 0x140 + +#if __SIZEOF_LONG_LONG__ == 8 + +#define SYS_stat64 0xc3 +#define SYS_lstat64 0xc4 +#define SYS_fstat64 0xc5 +#define SYS_fcntl64 0xdd +#define SYS_getdents64 0xdc + +#undef SYS_stat +#define SYS_stat SYS_stat64 + +#undef SYS_lstat +#define SYS_lstat SYS_lstat64 + +#undef SYS_fstat +#define SYS_fstat SYS_fstat64 + +#endif // __SIZEOF_LONG_LONG__ == 8 + +#endif /* __MES_LINUX_X86_SYSCALL_H */ diff --git a/vendor/mes-libc/include/linux/x86_64/kernel-stat.h b/vendor/mes-libc/include/linux/x86_64/kernel-stat.h @@ -0,0 +1,51 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_LINUX_X86_64_KERNEL_STAT_H +#define __MES_LINUX_X86_64_KERNEL_STAT_H 1 + +// https://github.com/torvalds/linux/blob/master/arch/x86/include/uapi/asm/stat.h + +// *INDENT-OFF* +struct stat +{ + unsigned long st_dev; + unsigned long st_ino; + unsigned long st_nlink; + unsigned int st_mode; + unsigned int st_uid; + unsigned int st_gid; + unsigned int __pad0; + unsigned long st_rdev; + long st_size; + long st_blksize; + long st_blocks; + unsigned long st_atime; + unsigned long st_atime_nsec; + unsigned long st_mtime; + unsigned long st_mtime_nsec; + unsigned long st_ctime; + unsigned long st_ctime_nsec; + unsigned long __pad1; + unsigned long __pad2; + unsigned long __pad3; + unsigned long __pad4; +}; + +#endif // __MES_LINUX_X86_64_KERNEL_STAT_H diff --git a/vendor/mes-libc/include/linux/x86_64/signal.h b/vendor/mes-libc/include/linux/x86_64/signal.h @@ -0,0 +1,102 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2024 Ekaitz Zarraga <ekaitz@elenq.tech> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +// Taken from musl libc (4a16ddf5) and simplified + +#define REG_R8 0 +#define REG_R9 1 +#define REG_R10 2 +#define REG_R11 3 +#define REG_R12 4 +#define REG_R13 5 +#define REG_R14 6 +#define REG_R15 7 +#define REG_RDI 8 +#define REG_RSI 9 +#define REG_RBP 10 +#define REG_RBX 11 +#define REG_RDX 12 +#define REG_RAX 13 +#define REG_RCX 14 +#define REG_RSP 15 +#define REG_RIP 16 +#define REG_EFL 17 +#define REG_CSGSFS 18 +#define REG_ERR 19 +#define REG_TRAPNO 20 +#define REG_OLDMASK 21 +#define REG_CR2 22 + +typedef long long greg_t; +typedef long long gregset_t[23]; + +struct __st +{ + unsigned short significand[4], exponent, padding[3]; +}; + +struct _xmm +{ + unsigned element[4]; +}; + +typedef struct _fpstate +{ + unsigned short cwd, swd, ftw, fop; + unsigned long long rip, rdp; + unsigned mxcsr, mxcr_mask; + struct __st _st[8]; + struct _xmm _xmm[16]; + unsigned padding[24]; +} *fpregset_t; + +struct sigcontext +{ + unsigned long r8, r9, r10, r11, r12, r13, r14, r15; + unsigned long rdi, rsi, rbp, rbx, rdx, rax, rcx, rsp, rip, eflags; + unsigned short cs, gs, fs, __pad0; + unsigned long err, trapno, oldmask, cr2; + struct _fpstate *fpstate; + unsigned long __reserved1[8]; +}; + +typedef struct +{ + gregset_t gregs; + fpregset_t fpregs; + unsigned long long __reserved1[8]; +} mcontext_t; + +struct sigaltstack +{ + void *ss_sp; + int ss_flags; + size_t ss_size; +}; + +typedef struct __ucontext +{ + unsigned long uc_flags; + struct __ucontext *uc_link; + stack_t uc_stack; + mcontext_t uc_mcontext; + sigset_t uc_sigmask; + unsigned long __fpregs_mem[64]; +} ucontext_t; diff --git a/vendor/mes-libc/include/linux/x86_64/syscall.h b/vendor/mes-libc/include/linux/x86_64/syscall.h @@ -0,0 +1,104 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2024 Andrius Štikonas <andrius@stikonas.eu> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +/* Commentary: + * See https://github.com/torvalds/linux/blob/v4.19/arch/x86/entry/syscalls/syscall_64.tbl + * https://github.com/torvalds/linux/raw/v4.19/arch/x86/entry/syscalls/syscall_64.tbl + * + * Code: + */ +#ifndef __MES_LINUX_X86_64_SYSCALL_H +#define __MES_LINUX_X86_64_SYSCALL_H 1 + +// libc-mini +#ifndef SYS_write +#define SYS_write 0x01 +#endif +#ifndef SYS_exit +#define SYS_exit 0x3c +#endif + +// libc +#define SYS_fork 0x39 +#define SYS_read 0x00 +#define SYS_open 0x02 +//#define SYS_waitpid +#define SYS_wait4 0x3d +#define SYS_execve 0x3b +#define SYS_chmod 0x5a +#define SYS_access 0x15 +#define SYS_brk 0x0c +#define SYS_ioctl 0x10 +#define SYS_fsync 0x4a +#define SYS_getcwd 0x4f +#define SYS_dup 0x20 +#define SYS_dup2 0x21 +#define SYS_unlink 0x57 +#define SYS_gettimeofday 0x60 +#define SYS_clock_gettime 0xe4 +#define SYS_time 0xc9 +#define SYS_newuname 0x3f + +// libc+tcc +#define SYS_close 0x03 +#define SYS_lseek 0x08 +#define SYS_rmdir 0x54 +#define SYS_stat 0x04 + +// libc+gnu +#define SYS_chdir 0x50 +#define SYS_link 0x56 +#define SYS_getpid 0x27 +#define SYS_getuid 0x66 +#define SYS_kill 0x3e +#define SYS_rename 0x52 +#define SYS_mkdir 0x53 +#define SYS_pipe 0x16 +#define SYS_getgid 0x68 +#define SYS_rt_sigaction 0x0d +#define SYS_rt_sigreturn 0x0f +#define SYS_fcntl 0x48 +#define SYS_getrusage 0x62 +#define SYS_lstat 0x06 +#define SYS_setitimer 0x26 +#define SYS_fstat 0x05 +#define SYS_nanosleep 0x33 +#define SYS_getdents64 0xd9 + +// bash +#define SYS_setuid 0x69 +#define SYS_setgid 0x6a +#define SYS_geteuid 0x6b +#define SYS_getegid 0x6c +#define SYS_getppid 0x6e + +// make+SYSTEM_LIBC +#define SYS_rt_sigprocmask 0x0e + +// tar +#define SYS_symlink 0x58 +#define SYS_readlink 0x59 +#define SYS_mknod 0x85 + +/* gash */ +#define SYS_umask 0x5f +#define SYS_utimensat 0x118 + +#endif // __MES_LINUX_X86_64_SYSCALL_H diff --git a/vendor/mes-libc/include/locale.h b/vendor/mes-libc/include/locale.h @@ -0,0 +1,45 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_LOCALE_H +#define __MES_LOCALE_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_LOCALE_H +#include_next <locale.h> + +#else // ! SYSTEM_LIBC + +// *INDENT-OFF* +#ifndef LC_ALL +#define LC_CTYPE 0 +#define LC_NUMERIC 1 +#define LC_COLLATE 3 +#define LC_ALL 6 +#endif +// *INDENT-ON* + +char *setlocale (int category, char const *locale); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_LOCALE_H diff --git a/vendor/mes-libc/include/m2/types.h b/vendor/mes-libc/include/m2/types.h @@ -0,0 +1,145 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2022,2023 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __M2_TYPES_H +#define __M2_TYPES_H 1 + +// FIXME M2_Planet chokes on -1, even inside #if ! __M2__ +#if __arm__ || __i386__ +#define EOF 0xffffffff +#else +#define EOF 0xffffffffffffffff +#endif + +/* +#ifndef __MES_CLOCK_T +#define __MES_CLOCK_T +#undef clock_t +typedef long clock_t; +#endif +*/ + +#ifndef __MES_DEV_T +#define __MES_DEV_T +#undef dev_t +typedef long dev_t; +#endif + +/* +#if !defined (__MES_FILE_T) && ! defined (_FILE_T) +#define __MES_FILE_T +#define _FILE_T +typedef long FILE; +#endif +*/ + +#ifndef __MES_GID_T +#define __MES_GID_T +#undef gid_t +typedef unsigned gid_t; +#endif + +#ifndef __MES_INO_T +#define __MES_INO_T +#undef ino_t +typedef unsigned ino_t; +#endif + +#if __SIZEOF_LONG_LONG__ == 8 +#ifndef __MES_INO64_T +#define __MES_INO64_T +#undef ino64_t +typedef unsigned ino64_t; +#endif +#endif // __SIZEOF_LONG_LONG__ == 8 + +#if !defined (__MES_INTPTR_T) && !defined (__intptr_t_defined) +#define __MES_INTPTR_T +#define __intptr_t_defined +#undef intptr_t +typedef long intptr_t; +#undef uintptr_t +typedef unsigned uintptr_t; +#endif + +#ifndef __MES_OFF_T +#define __MES_OFF_T +#undef off_t +typedef long off_t; +#endif + +#if __SIZEOF_LONG_LONG__ == 8 +#ifndef __MES_OFF64_T +#define __MES_OFF64_T +#undef off64_t +typedef unsigned off64_t; +#endif +#endif // __SIZEOF_LONG_LONG__ == 8 + +#ifndef __MES_PID_T +#define __MES_PID_T +#undef pid_t +typedef int pid_t; +#endif + +#ifndef __PTRDIFF_T +#define __PTRDIFF_T +#ifndef __MES_PTRDIFF_T +#define __MES_PTRDIFF_T +#undef ptrdiff_t +typedef long ptrdiff_t; +#endif +#endif + +#ifndef __MES_SIGVAL_T +#define __MES_SIGVAL_T +#undef clock_t +typedef long sigval_t; +#endif + +#ifndef __SIZE_T +#define __SIZE_T +#ifndef __MES_SIZE_T +#define __MES_SIZE_T +typedef unsigned size_t; +#endif +#endif + +#ifndef __MES_SSIZE_T +#define __MES_SSIZE_T +#undef ssize_t +typedef long ssize_t; +#endif + +#ifndef __MES_UID_T +#define __MES_UID_T +#undef uid_t +typedef unsigned uid_t; +#endif + +#ifndef __WCHAR_T +#define __WCHAR_T +#ifndef __MES_WCHAR_T +#define __MES_WCHAR_T +#undef wchar_t +typedef int wchar_t; +#endif +#endif + +#endif // __M2_TYPES_H diff --git a/vendor/mes-libc/include/mach/mach-init.h b/vendor/mes-libc/include/mach/mach-init.h @@ -0,0 +1,50 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 1993-2016 Free Software Foundation, Inc. + * Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +/** Commentary: + Taken from GNU C Library + Declarations and macros for the basic Mach things set at startup. + */ + +#ifndef _MACH_INIT_H + +#define _MACH_INIT_H 1 + +#include <mach/mach_types.h> + +/* Return the current task's task port. */ +extern mach_port_t mach_task_self (void); +extern mach_port_t mach_host_self (void); + +/* Kernel page size. */ +extern vm_size_t __vm_page_size; +extern vm_size_t vm_page_size; + +/* Round the address X up to a page boundary. */ +#define round_page(x) \ + ((((vm_offset_t) (x) + __vm_page_size - 1) / __vm_page_size) * \ + __vm_page_size) + +/* Truncate the address X down to a page boundary. */ +#define trunc_page(x) \ + ((((vm_offset_t) (x)) / __vm_page_size) * __vm_page_size) + +#endif /* mach_init.h */ diff --git a/vendor/mes-libc/include/math.h b/vendor/mes-libc/include/math.h @@ -0,0 +1,43 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_MATH_H +#define __MES_MATH_H 1 + +#if SYSTEM_LIBC +#undef __MES_MATH_H +#include_next <math.h> +#else // ! SYSTEM_LIBC + +double atan2 (double y, double x); +double ceil (double x); +double cos (double x); +double exp (double x); +double fabs (double number); +double floor (double x); +double ldexp (double value, int exponent); +double log (double x); +double modf (double value, double *integer_part); +double pow (double base, double power); +double sin (double x); +double sqrt (double x); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_MATH_H diff --git a/vendor/mes-libc/include/memory.h b/vendor/mes-libc/include/memory.h @@ -0,0 +1,36 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_MEMORY_H +#define __MES_MEMORY_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_MEMORY_H +#include_next <memory.h> + +#else // ! SYSTEM_LIBC + +#include <string.h> + +#endif // ! SYSTEM_LIBC + +#endif // __MES_MEMORY_H diff --git a/vendor/mes-libc/include/mes/builtins.h b/vendor/mes-libc/include/mes/builtins.h @@ -0,0 +1,211 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019,2020,2022,2023 Janneke Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2022,2023 Timothy Sample <samplet@ngyro.com> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __MES_BUILTINS_H +#define __MES_BUILTINS_H + +/* src/builtins.c */ +struct scm *make_builtin (struct scm *builtin_type, struct scm *name, struct scm *arity, struct scm *function); +struct scm *builtin_name (struct scm *builtin); +struct scm *builtin_arity (struct scm *builtin); +struct scm *builtin_p (struct scm *x); +struct scm *builtin_printer (struct scm *builtin); +/* src/core.c */ +struct scm *car (struct scm *x); +struct scm *cdr (struct scm *x); +struct scm *list (struct scm *x); +struct scm *null_p (struct scm *x); +struct scm *eq_p (struct scm *x, struct scm *y); +struct scm *values (struct scm *x); +struct scm *acons (struct scm *key, struct scm *value, struct scm *alist); +struct scm *length (struct scm *x); +struct scm *error (struct scm *key, struct scm *x); +struct scm *append2 (struct scm *x, struct scm *y); +struct scm *append_reverse (struct scm *x, struct scm *y); +struct scm *reverse_x_ (struct scm *x, struct scm *t); +struct scm *assq (struct scm *x, struct scm *a); +struct scm *assoc (struct scm *x, struct scm *a); +/* src/display.c */ +struct scm *display_ (struct scm *x); +struct scm *display_error_ (struct scm *x); +struct scm *display_port_ (struct scm *x, struct scm *p); +struct scm *write_ (struct scm *x); +struct scm *write_error_ (struct scm *x); +struct scm *write_port_ (struct scm *x, struct scm *p); +/* src/eval-apply.c */ +struct scm *pairlis (struct scm *x, struct scm *y, struct scm *a); +struct scm *set_car_x (struct scm *x, struct scm *e); +struct scm *set_cdr_x (struct scm *x, struct scm *e); +struct scm *add_formals (struct scm *formals, struct scm *x); +struct scm *eval_apply (); +struct scm *primitive_load (struct scm *filename); +struct scm *make_binding (struct scm *name, struct scm *variable); +/* src/gc.c */ +struct scm *gc_stats (); +struct scm *cons (struct scm *x, struct scm *y); +struct scm *gc_check (); +struct scm *gc (); +/* src/hash.c */ +struct scm *hashq (struct scm *x, struct scm *size); +struct scm *hash (struct scm *x, struct scm *size); +struct scm *hashq_get_handle (struct scm *table, struct scm *key); +struct scm *hashq_ref_ (struct scm *table, struct scm *key, struct scm *dflt); +struct scm *hash_ref_ (struct scm *table, struct scm *key, struct scm *dflt); +struct scm *hashq_create_handle_x (struct scm *table, struct scm *key, struct scm *init); +struct scm *hash_create_handle_x (struct scm *table, struct scm *key, struct scm *init); +struct scm *hashq_set_x (struct scm *table, struct scm *key, struct scm *value); +struct scm *hash_set_x (struct scm *table, struct scm *key, struct scm *value); +struct scm *hash_remove_x (struct scm *table, struct scm *key); +struct scm *hash_table_printer (struct scm *table); +struct scm *make_hash_table (struct scm *x); +struct scm *hash_buckets (struct scm *table); +struct scm *hash_table_p (struct scm *x); +struct scm *hash_clear_x (struct scm *table); +/* src/lib.c */ +struct scm *type_ (struct scm *x); +struct scm *car_ (struct scm *x); +struct scm *cdr_ (struct scm *x); +struct scm *xassq (struct scm *x, struct scm *a); +struct scm *memq (struct scm *x, struct scm *a); +struct scm *equal2_p (struct scm *a, struct scm *b); +struct scm *last_pair (struct scm *x); +struct scm *pair_p (struct scm *x); +struct scm *char_to_integer (struct scm *x); +struct scm *integer_to_char (struct scm *x); +struct scm *make_bytevector (struct scm *args); +struct scm *bytevector_u8_ref (struct scm *bv, struct scm *k); +struct scm *bytevector_u8_set_x (struct scm *bv, struct scm *k, struct scm *value); +/* src/math.c */ +struct scm *greater_p (struct scm *x); +struct scm *less_p (struct scm *x); +struct scm *is_p (struct scm *x); +struct scm *minus (struct scm *x); +struct scm *plus (struct scm *x); +struct scm *divide (struct scm *x); +struct scm *modulo (struct scm *a, struct scm *b); +struct scm *multiply (struct scm *x); +struct scm *logand (struct scm *x); +struct scm *logior (struct scm *x); +struct scm *lognot (struct scm *x); +struct scm *logxor (struct scm *x); +struct scm *ash (struct scm *n, struct scm *count); +/* src/module.c */ +struct scm *initial_module (); +struct scm *current_module (); +struct scm *set_current_module (struct scm *module); +/* src/posix.c */ +struct scm *abort_ (); +struct scm *exit_ (struct scm *x); +struct scm *peek_byte (); +struct scm *read_byte (); +struct scm *unread_byte (struct scm *i); +struct scm *peek_char (); +struct scm *read_char (struct scm *port); +struct scm *unread_char (struct scm *i); +struct scm *write_char (struct scm *i); +struct scm *write_byte (struct scm *x); +struct scm *getenv_ (struct scm *s); +struct scm *setenv_ (struct scm *s, struct scm *v); +struct scm *access_p (struct scm *file_name, struct scm *mode); +struct scm *current_input_port (); +struct scm *open_ (struct scm *file_name, struct scm *flags); +struct scm *open_input_file (struct scm *file_name); +struct scm *open_input_string (struct scm *string); +struct scm *set_current_input_port (struct scm *port); +struct scm *current_output_port (); +struct scm *current_error_port (); +struct scm *open_output_file (struct scm *x); +struct scm *set_current_output_port (struct scm *port); +struct scm *set_current_error_port (struct scm *port); +struct scm *chmod_ (struct scm *file_name, struct scm *mode); +struct scm *isatty_p (struct scm *port); +struct scm *primitive_fork (); +struct scm *primitive_exit (struct scm *status); +struct scm *execl_ (struct scm *file_name, struct scm *args); +struct scm *execle_ (struct scm *file_name, struct scm *args, struct scm *env); +struct scm *waitpid_ (struct scm *pid, struct scm *options); +struct scm *current_time (); +struct scm *gettimeofday_ (); +struct scm *get_internal_run_time (); +struct scm *getcwd_ (); +struct scm *dup_ (struct scm *port); +struct scm *dup2_ (struct scm *old, struct scm *new); +struct scm *delete_file (struct scm *file_name); +struct scm *uname_ (); +/* src/reader.c */ +struct scm *read_input_file_env_ (struct scm *e, struct scm *a); +struct scm *read_input_file_env (struct scm *a); +struct scm *read_env (struct scm *a); +struct scm *reader_read_sexp (struct scm *c, struct scm *s, struct scm *a); +struct scm *reader_read_character (); +struct scm *reader_read_binary (); +struct scm *reader_read_octal (); +struct scm *reader_read_hex (); +struct scm *reader_read_string (); +/* src/stack.c */ +struct scm *frame_printer (struct scm *frame); +struct scm *make_stack (struct scm *stack); +struct scm *stack_length (struct scm *stack); +struct scm *stack_ref (struct scm *stack, struct scm *index); +/* src/string.c */ +struct scm *string_equal_p (struct scm *a, struct scm *b); +struct scm *symbol_to_string (struct scm *symbol); +struct scm *symbol_to_keyword (struct scm *symbol); +struct scm *keyword_to_string (struct scm *keyword); +struct scm *string_to_symbol (struct scm *string); +struct scm *make_symbol (struct scm *string); +struct scm *string_to_list (struct scm *string); +struct scm *list_to_string (struct scm *list); +struct scm *read_string (struct scm *port); +struct scm *string_append (struct scm *x); +struct scm *string_length (struct scm *string); +struct scm *string_ref (struct scm *str, struct scm *k); +struct scm *string_set_x (struct scm *str, struct scm *k, struct scm *c); +/* src/struct.c */ +struct scm *make_struct (struct scm *type, struct scm *fields, struct scm *printer); +struct scm *struct_length (struct scm *x); +struct scm *struct_ref (struct scm *x, struct scm *i); +struct scm *struct_set_x (struct scm *x, struct scm *i, struct scm *e); +/* src/variable.c */ +struct scm *make_variable (struct scm *var); +struct scm *variable_p (struct scm *x); +struct scm *variable_ref (struct scm *var); +struct scm *variable_set_x (struct scm *var, struct scm *value); +struct scm *variable_printer (struct scm *var); +/* src/vector.c */ +struct scm *make_vector (struct scm *x); +struct scm *vector_length (struct scm *x); +struct scm *vector_ref (struct scm *x, struct scm *i); +struct scm *vector_entry (struct scm *x); +struct scm *vector_set_x (struct scm *x, struct scm *i, struct scm *e); +struct scm *list_to_vector (struct scm *x); +struct scm *vector_to_list (struct scm *v); + +/* This is a conditional compilation hack for M2-Planet in bootstrap + mode. The following file will not be included in the M2-Planet build + of Mes, as M2-Planet will ignore the preprocessor directive. Other + builds of Mes will include it. The code in the file relies on system + interfaces supported by MesCC but not M2-Planet. Note that we use + the full include path here, as otherwise NYACC can't find it when + this file is included from elsewhere (possibly a bug). */ +#include "mes/mescc-builtins.h" + +#endif /* __MES_BUILTINS_H */ diff --git a/vendor/mes-libc/include/mes/cc.h b/vendor/mes-libc/include/mes/cc.h @@ -0,0 +1,42 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __MES_CC_H +#define __MES_CC_H + +typedef struct scm* SCM; + +#if __MESC__ +typedef long FUNCTION; +typedef long function0_t; +typedef long function1_t; +typedef long function2_t; +typedef long function3_t; +typedef long functionn_t; +#else // !__MESC__ +typedef SCM (*FUNCTION) (void); +typedef SCM (*function0_t) (void); +typedef SCM (*function1_t) (SCM); +typedef SCM (*function2_t) (SCM, SCM); +typedef SCM (*function3_t) (SCM, SCM, SCM); +typedef SCM (*functionn_t) (SCM); +#endif // !__MESC__ + +#endif //__MES_CC_H diff --git a/vendor/mes-libc/include/mes/config.h b/vendor/mes-libc/include/mes/config.h @@ -0,0 +1,3 @@ +/* Empty config.h shim. mes/lib-mini.h includes this when HAVE_CONFIG_H + * is set; live-bootstrap and our boot-build-libc.sh both treat it as + * a stub that exists only to satisfy the include. */ diff --git a/vendor/mes-libc/include/mes/constants.h b/vendor/mes-libc/include/mes/constants.h @@ -0,0 +1,59 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __MES_CONSTANTS_H +#define __MES_CONSTANTS_H + +/* Cell types */ + +#define TCHAR 0 + +#define TBYTES 1 +#define TCLOSURE 2 +#define TCONTINUATION 3 +#define TKEYWORD 4 +#define TMACRO 5 +#define TNUMBER 6 +#define TPAIR 7 +#define TPORT 8 +#define TREF 9 +#define TSPECIAL 10 +#define TSTRING 11 +#define TSTRUCT 12 +#define TSYMBOL 13 +#define TVALUES 14 +#define TBINDING 15 +#define TVECTOR 16 +#define TBROKEN_HEART 17 + +/* Struct types */ + +#define STRUCT_TYPE 0 +#define STRUCT_PRINTER 1 + +#define GC_FRAME_SIZE 5 +#define GC_FRAME_PROCEDURE 4 + +#define MODULE_OBARRAY 3 +#define MODULE_USES 4 +#define MODULE_BINDER 5 +#define MODULE_EVAL_CLOSURE 6 + +#endif /* __MES_CONSTANTS_H */ diff --git a/vendor/mes-libc/include/mes/lib-cc.h b/vendor/mes-libc/include/mes/lib-cc.h @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_LIB_CC_H +#define __MES_LIB_CC_H + +#define EOF -1 + +#if __TINYC__ || SYSTEM_LIBC +#define __raise(x) -1 +#endif + +#endif //__MES_LIB_CC_H diff --git a/vendor/mes-libc/include/mes/lib-mini.h b/vendor/mes-libc/include/mes/lib-mini.h @@ -0,0 +1,116 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2020,2022,2023,2025 Janneke Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __MES_LIB_MINI_H +#define __MES_LIB_MINI_H + +#if HAVE_CONFIG_H +#include <mes/config.h> +#endif + +#ifndef STDIN +#define STDIN 0 +#endif + +#ifndef STDOUT +#define STDOUT 1 +#endif + +#ifndef STDERR +#define STDERR 2 +#endif + +/* M2-Planet does not support pointer arithmetic. Explicitly compensate + for that by multiplying with M2_PTR_SIZE when using (char) + pointers. */ +#if __M2__ +#define M2_PTR_SIZE sizeof (void*) +#else +#define M2_PTR_SIZE 1 +#endif + +extern char **environ; +extern int __stdin; +extern int __stdout; +extern int __stderr; + +void __init_io (); +int eputs (char const *s); +int puts (char const *s); +int oputs (char const *s); + +#if SYSTEM_LIBC + +#include <stdlib.h> +#include <sys/types.h> +#include <unistd.h> + +#else //!SYSTEM_LIBC + +#ifndef _SIZE_T +#define _SIZE_T +#ifndef __SIZE_T +#define __SIZE_T +#ifndef __MES_SIZE_T +#define __MES_SIZE_T +#undef size_t +#if __M2__ +typedef unsigned size_t; +#else +typedef unsigned long size_t; +#endif +#endif +#endif +#endif + +#ifndef _SSIZE_T +#define _SSIZE_T +#ifndef __SSIZE_T +#define __SSIZE_T +#ifndef __MES_SSIZE_T +#define __MES_SSIZE_T +#undef ssize_t +#if __i386__ +typedef int ssize_t; +#else +typedef long ssize_t; +#endif +#endif +#endif +#endif + +#ifndef __MES_ERRNO_T +#define __MES_ERRNO_T 1 +typedef int error_t; +extern int errno; +#endif // !__MES_ERRNO_T + +#if !__M2__ +extern void (*__call_at_exit) (void); +#endif + +void _exit (int status); +void exit (int status); +size_t strlen (char const *s); +ssize_t _write (); +ssize_t write (int filedes, void const *buffer, size_t size); +#endif // !SYSTEM_LIBC + +#endif //__MES_LIB_MINI_H diff --git a/vendor/mes-libc/include/mes/lib.h b/vendor/mes-libc/include/mes/lib.h @@ -0,0 +1,93 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2023 Timothy Sample <samplet@ngyro.com> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __MES_LIB_H +#define __MES_LIB_H + +#include <mes/lib-mini.h> +#include <mes/lib-cc.h> + +#define __FILEDES_MAX 4096 +extern char *__brk; + +char *cast_intp_to_charp (int const *i); +char *cast_long_to_charp (long i); +long cast_charp_to_long (char const *); +long cast_int_to_long (int i); +long cast_voidp_to_long (void const *); + +int __mes_debug (); +void __ungetc_init (); +void __ungetc_clear (int filedes); +void __ungetc_set (int filedes, int c); +int __ungetc_p (int filedes); +long abtol (char const **p, int base); +char *itoa (int number); +char *ltoa (long number); +char *ltoab (long x, int base); +char *ntoab (long number, unsigned base, int signed_p); +char *utoa (unsigned number); +int eputc (int c); +int fdgetc (int fd); +char * fdgets (char *s, int count, int fd); +int fdputc (int c, int fd); +int fdputs (char const *s, int fd); +int fdungetc (int c, int fd); +char *_getcwd (char *buffer, size_t size); +int ioctl3 (int filedes, size_t command, long data); +int isnumber (int c, int base); +int mes_open (char const *file_name, int flags, int mask); +int _open2 (char const *file_name, int flags); +int _open3 (char const *file_name, int flags, int mask); +int oputc (int c); +int oputs (char const *s); +char *search_path (char const *file_name); +ssize_t _read (int fd, void *buffer, size_t size); +void assert_msg (int check, char *msg); + +long __mesabi_imod (long a, long b); +long __mesabi_idiv (long a, long b); +void *__memcpy (void *dest, void const *src, size_t n); +void *__memmove (void *dest, void const *src, size_t n); +void *__memset (void *s, int c, size_t n); + +#if !SYSTEM_LIBC +void __assert_fail (char const *s, char const *file, unsigned line, + char const *function); +ssize_t __buffered_read (int filedes, void *buffer, size_t size); +size_t __buffered_read_clear (int filedes); +long brk (void *addr); +#ifndef __raise +int __raise (int signal); +#endif +#endif // !SYSTEM_LIBC + +#if !__M2__ +double abtod (char const **p, int base); +char *dtoab (double number, int base, int signed_p); +char *ultoa (unsigned long number); +unsigned long __mesabi_umod (unsigned long a, unsigned long b); +unsigned long __mesabi_udiv (unsigned long a, unsigned long b); +unsigned long __mesabi_uldiv (unsigned long a, unsigned long b, + unsigned long *remainder); +#endif + +#endif //__MES_LIB_H diff --git a/vendor/mes-libc/include/mes/mes.h b/vendor/mes-libc/include/mes/mes.h @@ -0,0 +1,213 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019,2020,2021,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2022 Timothy Sample <samplet@ngyro.com> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __MES_MES_H +#define __MES_MES_H + +#include <sys/types.h> +#include "mes/cc.h" + +struct scm +{ + long type; + union + { + struct scm *car; + long car_value; + char *bytes; + long length; + struct scm *ref; + struct scm *binding; + struct scm *macro; + long port; + }; + union + { + struct scm *cdr; + long cdr_value; + struct scm *closure; + struct scm *continuation; + char *name; + struct scm *string; + struct scm *structure; + long value; + FUNCTION function; + struct scm *vector; + long lexical_p; /* for bindings */ + }; +}; + +/* M2-Planet does not support pointer arithmetic. Explicitly compensate + for that by multiplying with M2_CELL_SIZE when using cell + pointers. */ +#if __M2__ +#define M2_CELL_SIZE sizeof (struct scm) +#else +#define M2_CELL_SIZE 1 +#endif + +/* mes */ +extern char *g_datadir; +extern int g_debug; +extern char *g_buf; +extern int g_continuations; +extern struct scm *g_symbols; +extern struct scm *g_symbol_max; +extern int g_mini; + +/* a/env */ +extern struct scm *R0; +/* param 1 */ +extern struct scm *R1; +/* save 2 */ +extern struct scm *R2; +/* continuation */ +extern struct scm *R3; +/* initial module obarray */ +extern struct scm *M0; +/* current module */ +extern struct scm *M1; +/* macro */ +extern struct scm *g_macros; +extern struct scm *g_ports; + +/* gc */ +extern size_t ARENA_SIZE; +extern size_t MAX_ARENA_SIZE; +extern size_t STACK_SIZE; +extern size_t JAM_SIZE; +extern size_t GC_SAFETY; +extern size_t MAX_STRING; +extern char *g_arena; +extern struct scm *cell_arena; +extern struct scm *cell_zero; + +extern struct scm *g_free; +extern struct scm *g_symbol; + +extern struct scm **g_stack_array; +extern struct scm *g_cells; +extern struct scm *g_news; +extern long g_stack; +extern size_t gc_count; +extern struct timespec *gc_start_time; +extern struct timespec *gc_end_time; +extern size_t gc_time; + +extern char **__execl_c_argv; +extern char **__execle_c_env; +extern char *__open_boot_buf; +extern char *__open_boot_file_name; +extern char *__setenv_buf; +extern char *__reader_read_char_buf; +extern struct timespec *g_start_time; +extern struct timeval *__gettimeofday_time; +extern struct timespec *__get_internal_run_time_ts; +extern struct utsname *__uts; + +extern struct scm *scm_hash_table_type; +extern struct scm *scm_variable_type; + +struct scm *cast_charp_to_scmp (char const *i); +struct scm **cast_charp_to_scmpp (char const *i); +char *cast_voidp_to_charp (void const *i); +long cast_scmp_to_long (struct scm *i); +char *cast_scmp_to_charp (struct scm *i); + +struct scm *alloc (long n); +struct scm *apply (struct scm *f, struct scm *x, struct scm *a); +struct scm *apply_builtin (struct scm *fn, struct scm *x); +struct scm *apply_builtin0 (struct scm *fn); +struct scm *apply_builtin1 (struct scm *fn, struct scm *x); +struct scm *apply_builtin2 (struct scm *fn, struct scm *x, struct scm *y); +struct scm *apply_builtin3 (struct scm *fn, struct scm *x, struct scm *y, struct scm *z); +struct scm *builtin_name (struct scm *builtin); +struct scm *cstring_to_list (char const *s); +struct scm *cstring_to_symbol (char const *s); +struct scm *cell_ref (struct scm *cell, long index); +struct scm *current_module_variable (struct scm *name, struct scm *define_p); +struct scm *standard_eval_closure (struct scm *name, struct scm *define_p); +struct scm *standard_interface_eval_closure (struct scm *name, struct scm *define_p); +struct scm *module_make_local_var_x (struct scm *module, struct scm *name); +struct scm *module_variable (struct scm *module, struct scm *name); +struct scm *fdisplay_ (struct scm *, int, int); +struct scm *init_symbols (); +struct scm *init_time (struct scm *a); +struct scm *lookup_binding (struct scm *name, struct scm *define_p); +struct scm *lookup_value (struct scm *name); +struct scm *make_builtin_type (); +struct scm *make_bytes (size_t length); +struct scm *make_cell (long type, struct scm *car, struct scm *cdr); +struct scm *make_pointer_cell (long type, long car, void *cdr); +struct scm *make_value_cell (long type, long car, long cdr); +struct scm *make_char (int n); +struct scm *make_continuation (long n); +struct scm *make_hash_table_ (long size); +struct scm *make_hash_table_type (); +struct scm *make_initial_module (struct scm *a); +struct scm *make_macro (struct scm *name, struct scm *x); +struct scm *make_number (long n); +struct scm *make_ref (struct scm *x); +struct scm *make_string (char const *s, size_t length); +struct scm *make_string0 (char const *s); +struct scm *make_string_port (struct scm *x); +struct scm *make_variable_type (); +struct scm *make_vector_ (long k, struct scm *e); +struct scm *mes_builtins (struct scm *a); +struct scm *push_cc (struct scm *p1, struct scm *p2, struct scm *a, struct scm *c); +struct scm *set_x (struct scm *x, struct scm *e, int define_p); +struct scm *struct_ref_ (struct scm *x, long i); +struct scm *struct_set_x_ (struct scm *x, long i, struct scm *e); +struct scm *vector_ref_ (struct scm *x, long i); +struct scm *vector_set_x_ (struct scm *x, long i, struct scm *e); +FUNCTION builtin_function (struct scm *builtin); +void assert_num (long pos, struct scm *x); +void assert_range (int assert, long x); +void assert_struct (long pos, struct scm *x); +#if 0 +void assert_type (long type, char const *name_name, struct scm *x) +#endif +char *cell_bytes (struct scm *x); +int peekchar (); +int readchar (); +int unreadchar (); +long gc_free (); +long length__ (struct scm *x); +size_t bytes_cells (size_t length); +void assert_max_string (size_t i, char const *msg, char const *string); +void assert_msg (int check, char *msg); +void assert_number (char const *name, struct scm *x); +void copy_cell (struct scm *to, struct scm *from); +void gc_ (); +void gc_dump_arena (struct scm *cells, long size); +void gc_init (); +void gc_peek_frame (); +void gc_pop_frame (); +void gc_push_frame (); +void gc_stats_ (char const* where); +void init_symbols_ (); +long seconds_and_nanoseconds_to_long (long s, long ns); + +#include "mes/builtins.h" +#include "mes/constants.h" +#include "mes/symbols.h" + +#endif /* __MES_MES_H */ diff --git a/vendor/mes-libc/include/mes/mescc-builtins.h b/vendor/mes-libc/include/mes/mescc-builtins.h @@ -0,0 +1,40 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2022,2023 Timothy Sample <samplet@ngyro.com> + * Copyright © 2023 Janneke Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +struct scm *getpid_ (); +struct scm *environ_ (struct scm *args); +struct scm *opendir_ (struct scm *args); +struct scm *closedir_ (struct scm *args); +struct scm *readdir_ (struct scm *args); +struct scm *pipe_ (); +struct scm *close_port (struct scm *port); +struct scm *seek (struct scm *port, struct scm *offset, struct scm *whence); +struct scm *chdir_ (struct scm *file_name); +struct scm *stat_ (struct scm *args); +struct scm *lstat_ (struct scm *args); +struct scm *rename_file (struct scm *old_name, struct scm *new_name); +struct scm *mkdir_ (struct scm *file_name); +struct scm *rmdir_ (struct scm *file_name); +struct scm *link_ (struct scm *old_name, struct scm *new_name); +struct scm *symlink_ (struct scm *old_name, struct scm *new_name); +struct scm *umask_ (struct scm *mode); +struct scm *utime_ (struct scm *file_name, struct scm *actime, struct scm *modtime); +struct scm *sleep_ (struct scm *seconds); diff --git a/vendor/mes-libc/include/mes/symbols.h b/vendor/mes-libc/include/mes/symbols.h @@ -0,0 +1,141 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019,2021,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __MES_SYMBOLS_H +#define __MES_SYMBOLS_H + +extern struct scm *cell_nil; +extern struct scm *cell_f; +extern struct scm *cell_t; +extern struct scm *cell_dot; +extern struct scm *cell_arrow; +extern struct scm *cell_undefined; +extern struct scm *cell_unspecified; +extern struct scm *cell_closure; +extern struct scm *cell_circular; + +extern struct scm *cell_vm_apply; +extern struct scm *cell_vm_apply2; +extern struct scm *cell_vm_begin; +extern struct scm *cell_vm_begin_eval; +extern struct scm *cell_vm_begin_expand; +extern struct scm *cell_vm_begin_expand_eval; +extern struct scm *cell_vm_begin_expand_macro; +extern struct scm *cell_vm_begin_read_input_file; +extern struct scm *cell_vm_call_with_current_continuation2; +extern struct scm *cell_vm_call_with_values2; +extern struct scm *cell_vm_eval; +extern struct scm *cell_vm_eval2; +extern struct scm *cell_vm_eval_check_func; +extern struct scm *cell_vm_eval_define; +extern struct scm *cell_vm_eval_macro_expand_eval; +extern struct scm *cell_vm_eval_macro_expand_expand; +extern struct scm *cell_vm_eval_set_x; +extern struct scm *cell_vm_evlis; +extern struct scm *cell_vm_evlis2; +extern struct scm *cell_vm_evlis3; +extern struct scm *cell_vm_if; +extern struct scm *cell_vm_if_expr; +extern struct scm *cell_vm_macro_expand; +extern struct scm *cell_vm_macro_expand_car; +extern struct scm *cell_vm_macro_expand_cdr; +extern struct scm *cell_vm_macro_expand_define; +extern struct scm *cell_vm_macro_expand_define_macro; +extern struct scm *cell_vm_macro_expand_lambda; +extern struct scm *cell_vm_macro_expand_set_x; +extern struct scm *cell_vm_return; + +extern struct scm *cell_symbol_lambda; +extern struct scm *cell_symbol_begin; +extern struct scm *cell_symbol_if; +extern struct scm *cell_symbol_quote; +extern struct scm *cell_symbol_define; +extern struct scm *cell_symbol_define_macro; +extern struct scm *cell_symbol_quasiquote; +extern struct scm *cell_symbol_unquote; +extern struct scm *cell_symbol_unquote_splicing; +extern struct scm *cell_symbol_syntax; +extern struct scm *cell_symbol_quasisyntax; +extern struct scm *cell_symbol_unsyntax; +extern struct scm *cell_symbol_unsyntax_splicing; +extern struct scm *cell_symbol_set_x; +extern struct scm *cell_symbol_sc_expand; +extern struct scm *cell_symbol_macro_expand; +extern struct scm *cell_symbol_portable_macro_expand; +extern struct scm *cell_symbol_sc_expander_alist; +extern struct scm *cell_symbol_call_with_values; +extern struct scm *cell_symbol_call_with_current_continuation; +extern struct scm *cell_symbol_current_environment; +extern struct scm *cell_symbol_car; +extern struct scm *cell_symbol_cdr; +extern struct scm *cell_symbol_not_a_number; +extern struct scm *cell_symbol_not_a_pair; +extern struct scm *cell_symbol_system_error; +extern struct scm *cell_symbol_throw; +extern struct scm *cell_symbol_unbound_variable; +extern struct scm *cell_symbol_wrong_number_of_args; +extern struct scm *cell_symbol_wrong_type_arg; +extern struct scm *cell_symbol_buckets; +extern struct scm *cell_symbol_builtin; +extern struct scm *cell_symbol_frame; +extern struct scm *cell_symbol_hashq_table; +extern struct scm *cell_symbol_procedure; +extern struct scm *cell_symbol_record_type; +extern struct scm *cell_symbol_size; +extern struct scm *cell_symbol_stack; +extern struct scm *cell_symbol_argv; +extern struct scm *cell_symbol_mes_datadir; +extern struct scm *cell_symbol_mes_version; +extern struct scm *cell_symbol_internal_time_units_per_second; +extern struct scm *cell_symbol_compiler; +extern struct scm *cell_symbol_arch; +extern struct scm *cell_symbol_variable; +extern struct scm *cell_symbol_standard_eval_closure; +extern struct scm *cell_symbol_standard_interface_eval_closure; +extern struct scm *cell_type_bytes; +extern struct scm *cell_type_char; +extern struct scm *cell_type_closure; +extern struct scm *cell_type_continuation; +extern struct scm *cell_type_function; +extern struct scm *cell_type_keyword; +extern struct scm *cell_type_macro; +extern struct scm *cell_type_number; +extern struct scm *cell_type_pair; +extern struct scm *cell_type_port; +extern struct scm *cell_type_ref; +extern struct scm *cell_type_special; +extern struct scm *cell_type_string; +extern struct scm *cell_type_struct; +extern struct scm *cell_type_symbol; +extern struct scm *cell_type_values; +extern struct scm *cell_type_binding; +extern struct scm *cell_type_vector; +extern struct scm *cell_type_broken_heart; +extern struct scm *cell_symbol_program; +extern struct scm *cell_symbol_test; + +// CONSTANT SYMBOL_MAX 113 +#define SYMBOL_MAX 113 + +#define CELL_UNSPECIFIED 7 + +#define CELL_SYMBOL_RECORD_TYPE 77 + +#endif /* __MES_SYMBOLS_H */ diff --git a/vendor/mes-libc/include/pwd.h b/vendor/mes-libc/include/pwd.h @@ -0,0 +1,46 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_PWD_H +#define __MES_PWD_H 1 + +#if SYSTEM_LIBC +#undef __MES_PWD_H +#include_next <pwd.h> +#else // ! SYSTEM_LIBC + +#include <sys/types.h> + +struct passwd +{ + char *pw_name; + char *pw_passwd; + uid_t pw_uid; + gid_t pw_gid; + char *pw_gecos; + char *pw_dir; + char *pw_shell; +}; + +struct passwd *getpwuid (); + + +#endif // ! SYSTEM_LIBC + +#endif // __MES_PWD_H diff --git a/vendor/mes-libc/include/setjmp.h b/vendor/mes-libc/include/setjmp.h @@ -0,0 +1,69 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org> + * Copyright © 2023 Andrius Štikonas <andrius@stikonas.eu> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SETJMP_H +#define __MES_SETJMP_H 1 + +#if SYSTEM_LIBC +#undef __MES_SETJMP_H +#include_next <setjmp.h> +#else // ! SYSTEM_LIBC + +#if __arm__ +#if __GNUC__ || __TINYC__ +#warning "It is not supported to use mes' setjmp implementation together with GCC. Continuing with best-effort implementation." +typedef struct +{ + long __sp; + long __lr; + long __registers[8]; /* Note: Keep in sync with lib/arm-mes-gcc/setjmp.c */ +} __jmp_buf; +#else +typedef struct +{ + long __fp; + long __lr; + long __sp; +} __jmp_buf; +#endif +#elif __riscv && (__GNUC__ || __TINYC__) +typedef struct +{ + long __sp; + long __lr; + long __registers[14]; /* Note: Keep in sync with lib/riscv64-mes-gcc/setjmp.c */ +} __jmp_buf; +#else +typedef struct +{ + long __bp; + long __pc; + long __sp; +} __jmp_buf; +#endif +typedef __jmp_buf jmp_buf[1]; + +void longjmp (jmp_buf env, int val); +int setjmp (jmp_buf env); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_SETJMP_H diff --git a/vendor/mes-libc/include/signal.h b/vendor/mes-libc/include/signal.h @@ -0,0 +1,193 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SIGNAL_H +#define __MES_SIGNAL_H 1 + +#if SYSTEM_LIBC +#undef __MES_SIGNAL_H +#include_next <signal.h> +#else //! SYSTEM_LIBC + +#define _NSIG 64 + +#define _SIGSET_NITEMS (_NSIG / (8 * sizeof(unsigned long))) + +#if !__M2__ +typedef struct +{ + unsigned long items[_SIGSET_NITEMS]; +} sigset_t; +#endif +typedef long stack_t; + +#include <sys/types.h> + +// *INDENT-OFF* +#define NSIG 30 +#define SIGHUP 1 +#define SIGINT 2 +#define SIGQUIT 3 +#define SIGILL 4 +#define SIGTRAP 5 +#define SIGABRT 6 +#define SIGIOT 6 +#define SIGBUS 7 +#define SIGFPE 8 +#define SIGKILL 9 +#define SIGUSR1 10 +#define SIGSEGV 11 +#define SIGUSR2 12 +#define SIGPIPE 13 +#define SIGALRM 14 +#define SIGTERM 15 +#define SIGSTKFLT 16 +#define SIGCHLD 17 +#define SIGCONT 18 +#define SIGSTOP 19 +#define SIGTSTP 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGURG 23 +#define SIGXCPU 24 +#define SIGXFSZ 25 +#define SIGVTALRM 26 +#define SIGPROF 27 +#define SIGWINCH 28 +#define SIGIO 29 +#define SIGPOLL SIGIO + +#define FPE_INTDIV 1 +#define FPE_INTOVF 2 +#define FPE_FLTDIV 3 +#define FPE_FLTOVF 4 +#define FPE_FLTUND 5 +#define FPE_FLTRES 6 +#define FPE_FLTINV 7 +#define FPE_FLTSUB 8 + +#define SA_NOCLDSTOP 0x00000001 +#define SA_NOCLDWAIT 0x00000002 +#define SA_SIGINFO 0x00000004 +#define SA_RESTORER 0x04000000 +#define SA_ONSTACK 0x08000000 +#define SA_RESTART 0x10000000 +#define SA_NODEFER 0x40000000 +#define SA_RESETHAND 0x80000000 + +#define SA_NOMASK SA_NODEFER +#define SA_ONESHOT SA_RESETHAND + +#if !__M2__ // lacks short, casts +typedef struct siginfo_t +{ + int si_signo; + int si_errno; + int si_code; + int si_trapno; + pid_t si_pid; + uid_t si_uid; + int si_status; + clock_t si_utime; + clock_t si_stime; + sigval_t si_value; + int si_int; + void *si_ptr; + int si_overrun; + int si_timerid; + void *si_addr; + long si_band; + int si_fd; + short si_addr_lsb; + void *si_lower; + void *si_upper; + int si_pkey; + void *si_call_addr; + int si_syscall; + unsigned int si_arch; +} siginfo_t; +// *INDENT-ON* + +#if __M2__ || __MESC__ +typedef long sighandler_t; +#else +typedef void (*sighandler_t) (int); +#endif + +#if __i386__ || __x86_64__ +struct sigaction +{ + union + { + sighandler_t sa_handler; + void (*sa_sigaction) (int signum, siginfo_t *, void *); + }; + unsigned long sa_flags; +#if __x86_64__ + long _foo0; +#endif + sigset_t sa_mask; +#if __x86_64__ + long _foo1[15]; +#endif + //unsigned long sa_flags; // x86? + void (*sa_restorer) (void); +}; +#else /* uapi */ +struct sigaction +{ + union + { + sighandler_t sa_handler; + void (*sa_sigaction) (int signum, siginfo_t *, void *); + }; + unsigned long sa_flags; + void (*sa_restorer) (void); + sigset_t sa_mask; +}; +#endif + +#define SIG_DFL ((sighandler_t)0) +#define SIG_IGN ((sighandler_t)1) +#define SIG_ERR ((sighandler_t)-1) + +#include <arch/signal.h> + +int kill (pid_t pid, int signum); +int raise (int); +int sigaction (int signum, struct sigaction const *act, struct sigaction *oldact); +int sigaddset (sigset_t * set, int signum); +#if __MESC__ +void *signal (int signum, void *action); +#else +sighandler_t signal (int signum, sighandler_t action); +#endif +int sigemptyset (sigset_t * set); +#ifndef SIG_BLOCK +#define SIG_BLOCK 0 +#define SIG_UNBLOCK 1 +#define SIG_SETMASK 2 +#endif +int sigprocmask (int how, sigset_t const *set, sigset_t * oldset); + +#endif // !__M2__ + +#endif //! SYSTEM_LIBC + +#endif // __MES_SIGNAL_H diff --git a/vendor/mes-libc/include/stdarg.h b/vendor/mes-libc/include/stdarg.h @@ -0,0 +1,94 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com> + * Copyright © 2023 Andrius Štikonas <andrius@stikonas.eu> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_STDARG_H +#define __MES_STDARG_H 1 + +#if SYSTEM_LIBC +#undef __MES_STDARG_H +#include_next <stdarg.h> + +#define va_arg8(ap, type) va_arg (ap, type) + +#elif (__GNUC__ || __TINYC__) && __riscv + +// GCC on RISC-V always passes arguments in registers. Implementing +// these macros without the use of built-ins would be very involved. +// TINYCC tries to be GCC compatible in this case. + +#if __TINYC__ +// TINYCC needs some definitions in RISC-V in order to be built +// without it's own code generation tool. +typedef char *__builtin_va_list; +#define __va_reg_size (__riscv_xlen >> 3) +#define _tcc_align(addr, type) \ + (((unsigned long)addr + __alignof__(type) - 1) \ + & -(__alignof__(type))) +#define __builtin_va_arg(ap, type) \ + (*(sizeof (type) > (2*__va_reg_size) \ + ? *(type **)((ap += __va_reg_size) - __va_reg_size) \ + : (ap = (va_list)(_tcc_align (ap, type) \ + + (sizeof (type) + __va_reg_size - 1) \ + & -__va_reg_size), \ + (type *)(ap - ((sizeof (type)+ __va_reg_size - 1) \ + & -__va_reg_size))))) + +#define __builtin_va_end(ap) (void)(ap) +#if !defined (__builtin_va_copy) +#define __builtin_va_copy(dest, src) (dest) = (src) +#endif +#endif // __TINYC__ + +typedef __builtin_va_list va_list; + +#define va_start(v, l) __builtin_va_start (v, l) +#define va_end(v) __builtin_va_end (v) +#define va_arg(v, l) __builtin_va_arg (v, l) +#define va_arg8(ap, type) va_arg (ap, type) +#define va_copy(d, s) __builtin_va_copy (d, s) + +#else // ! SYSTEM_LIBC && ! __riscv + +#include <sys/types.h> + +#if __GNUC__ && __x86_64__ +#define __FOO_VARARGS 1 +#endif + +typedef char *va_list; +#define va_start(ap, last) (void)((ap) = (char*)(&(last)) + sizeof (void*)) +#define va_arg(ap, type) (type)(((long*)((ap) = ((ap) + sizeof (void*))))[-1]) +#define va_align(ap, alignment) ((char*)((((unsigned long) (ap)) + (alignment) - 1) &~ ((alignment) - 1))) +#define va_arg8(ap, type) (type)(((double*)((ap) = (va_align((ap), 8) + sizeof(double))))[-1]) +#define va_end(ap) (void)((ap) = 0) +#define va_copy(dest, src) dest = src + +int vexec (char const *file_name, va_list ap); +int vfprintf (FILE * stream, char const *template, va_list ap); +int vfscanf (FILE * stream, char const *template, va_list ap); +int vprintf (char const *format, va_list ap); +int vsprintf (char *str, char const *format, va_list ap); +int vsnprintf (char *str, size_t size, char const *format, va_list ap); +int vsscanf (char const *s, char const *template, va_list ap); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_STDARG_H diff --git a/vendor/mes-libc/include/stdbool.h b/vendor/mes-libc/include/stdbool.h @@ -0,0 +1,36 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_STDBOOL_H +#define __MES_STDBOOL_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_STDBOOL_H +#include_next <stdbool.h> + +#else // ! SYSTEM_LIBC +typedef int bool; +#define false 0 +#define true 1 +#endif // ! SYSTEM_LIBC + +#endif // __MES_STDBOOL_H diff --git a/vendor/mes-libc/include/stddef.h b/vendor/mes-libc/include/stddef.h @@ -0,0 +1,47 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2021 Danny Milosavljevic <dannym@scratchpost.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_STDDEF_H +#define __MES_STDDEF_H 1 + +#if SYSTEM_LIBC +#undef __MES_STDDEF_H +#include_next <stddef.h> +#else // ! SYSTEM_LIBC + +#include <sys/types.h> +#include <stdint.h> +#include <unistd.h> + +#ifndef offsetof +#if __MESC__ +#define offsetof(type, field) (&((type *)0)->field) +#else // !__MESC__ +#define offsetof(type, field) ((size_t)&((type *)0)->field) +#endif // !__MESC__ +#endif // offsetof + +/* Note: on banana gcc, max_align_t is 16 Byte big instead! */ + +typedef double max_align_t; + +#endif // ! SYSTEM_LIBC + +#endif // __MES_STDDEF_H diff --git a/vendor/mes-libc/include/stdint.h b/vendor/mes-libc/include/stdint.h @@ -0,0 +1,126 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2018 Peter De Wachter <pdewacht@gmail.com> + * Copyright © 2024 Ekaitz Zarraga <ekaitz@elenq.tech> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_STDINT_H +#define __MES_STDINT_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_STDINT_H +#include_next <stdint.h> + +#else // ! SYSTEM_LIBC + +#undef unsigned +#undef uint8_t +#undef int8_t + +#undef uint16_t +#undef int16_t + +#undef uint32_t +#undef int32_t + +#undef uint64_t +#undef int64_t + +#undef uintptr_t +#undef intmax_t +#undef intptr_t +#undef uintmax_t +#undef ptrdiff_t + +typedef unsigned char uint8_t; +typedef signed char int8_t; +typedef unsigned short uint16_t; +typedef short int16_t; +typedef unsigned uint32_t; +typedef int int32_t; +#if __SIZEOF_LONG_LONG__ == 8 +typedef unsigned long long uint64_t; +typedef long long int64_t; +#endif // __SIZEOF_LONG_LONG__ == 8 + +#if __i386__ || __arm__ || __riscv_xlen == 32 +typedef int intmax_t; +typedef unsigned uintmax_t; +#elif __x86_64__ || __riscv_xlen == 64 +typedef long intmax_t; +typedef unsigned long uintmax_t; +#endif + +#include <sys/types.h> + +#define CHAR_BIT 8 +#define SCHAR_MIN (-128) +#define SCHAR_MAX 127 +#define UCHAR_MAX 255 + +/* Check if we are in signed or unsigned char case */ +#if '\xff' > 0 +#define CHAR_MIN 0 +#define CHAR_MAX UCHAR_MAX +#else +#define CHAR_MIN SCHAR_MIN +#define CHAR_MAX SCHAR_MAX +#endif + +#define INT8_MAX 127 +#define INT8_MIN (-INT8_MAX-1) +#define UINT8_MAX 255 + +#define INT16_MAX 32767 +#define INT16_MIN (-INT16_MAX-1) +#define UINT16_MAX 65535 + +#define INT32_MAX 2147483647 +#define INT32_MIN (-INT32_MAX-1) +#define UINT32_MAX 4294967295U + +#define INT64_MAX 9223372036854775807LL +#define INT64_MIN (-INT64_MAX-1) +#define UINT64_MAX 18446744073709551615ULL + +#define INT_MIN -2147483648 +#define INT_MAX 2147483647 +#if __i386__ || __arm__ || __riscv_xlen == 32 +#define LONG_MIN INT_MIN +#define LONG_MAX INT_MAX +#define UINT_MAX UINT32_MAX +#define ULONG_MAX UINT32_MAX +#define LLONG_MIN INT64_MIN +#define LLONG_MAX INT64_MAX +#define SIZE_MAX UINT32_MAX +#elif __x86_64__ || __riscv_xlen == 64 +#define LONG_MIN INT64_MIN +#define LONG_MAX INT64_MAX +#define UINT_MAX UINT32_MAX +#define ULONG_MAX UINT64_MAX +#define LLONG_MIN INT64_MIN +#define LLONG_MAX INT64_MAX +#define SIZE_MAX UINT64_MAX +#endif + +#endif // ! SYSTEM_LIBC + +#endif // __MES_STDINT_H diff --git a/vendor/mes-libc/include/stdio.h b/vendor/mes-libc/include/stdio.h @@ -0,0 +1,99 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_STDIO_H +#define __MES_STDIO_H 1 + +#include <mes/lib.h> + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_STDIO_H +#include_next <stdio.h> + +#else // ! SYSTEM_LIBC + +#ifndef _IOFBF +#define _IOFBF 0 /* Fully buffered. */ +#define _IOLBF 1 /* Line buffered. */ +#define _IONBF 2 /* No buffering. */ +#endif + +#ifndef BUFSIZ +#define BUFSIZ 256 +#endif + +#ifndef L_tmpnam +#define L_tmpnam 100 +#endif + +#include <sys/types.h> + +#define stdin (FILE*)0 +#define stdout (FILE*)1 +#define stderr (FILE*)2 + +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 + +FILE *fdopen (int fd, char const *mode); +FILE *fopen (char const *file_name, char const *mode); +int eputc (int c); +int eputs (char const *s); +int fclose (FILE * stream); +int feof (FILE * stream); +int ferror (FILE * stream); +int fflush (FILE * stream); +int fgetc (FILE * stream); +char *fgets (char *s, int size, FILE * stream); +int fpurge (FILE * stream); +int fputc (int c, FILE * stream); +int fputs (char const *s, FILE * stream); +int fseek (FILE * stream, long offset, int whence); +int getc (FILE * stream); +int getchar (void); +char *getlogin (void); +int putc (int c, FILE * stream); +int putchar (int c); +int puts (char const *s); +int remove (char const *file_name); +int rename (char const *old_name, char const *new_name); +int setvbuf (FILE * stream, char *buf, int mode, size_t size); +int ungetc (int c, FILE * stream); +long ftell (FILE * stream); +size_t fread (void *ptr, size_t size, size_t count, FILE * stream); +size_t freadahead (FILE * fp); +size_t fwrite (void const *ptr, size_t size, size_t count, FILE * stream); +void perror (char const *message); + +#if !__M2__ +int fprintf (FILE * stream, char const *format, ...); +int fscanf (FILE * stream, char const *template, ...); +int printf (char const *format, ...); +int snprintf (char *str, size_t size, char const *format, ...); +int sprintf (char *str, char const *format, ...); +int sscanf (char const *str, char const *format, ...); +#endif // !__M2__ + +#endif // ! SYSTEM_LIBC + +#endif // __MES_STDIO_H diff --git a/vendor/mes-libc/include/stdlib.h b/vendor/mes-libc/include/stdlib.h @@ -0,0 +1,74 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2024 Andrius Štikonas <andrius@stikonas.eu> + * Copyright © 2024 Ekaitz Zarraga <ekaitz@elenq.tech> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_STDLIB_H +#define __MES_STDLIB_H 1 + +#ifndef __MES_COMPARISON_FN_T +#define __MES_COMPARISON_FN_T +typedef int (*comparison_fn_t) (void const *, void const *); +#endif + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_STDLIB_H +#include_next <stdlib.h> +#else // ! SYSTEM_LIBC + +#include <sys/types.h> +#include <alloca.h> + +#define MB_CUR_MAX 1 + +void abort (void); +double atof (char const *s); +int atoi (char const *s); +int atexit (void (*function) (void)); +void *calloc (size_t nmemb, size_t size); +void _exit (int status); +void exit (int status); +void free (void *ptr); +char *getenv (char const *s); +int putenv (char *s); +int setenv (char const *s, char const *v, int overwrite_p); +void unsetenv (char const *name); +void *malloc (size_t); +void qsort (void *base, size_t nmemb, size_t size, int (*compar) (void const *, void const *)); +int rand (void); +void *realloc (void *p, size_t size); +double strtod (char const *string, char **tailptr); +float strtof (char const *string, char **tailptr); +long double strtold (char const *string, char **tailptr); +long strtol (char const *string, char **tailptr, int base); +long long strtoll (char const *string, char **tailptr, int base); +unsigned long strtoul (char const *string, char **tailptr, int base); +unsigned long long strtoull (char const *string, char **tailptr, int base); + +#define EXIT_FAILURE 1 +#define EXIT_SUCCESS 0 + +void *bsearch (void const *key, void const *array, size_t count, size_t size, comparison_fn_t compare); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_STDLIB_H diff --git a/vendor/mes-libc/include/stdnoreturn.h b/vendor/mes-libc/include/stdnoreturn.h @@ -0,0 +1,34 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_STDNORETURN_H +#define __MES_STDNORETURN_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_STDNORETURN_H +#include_next <stdnoreturn.h> + +#else // ! SYSTEM_LIBC +// whut? +#endif // ! SYSTEM_LIBC + +#endif // __MES_STDNORETURN_H diff --git a/vendor/mes-libc/include/string.h b/vendor/mes-libc/include/string.h @@ -0,0 +1,62 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,20225 janneke Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_STRING_H +#define __MES_STRING_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_STRING_H +#include_next <string.h> + +#else // ! SYSTEM_LIBC + +#include <sys/types.h> + +void *memchr (void const *block, int c, size_t size); +void *memcpy (void *dest, void const *src, size_t n); +void *memmove (void *dest, void const *src, size_t n); +void *memset (void *s, int c, size_t n); +int memcmp (void const *s1, void const *s2, size_t n); +void *memmem (void const *haystack, int haystack_len, void const *needle, int needle_len); +char *strcat (char *dest, char const *src); +char *strchr (char const *s, int c); +int strcasecmp (char const *s1, char const *s2); +int strcmp (char const *, char const *); +char *strcpy (char *dest, char const *src); +size_t strcspn (char const *string, char const *stopset); +size_t strlen (char const *); +char *strncat (char *to, char const *from, size_t size); +char *strncpy (char *to, char const *from, size_t size); +int strncmp (char const *, char const *, size_t); +char *strpbrk (char const *string, char const *stopset); +char *strrchr (char const *s, int c); +size_t strspn (char const *string, char const *skipset); +char *strstr (char const *haystack, char const *needle); +char *strlwr (char *string); +char *strupr (char *string); + + +char *strerror (int errnum); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_STRING_H diff --git a/vendor/mes-libc/include/strings.h b/vendor/mes-libc/include/strings.h @@ -0,0 +1,28 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_STRINGS_H +#define __MES_STRINGS_H 1 + +#if SYSTEM_LIBC +#undef __MES_STRINGS_H +#include_next <strings.h> +#endif // (SYSTEM_LIBC) + +#endif // __MES_STRINGS_H diff --git a/vendor/mes-libc/include/sys/cdefs.h b/vendor/mes-libc/include/sys/cdefs.h @@ -0,0 +1,28 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_CDEFS_H +#define __MES_SYS_CDEFS_H 1 + +#if SYSTEM_LIBC +#undef __MES_SYS_CDEFS_H +#include_next <sys/cdefs.h> +#endif // (SYSTEM_LIBC) + +#endif // __MES_SYS_CDEFS_H diff --git a/vendor/mes-libc/include/sys/dir.h b/vendor/mes-libc/include/sys/dir.h @@ -0,0 +1,32 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_DIR_H +#define __MES_SYS_DIR_H 1 + +#if SYSTEM_LIBC +#undef __MES_SYS_DIR_H +#include_next <sys/dir.h> + +#else // ! SYSTEM_LIBC + + +#endif // ! SYSTEM_LIBC + +#endif // __MES_SYS_DIR_H diff --git a/vendor/mes-libc/include/sys/file.h b/vendor/mes-libc/include/sys/file.h @@ -0,0 +1,32 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_FILE_H +#define __MES_SYS_FILE_H 1 + +#if SYSTEM_LIBC +#undef __MES_SYS_FILE_H +#include_next <sys/file.h> + +#else // ! SYSTEM_LIBC + + +#endif // ! SYSTEM_LIBC + +#endif // __MES_SYS_FILE_H diff --git a/vendor/mes-libc/include/sys/ioctl.h b/vendor/mes-libc/include/sys/ioctl.h @@ -0,0 +1,41 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_IOCTL_H +#define __MES_SYS_IOCTL_H 1 + +#if SYSTEM_LIBC +#undef __MES_SYS_IOCTL_H +#include_next <sys/ioctl.h> + +#else // ! SYSTEM_LIBC + +#define TCGETS 0x5401 +#define TCGETA 0x5405 +#if __M2__ +int ioctl (int fd, unsigned request, long data); +int ioctl3 (int fd, unsigned request, long data); +#else +int ioctl (int fd, unsigned long request, ...); +int ioctl3 (int fd, unsigned long request, long data); +#endif + +#endif // ! SYSTEM_LIBC + +#endif // __MES_SYS_IOCTL_H diff --git a/vendor/mes-libc/include/sys/mman.h b/vendor/mes-libc/include/sys/mman.h @@ -0,0 +1,43 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_MMAN_H +#define __MES_SYS_MMAN_H 1 + +#if SYSTEM_LIBC +#undef __MES_SYS_MMAN_H +#include_next <sys/mman.h> +#else // ! SYSTEM_LIBC + +#ifndef __MES_SIZE_T +#define __MES_SIZE_T +typedef unsigned long size_t; +#endif + +#define PROT_NONE 0 +#define PROT_READ 1 +#define PROT_WRITE 2 +#define PROT_EXEC 4 + +int mprotect (void *addr, size_t len, int prot); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_SYS_MMAN_H + diff --git a/vendor/mes-libc/include/sys/param.h b/vendor/mes-libc/include/sys/param.h @@ -0,0 +1,31 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_PARAM_H +#define __MES_SYS_PARAM_H 1 + +#if SYSTEM_LIBC +#undef __MES_SYS_PARAM_H +#include_next <sys/param.h> + +#else // ! SYSTEM_LIBC + +#endif // ! SYSTEM_LIBC + +#endif // __MES_SYS_PARAM_H diff --git a/vendor/mes-libc/include/sys/resource.h b/vendor/mes-libc/include/sys/resource.h @@ -0,0 +1,60 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_RESOURCE_H +#define __MES_SYS_RESOURCE_H 1 + +#if SYSTEM_LIBC +#undef __MES_SYS_RESOURCE_H +#include_next <sys/resource.h> + +#else // ! SYSTEM_LIBC + +#include <sys/time.h> + +struct rusage +{ + struct timeval ru_utime; + struct timeval ru_stime; + long ru_maxrss; + long ru_ixrss; + long ru_idrss; + long ru_isrss; + long ru_minflt; + long ru_majflt; + long ru_nswap; + long ru_inblock; + long ru_oublock; + long ru_msgsnd; + long ru_msgrcv; + long ru_nsignals; + long ru_nvcsw; + long ru_nivcsw; +}; + +#define RUSAGE_SELF 0 +#define RUSAGE_CHILDREN -1 +#define RLIMIT_NOFILE 1024 +#define OPEN_MAX RLIMIT_NOFILE + +int getrusage (int processes, struct rusage *rusage); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_SYS_RESOURCE_H diff --git a/vendor/mes-libc/include/sys/select.h b/vendor/mes-libc/include/sys/select.h @@ -0,0 +1,30 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_SELECT_H +#define __MES_SYS_SELECT_H 1 + +#if SYSTEM_LIBC +#undef __MES_SYS_SELECT_H +#include_next <sys/select.h> +#else //! SYSTEM_LIBC +typedef int fd_set; +#endif //! SYSTEM_LIBC + +#endif // __MES_SYS_SELECT_H diff --git a/vendor/mes-libc/include/sys/stat.h b/vendor/mes-libc/include/sys/stat.h @@ -0,0 +1,82 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2024 Janneke Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2022 Dor Askayo <dor.askayo@gmail.com> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_STAT_H +#define __MES_SYS_STAT_H 1 + +#if SYSTEM_LIBC +#undef __MES_SYS_STAT_H +#include_next <sys/stat.h> + +#else // ! SYSTEM_LIBC + +#include <time.h> +#include <sys/types.h> + +#ifndef __MES_MODE_T +#define __MES_MODE_T +typedef int mode_t; +#endif + +#include <arch/kernel-stat.h> + +int chmod (char const *file_name, mode_t mode); +int fstat (int filedes, struct stat *buf); +int mkdir (char const *file_name, mode_t mode); +int mknod (char const *file_name, mode_t mode, dev_t dev); +int chown (char const *file_name, uid_t owner, gid_t group); +int rmdir (char const *file_name); +int stat (char const *file_name, struct stat *buf); +int lstat (char const *file_name, struct stat *buf); +mode_t umask (mode_t mask); +int utimensat(int dirfd, char const *file_name, + struct timespec const *times, int flags); + +#define S_IFIFO 0010000 +#define S_IFCHR 0020000 +#define S_IFDIR 0040000 +#define S_IFBLK 0060000 +#define S_IFREG 0100000 +#define S_IFLNK 0120000 +#define S_IFMT 0170000 + +#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) + +#define S_IRWXU 00700 +#define S_IXUSR 00100 +#define S_IWUSR 00200 +#define S_IRUSR 00400 + +#define S_ISUID 04000 +#define S_ISGID 02000 +#define S_IXGRP 00010 +#define S_IXOTH 00001 +#define S_IRGRP 00040 +#define S_IROTH 00004 +#define S_IWGRP 00020 +#define S_IWOTH 00002 +#define S_IRWXG 00070 +#define S_IRWXO 00007 + +#endif // ! SYSTEM_LIBC + +#endif // __MES_SYS_STAT_H diff --git a/vendor/mes-libc/include/sys/time.h b/vendor/mes-libc/include/sys/time.h @@ -0,0 +1,56 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_TIME_H +#define __MES_SYS_TIME_H 1 + +#if SYSTEM_LIBC +#undef __MES_SYS_TIME_H +#include_next <sys/time.h> + +#else // ! SYSTEM_LIBC + +struct timeval +{ + long tv_sec; + long tv_usec; +}; + +struct timezone +{ + int tz_minuteswest; + int tz_dsttime; +}; + +struct itimerval +{ + struct timeval it_interval; + struct timeval it_value; +}; + +#define ITIMER_REAL 0 +#define ITIMER_VIRTUAL 1 +#define ITIMER_PROF 2 + +int gettimeofday (struct timeval *tv, struct timezone *tz); +int setitimer (int which, struct itimerval const *new, struct itimerval *old); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_SYS_TIME_H diff --git a/vendor/mes-libc/include/sys/timeb.h b/vendor/mes-libc/include/sys/timeb.h @@ -0,0 +1,28 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_TIMEB_H +#define __MES_SYS_TIMEB_H 1 + +#if SYSTEM_LIBC +#undef __MES_SYS_TIMEB_H +#include_next <sys/timeb.h> +#endif // (SYSTEM_LIBC) + +#endif // __MES_SYS_TIMEB_H diff --git a/vendor/mes-libc/include/sys/times.h b/vendor/mes-libc/include/sys/times.h @@ -0,0 +1,53 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_TIMES_H +#define __MES_SYS_TIMES_H 1 + +#if SYSTEM_LIBC +#undef __MES_SYS_TIMES_H +#include_next <sys/times.h> + +#else // ! SYSTEM_LIBC + +#ifndef __MES_CLOCK_T +#define __MES_CLOCK_T +#undef clock_t +typedef long clock_t; +#endif + +#ifndef CLOCKS_PER_SEC +#define CLOCKS_PER_SEC 1000000 +#endif + +#ifndef HZ +#define HZ 100 +#endif + +struct tms +{ + clock_t tms_utime; + clock_t tms_stime; + clock_t tms_cutime; + clock_t tms_cstime; +}; + +#endif // ! SYSTEM_LIBC + +#endif // __MES_SYS_TIMES_H diff --git a/vendor/mes-libc/include/sys/types.h b/vendor/mes-libc/include/sys/types.h @@ -0,0 +1,174 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_TYPES_H +#define __MES_SYS_TYPES_H 1 + +#include <mes/lib-cc.h> + +#if SYSTEM_LIBC +#undef __MES_SYS_TYPES_H +#include_next <sys/types.h> +#else // ! SYSTEM_LIBC + +#include <endian.h> + +#ifndef __MESCCLIB__ +#define __MESCCLIB__ 15 +#endif + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef __MES_CLOCK_T +#define __MES_CLOCK_T +#undef clock_t +typedef long clock_t; +#endif + +#ifndef __MES_DEV_T +#define __MES_DEV_T +#undef dev_t +typedef long dev_t; +#endif + +#if !defined (__MES_FILE_T) && ! defined (_FILE_T) +#define __MES_FILE_T +#define _FILE_T +typedef long FILE; +#endif + +#ifndef __MES_GID_T +#define __MES_GID_T +#undef gid_t +typedef unsigned gid_t; +#endif + +#ifndef __MES_INO_T +#define __MES_INO_T +#undef ino_t +#if __M2__ +typedef unsigned ino_t; +#else +typedef unsigned long ino_t; +#endif +#endif + +#if __SIZEOF_LONG_LONG__ == 8 +#ifndef __MES_INO64_T +#define __MES_INO64_T +#undef ino64_t +#if __M2__ +typedef unsigned ino64_t; +#else +typedef unsigned long long ino64_t; +#endif +#endif +#endif // __SIZEOF_LONG_LONG__ == 8 + +#if !defined (__MES_INTPTR_T) && !defined (__intptr_t_defined) +#define __MES_INTPTR_T +#define __intptr_t_defined +#undef intptr_t +typedef long intptr_t; +#undef uintptr_t +#if __M2__ +typedef unsigned uintptr_t; +#else +typedef unsigned long uintptr_t; +#endif +#endif + +#ifndef __MES_OFF_T +#define __MES_OFF_T +#undef off_t +typedef long off_t; +#endif + +#if __SIZEOF_LONG_LONG__ == 8 +#ifndef __MES_OFF64_T +#define __MES_OFF64_T +#undef off64_t +#if __M2__ +typedef unsigned off64_t; +#else +typedef unsigned long long off64_t; +#endif +#endif +#endif // __SIZEOF_LONG_LONG__ == 8 + +#ifndef __MES_PID_T +#define __MES_PID_T +#undef pid_t +typedef int pid_t; +#endif + +#ifndef __PTRDIFF_T +#define __PTRDIFF_T +#ifndef __MES_PTRDIFF_T +#define __MES_PTRDIFF_T +#undef ptrdiff_t +typedef long ptrdiff_t; +#endif +#endif + +#ifndef __MES_SIGVAL_T +#define __MES_SIGVAL_T +#undef clock_t +typedef long sigval_t; +#endif + +#ifndef __SIZE_T +#define __SIZE_T +#ifndef __MES_SIZE_T +#define __MES_SIZE_T +#undef size_t +#if __M2__ +typedef unsigned size_t; +#else +typedef unsigned long size_t; +#endif +#endif +#endif + +#ifndef __MES_SSIZE_T +#define __MES_SSIZE_T +#undef ssize_t +typedef long ssize_t; +#endif + +#ifndef __MES_UID_T +#define __MES_UID_T +#undef uid_t +typedef unsigned uid_t; +#endif + +#ifndef __WCHAR_T +#define __WCHAR_T +#ifndef __MES_WCHAR_T +#define __MES_WCHAR_T +#undef wchar_t +typedef int wchar_t; +#endif +#endif + +#endif // ! SYSTEM_LIBC + +#endif // __MES_SYS_TYPES_H diff --git a/vendor/mes-libc/include/sys/ucontext.h b/vendor/mes-libc/include/sys/ucontext.h @@ -0,0 +1,28 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_UCONTEXT_H +#define __MES_SYS_UCONTEXT_H 1 + +#if SYSTEM_LIBC +#undef __MES_SYS_UCONTEXT_H +#include_next <sys/ucontext.h> +#endif // (SYSTEM_LIBC) + +#endif // __MES_SYS_UCONTEXT_H diff --git a/vendor/mes-libc/include/sys/user.h b/vendor/mes-libc/include/sys/user.h @@ -0,0 +1,111 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_USER_H +#define __MES_SYS_USER_H 1 + +#if SYSTEM_LIBC +#undef __MES_SYS_USER_H +#include_next <sys/user.h> + +#else // ! SYSTEM_LIBC + +/* These are the 32-bit x86 structures. */ +struct user_fpregs_struct +{ + long int cwd; + long int swd; + long int twd; + long int fip; + long int fcs; + long int foo; + long int fos; + long int st_space[20]; +}; + +struct user_fpxregs_struct +{ + unsigned short int cwd; + unsigned short int swd; + unsigned short int twd; + unsigned short int fop; + long int fip; + long int fcs; + long int foo; + long int fos; + long int mxcsr; + long int reserved; + long int st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */ + long int xmm_space[32]; /* 8*16 bytes for each XMM-reg = 128 bytes */ + long int padding[56]; +}; + +struct user_regs_struct +{ + long int ebx; + long int ecx; + long int edx; + long int esi; + long int edi; + long int ebp; + long int eax; + long int xds; + long int xes; + long int xfs; + long int xgs; + long int orig_eax; + long int eip; + long int xcs; + long int eflags; + long int esp; + long int xss; +}; + +// *INDENT-OFF* +struct user +{ + struct user_regs_struct regs; + int u_fpvalid; + struct user_fpregs_struct i387; + unsigned long int u_tsize; + unsigned long int u_dsize; + unsigned long int u_ssize; + unsigned long int start_code; + unsigned long int start_stack; + long int signal; + int reserved; + struct user_regs_struct *u_ar0; + struct user_fpregs_struct *u_fpstate; + unsigned long int magic; + char u_comm [32]; + int u_debugreg [8]; +}; + +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1UL << PAGE_SHIFT) +#define PAGE_MASK (~(PAGE_SIZE-1)) +#define NBPG PAGE_SIZE +#define UPAGES 1 +#define HOST_TEXT_START_ADDR (u.start_code) +#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG) +// *INDENT-ON* + +#endif // ! SYSTEM_LIBC + +#endif // __MES_SYS_USER_H diff --git a/vendor/mes-libc/include/sys/utsname.h b/vendor/mes-libc/include/sys/utsname.h @@ -0,0 +1,49 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2023 Janneke Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_UTSNAME_H +#define __MES_SYS_UTSNAME_H 1 + +#if SYSTEM_LIBC +#undef __MES_SYS_UTSNAME_H +#include_next <sys/utsname.h> + +#else // ! SYSTEM_LIBC + +#define _UTSNAME_LENGTH 65 + +struct utsname +{ + char sysname[_UTSNAME_LENGTH]; + char nodename[_UTSNAME_LENGTH]; + char release[_UTSNAME_LENGTH]; + char version[_UTSNAME_LENGTH]; + char machine[_UTSNAME_LENGTH]; +#ifdef _GNU_SOURCE + char domainname[_UTSNAME_LENGTH]; +#else + char __domainname[_UTSNAME_LENGTH]; +#endif +}; + +int uname (struct utsname *uts); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_SYS_UTSNAME_H diff --git a/vendor/mes-libc/include/sys/wait.h b/vendor/mes-libc/include/sys/wait.h @@ -0,0 +1,45 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_SYS_WAIT_H +#define __MES_SYS_WAIT_H 1 + +#include <sys/resource.h> + +#if SYSTEM_LIBC +#undef __MES_SYS_WAIT_H +#include_next <sys/wait.h> +#else // ! SYSTEM_LIBC + +#ifndef __MES_PID_T +#define __MES_PID_T +typedef int pid_t; +#endif + +#define WNOHANG 1 +#define W_EXITCODE(status, signal) ((status) << 8 | (signal)) + +pid_t waitpid (pid_t pid, int *status_ptr, int options); +pid_t wait (int *status_ptr); +pid_t wait4 (pid_t pid, int *wstatus, int options, + struct rusage *rusage); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_SYS_WAIT_H diff --git a/vendor/mes-libc/include/termio.h b/vendor/mes-libc/include/termio.h @@ -0,0 +1,72 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_TERMIO_H +#define __MES_TERMIO_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_TERMIO_H +#include_next <termio.h> + +#else // ! SYSTEM_LIBC + +#define TIOCGWINSZ 0x5413 +#define TCGETA 0x5405 +#define TCSETAW 0x5407 + +#define VTIME 5 +#define VMIN 6 + +#define ISIG 0000001 +#define ICANON 0000002 +#define ECHO 0000010 +#define ECHOK 0000040 +#define ECHONL 0000100 + +#define ISTRIP 0000040 +#define INLCR 0000100 +#define ICRNL 0000400 + +#define CS8 0000060 +#define PARENB 0000400 + +struct winsize +{ + unsigned short ws_row; + unsigned short ws_col; + unsigned short ws_xpixel; + unsigned short ws_ypixel; +}; + +struct termio +{ + unsigned short c_iflag; + unsigned short c_oflag; + unsigned short c_cflag; + unsigned short c_lflag; + unsigned char c_line; + unsigned char c_cc[8]; +}; + +#endif // ! SYSTEM_LIBC + +#endif // __MES_TERMIO_H diff --git a/vendor/mes-libc/include/time.h b/vendor/mes-libc/include/time.h @@ -0,0 +1,68 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_TIME_H +#define __MES_TIME_H 1 + +#if SYSTEM_LIBC +#undef __MES_TIME_H +#include_next <time.h> +#else // ! SYSTEM_LIBC + +#ifndef __MES_TIME_T +#define __MES_TIME_T 1 +typedef long clockid_t; +typedef long time_t; +#endif + +struct tm +{ + int tm_sec; + int tm_min; + int tm_hour; + int tm_mday; + int tm_mon; + int tm_year; + int tm_wday; + int tm_yday; + int tm_isdst; +}; + +#ifndef __MES_STRUCT_TIMESPEC +#define __MES_STRUCT_TIMESPEC + +struct timespec +{ + long tv_sec; + long tv_nsec; +}; + +#endif // __MES_STRUCT_TIMESPEC + +#define CLOCK_PROCESS_CPUTIME_ID 2 +int clock_gettime (clockid_t clk_id, struct timespec *tp); +struct tm *localtime (time_t const *timep); +struct tm *gmtime (time_t const *time); +time_t mktime (struct tm *broken_time); +int nanosleep (struct timespec const *requested_time, struct timespec const *remaining); +time_t time (time_t * tloc); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_TIME_H diff --git a/vendor/mes-libc/include/unistd.h b/vendor/mes-libc/include/unistd.h @@ -0,0 +1,110 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2024 Janneke Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2023 Timothy Sample <samplet@ngyro.com> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef __MES_UNISTD_H +#define __MES_UNISTD_H 1 + +#if SYSTEM_LIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_UNISTD_H +#include_next <unistd.h> + +#else // ! SYSTEM_LIBC + +#if defined (BOOTSTRAP_WITH_POSIX) +#define _POSIX_VERSION 199009L +#endif + +#include <sys/types.h> +#ifndef NULL +#define NULL 0 +#endif + +#ifndef STDIN_FILENO +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 +#endif // STDIN_FILENO + +#ifndef STDIN_FILE_NO +#define STDIN_FILE_NO 0 +#define STDOUT_FILE_NO 1 +#define STDERR_FILE_NO 2 +#endif // STDIN_FILE_NO + +#ifndef R_OK +#define F_OK 0 +#define X_OK 1 +#define W_OK 2 +#define R_OK 4 +#endif + +#ifndef _PC_NAME_MAX +#define _PC_NAME_MAX 3 +#endif +#ifndef _PC_PATH_MAX +#define _PC_PATH_MAX 4 +#endif + +int access (char const *s, int mode); +unsigned int alarm (unsigned int seconds); +int chdir (char const *file_name); +int close (int fd); +int execv (char const *file_name, char *const argv[]); +int execl (char const *file_name, char const *arg, ...); +int execlp (char const *file_name, char const *arg, ...); +int execve (char const *file, char *const argv[], char *const env[]); +int execvp (char const *file, char *const argv[]); +int fork (void); +int fsync (int filedes); +char *getcwd (char *buf, size_t size); +uid_t getuid (void); +gid_t getgid (void); +int setgid (gid_t newgid); +int setuid (uid_t newuid); +uid_t geteuid (void); +gid_t getegid (void); +pid_t getpgrp (void); +pid_t getpid (void); +pid_t getppid (void); +int getpgid (pid_t pid); +int isatty (int fd); +int link (char const *old_name, char const *new_name); +off_t lseek (int fd, off_t offset, int whence); +long pathconf (char const *file_name, int parameter); +int pipe (int filedes[2]); +ssize_t read (int fd, void *buffer, size_t size); +ssize_t readlink (char const *file_name, char *buffer, size_t size); +char *realpath (char const *name, char *resolved); +#if __SBRK_CHAR_PTRDIFF +/* xmalloc in binutils <= 2.10.1 uses this old prototype */ +char *sbrk (ptrdiff_t delta); +#else +void *sbrk (intptr_t delta); +#endif +int symlink (char const *old_name, char const *new_name); +int unlink (char const *file_name); +ssize_t write (int filedes, void const *buffer, size_t size); + +#endif // ! SYSTEM_LIBC + +#endif // __MES_UNISTD_H diff --git a/vendor/mes-libc/linux/malloc.c b/vendor/mes-libc/linux/malloc.c @@ -0,0 +1,44 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019,2021,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2021 Danny Milosavljevic <dannym@scratchpost.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <string.h> +#include <stddef.h> +#include <stdint.h> + +char *__brk = 0; + +void * +malloc (size_t size) +{ + if (!__brk) + __brk = cast_long_to_charp (brk (0)); +#if !__M2__ + /* align what we give back. */ + __brk = (char*) (((uintptr_t) __brk + + sizeof (max_align_t) - 1) & -sizeof (max_align_t)); +#endif + if (brk (__brk + size) == -1) + return 0; + char *p = __brk; + __brk = __brk + size; + return p; +} diff --git a/vendor/mes-libc/lispcc-syscall.c b/vendor/mes-libc/lispcc-syscall.c @@ -0,0 +1,248 @@ +/* lispcc-syscall.c — replaces mes's per-arch inline-asm syscall wrappers + * with C wrappers that call P1pp's labelled syscall entry points. + * + * The P1pp labels (sys_read / sys_write / sys_open / sys_close / + * sys_lseek / sys_brk / sys_unlink / sys_exit) are defined in + * P1/P1pp.P1pp and resolved at the linker stage thanks to cc.scm's + * external-linkage rule (commit 6488cca). + * + * Layering: + * public libc (read, write, open, …) — comes from posix/*.c + * └─ low-level _read, _write, _open3 — provided here + * └─ named sys_* labels — provided by P1pp.P1pp + * + * mes's linux/{brk,close,lseek,_open3,_read,unlink}.c are NOT vendored; + * the equivalents live here and bypass mes's _sys_callN indirection. + * mes's linux/<arch>-mes-{mescc,gcc}/{syscall,_exit,_write,…}.c are + * also unused — those are the inline-asm files we replace. + */ + +#include <mes/lib.h> +#include <fcntl.h> +#include <errno.h> +#include <stdio.h> +#include <unistd.h> +#include <sys/stat.h> + +/* mes's <stdio.h> defines stdin/stdout/stderr as macros expanding to + * (FILE*)0/1/2. That works for libc's own .c files, but client code + * (cc-libc tests, eventually tcc-boot2's compiled output) that uses + * `extern FILE *stdout;` needs a real linkage symbol. Drop the macros + * after libc's headers have set their guards, then define globals + * with the same initializer values. mes's libc bodies that already + * referenced `stdout` had the macro substitution happen on their + * #include path; subsequent .c files re-include <stdio.h> but hit + * the include guard and so see the now-undef'd identifiers, which + * resolve to our globals at link time (same numeric value, same fd). */ +#undef stdin +#undef stdout +#undef stderr +FILE *stdin = (FILE *) 0; +FILE *stdout = (FILE *) 1; +FILE *stderr = (FILE *) 2; + +extern long sys_read (long fd, long buf, long n); +extern long sys_write (long fd, long buf, long n); +extern long sys_open (long path, long flags, long mode); +extern long sys_close (long fd); +extern long sys_lseek (long fd, long off, long whence); +extern long sys_brk (long addr); +extern long sys_unlink (long path); +extern long sys_exit (long code); + +/* mes/globals.c already provides `int errno;` and the FILE-helper + * indirections (__buffered_read_clear, __ungetc_clear, __ungetc_init). + * mes/__buffered_read.c and mes/fdgetc.c implement them. */ + +ssize_t +_read (int filedes, void *buffer, size_t size) +{ + return sys_read (filedes, (long) buffer, (long) size); +} + +ssize_t +_write (int filedes, void const *buffer, size_t size) +{ + return sys_write (filedes, (long) buffer, (long) size); +} + +int +_open3 (char const *file_name, int flags, int mask) +{ + int r = sys_open ((long) file_name, flags, mask); + __ungetc_init (); + if (r > 2) + { + if (r >= __FILEDES_MAX) + { + errno = EMFILE; + return -1; + } + __ungetc_clear (r); + __buffered_read_clear (r); + } + return r; +} + +int +close (int filedes) +{ + long r = sys_close (filedes); + if (r < 0) + { + errno = -r; + return -1; + } + errno = 0; + return (int) r; +} + +off_t +_lseek (int filedes, off_t offset, int whence) +{ + return sys_lseek (filedes, offset, whence); +} + +off_t +lseek (int filedes, off_t offset, int whence) +{ + /* mirrors mes's linux/lseek.c: drain the per-fd read buffer before + * letting the kernel see a positional move; SEEK_CUR offsets must + * back out the buffered-but-not-yet-consumed bytes. */ + size_t skip = __buffered_read_clear (filedes); + if (whence == SEEK_CUR) + offset -= skip; + return sys_lseek (filedes, offset, whence); +} + +long +brk (void *addr) +{ + return sys_brk ((long) addr); +} + +int +unlink (char const *file_name) +{ + long r = sys_unlink ((long) file_name); + if (r < 0) + { + errno = -r; + return -1; + } + errno = 0; + return 0; +} + +void +_exit (int status) +{ + sys_exit (status); +} + +/* Linux aarch64/amd64/riscv64 stack at exec entry: + * [sp] = argc + * [sp + 8 * (1)] = argv[0] + * ... + * [sp + 8 * (argc+1)] = NULL (terminates argv) + * [sp + 8 * (argc+2)] = envp[0] + * Our :_start passes (a0=argc, a1=argv) to :p1_main. envp follows + * argv's NULL terminator, so we compute it from argv. tcc's getenv + * walks the resulting environ; without initialization it dereferences + * NULL on the first call and segfaults during tcc_new(). */ +extern char **environ; + +void +__libc_init (int argc, char **argv) +{ + (void) argc; + char **p = argv; + while (*p) + p++; + environ = p + 1; +} + +/* ---- ENOSYS stubs for libc-internal references not exercised by ---- + * tcc-boot2's golden path. The mes libc transitively pulls these in + * (posix/getcwd.c → _getcwd, posix/execvp.c → execve, stdlib/abort.c + * → raise, …). Providing -ENOSYS stubs keeps the link clean; if any + * of these surfaces in a real workload, replace the stub with a P1pp + * label and a thin wrapper above. */ + +#define ENOSYS 38 + +char * +_getcwd (char *buffer, size_t size) +{ + (void) buffer; (void) size; + errno = ENOSYS; + return 0; +} + +int +access (char const *path, int mode) +{ + (void) path; (void) mode; + errno = ENOSYS; + return -1; +} + +void +assert_msg (int check, char *msg) +{ + if (!check) + { + sys_write (2, (long) msg, 0); + sys_exit (1); + } +} + +int +execve (char const *file, char *const argv[], char *const envp[]) +{ + (void) file; (void) argv; (void) envp; + errno = ENOSYS; + return -1; +} + +int +fsync (int filedes) +{ + (void) filedes; + return 0; +} + +int +raise (int sig) +{ + /* abort() calls raise(SIGABRT); take that as a hard exit. */ + sys_exit (128 + sig); + return -1; +} + +int +rmdir (char const *file_name) +{ + (void) file_name; + errno = ENOSYS; + return -1; +} + +int +stat (char const *file_name, struct stat *buf) +{ + (void) file_name; (void) buf; + errno = ENOSYS; + return -1; +} + +double +strtod (char const *string, char **tailptr) +{ + /* tcc.flat.c never reaches strtod under our defines (HAVE_FLOAT off), + * and stdlib/strtof.c only forwards. cc.scm rejects FP literals, so + * we cast a zero int — same numeric value, no `0.0` token. */ + if (tailptr) + *tailptr = (char *) string; + return (double) 0; +} diff --git a/vendor/mes-libc/mes/__assert_fail.c b/vendor/mes-libc/mes/__assert_fail.c @@ -0,0 +1,48 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <assert.h> + +void +__assert_fail (char const *msg, char const *file, unsigned line, + char const *function) +{ + if (file && *file) + { + eputs (file); + eputs (":"); + } + if (line) + { + eputs (itoa (line)); + eputs (":"); + } + if (function && *function) + { + eputs (function); + eputs (":"); + } + eputs ("assert fail: "); + eputs (msg); + eputs ("\n"); + char *fail = 0; + fail[0] = 0; +} diff --git a/vendor/mes-libc/mes/__buffered_read.c b/vendor/mes-libc/mes/__buffered_read.c @@ -0,0 +1,109 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <stdlib.h> +#include <string.h> + +#if !__MESC__ +#define __READ_BUFFER_MAX 128 +int __read_buffer_max; +#else /* FIXME: We want bin/mes-mescc's x86-linux sha256sum to stay the same. */ +#define __READ_BUFFER_MAX 100 +#define __read_buffer_max 100 +#endif + +struct __read_buffer +{ + ssize_t size; + char string[__READ_BUFFER_MAX]; +}; + +struct __read_buffer *__read_cache = 0; + +void +__buffered_read_init (int filedes) +{ + if (!__read_cache) + { + __read_cache = (struct __read_buffer *) malloc (sizeof (struct __read_buffer) * __FILEDES_MAX); +#if !__MESC__ + __read_buffer_max = __READ_BUFFER_MAX; + char *p = getenv ("MES_READ_BUFFER"); + if (p) + { + __read_buffer_max = atoi (p); + if (__read_buffer_max < 0) + __read_buffer_max = 0; + if (__read_buffer_max > __READ_BUFFER_MAX) + __read_buffer_max = __READ_BUFFER_MAX; + } +#endif + } +} + +size_t +__buffered_read_clear (int filedes) +{ + __buffered_read_init (filedes); + size_t size = __read_cache[filedes].size; + __read_cache[filedes].size = 0; + return size; +} + +ssize_t +__buffered_read (int filedes, void *buffer, size_t size) +{ + size_t todo = size; + __buffered_read_init (filedes); + struct __read_buffer *cache = &__read_cache[filedes]; + char *p = buffer; + if (!cache->size && size > __read_buffer_max) + return _read (filedes, buffer, size); + while (cache->size > 0 && todo) + { + todo--; + *p++ = cache->string[__read_buffer_max - cache->size--]; + } + if (todo) + { +#if !__MESC__ + if (todo > __read_buffer_max) + return size - todo + _read (filedes, p, todo); + if (__mes_debug () > 4) + { + eputs ("__buffered_read: "); + eputs (itoa (__read_buffer_max)); + eputs ("\n"); + } +#endif + ssize_t bytes = _read (filedes, cache->string, __read_buffer_max); + if (bytes < 0) + return -1; + if (bytes) + { + cache->size = bytes; + if (bytes < __read_buffer_max) + memmove (cache->string + __read_buffer_max - bytes, cache->string, bytes); + return size - todo + __buffered_read (filedes, p, todo); + } + } + return size - todo; +} diff --git a/vendor/mes-libc/mes/__init_io.c b/vendor/mes-libc/mes/__init_io.c @@ -0,0 +1,30 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2023 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "mes/lib-mini.h" + +void +__init_io (int argc, char** argv, char** envp) +{ + __stdin = 0; + __stdout = 1; + __stderr = 2; + environ = envp; +} diff --git a/vendor/mes-libc/mes/__mes_debug.c b/vendor/mes-libc/mes/__mes_debug.c @@ -0,0 +1,36 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "mes/lib.h" +#include <stdlib.h> + +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) + +int +__mes_debug () +{ + static int __mes_debug = -1; + if (__mes_debug == -1) + { + char *p = getenv ("MES_DEBUG"); + __mes_debug = p ? MAX (atoi (p), 1) : 0; + } + return __mes_debug; +} diff --git a/vendor/mes-libc/mes/abtol.c b/vendor/mes-libc/mes/abtol.c @@ -0,0 +1,63 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2022,2023 Rick Masters <grick23@gmail.com> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <ctype.h> + +long +abtol (char const **p, int base) +{ + char const *s = p[0]; + int i = 0; + int sign_p = 0; + int m = '0'; + if (base == 0) + base = 10; + while (isspace (s[0]) != 0) + s = s + 1; + if (s[0] != 0 && s[0] == '+') + s = s + 1; + if (s[0] != 0 && s[0] == '-') + { + sign_p = 1; + s = s + 1; + } + while (isnumber (s[0], base) != 0) + { + i = i * base; + if (s[0] >= 'a') + m = 'a' - 10; + else + { + if (s[0] >= 'A') + m = 'A' - 10; + else + m = '0'; + } + i = i + s[0] - m; + s = s + 1; + } + p[0] = s; + if (sign_p != 0) + return -i; + + return i; +} diff --git a/vendor/mes-libc/mes/cast.c b/vendor/mes-libc/mes/cast.c @@ -0,0 +1,57 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> + +#undef cast_intp_to_charp +#undef cast_long_to_charp +#undef cast_charp_to_long +#undef cast_int_to_long +#undef cast_voidp_to_long + +char* +cast_intp_to_charp (int const *i) +{ + return (char*)i; +} + +char* +cast_long_to_charp (long i) +{ + return (char*)i; +} + +long +cast_charp_to_long (char const *i) +{ + return (long)i; +} + +long +cast_int_to_long (int i) +{ + return (long)i; +} + +long +cast_voidp_to_long (void const *i) +{ + return (long)i; +} diff --git a/vendor/mes-libc/mes/dtoab.c b/vendor/mes-libc/mes/dtoab.c @@ -0,0 +1,46 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <limits.h> +#include <string.h> + +char * +dtoab (double d, int base, int signed_p) +{ + static char dtoa_buf[40]; + long i = (long) d; + char *p = ntoab (i, base, signed_p); + strcpy (dtoa_buf, p); + long f = (d - (double) i) * (double) 100000000; + if (f) + { + if (f < 0) + f = -f; + strcat (dtoa_buf, "."); + p = ntoab (f, base, 1); + strcat (dtoa_buf, p); + p = strchr (dtoa_buf, 0); + p--; + while (*p && *p == '0') + *p-- = 0; + } + return dtoa_buf; +} diff --git a/vendor/mes-libc/mes/eputc.c b/vendor/mes-libc/mes/eputc.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> + +int +eputc (int c) +{ + return fdputc (c, __stderr); +} diff --git a/vendor/mes-libc/mes/eputs.c b/vendor/mes-libc/mes/eputs.c @@ -0,0 +1,30 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib-mini.h> +#include <string.h> + +int +eputs (char const *s) +{ + int i = strlen (s); + write (__stderr, s, i); + return 0; +} diff --git a/vendor/mes-libc/mes/fdgetc.c b/vendor/mes-libc/mes/fdgetc.c @@ -0,0 +1,88 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <errno.h> +#include <limits.h> +#include <stdlib.h> +#include <string.h> +#include <sys/resource.h> +#include <unistd.h> + +int *__ungetc_buf; + +int +__ungetc_p (int filedes) +{ + if (__ungetc_buf == 0) + __ungetc_init (); + return __ungetc_buf[filedes] >= 0; +} + +void +__ungetc_init () +{ + if (__ungetc_buf == 0) + { + int save_errno = errno; + __ungetc_buf = malloc ((__FILEDES_MAX + 1) * sizeof (int)); + errno = save_errno; + memset (__ungetc_buf, -1, (__FILEDES_MAX + 1) * sizeof (int)); + } +} + +void +__ungetc_clear (int filedes) +{ + if (__ungetc_buf == 0) + __ungetc_init (); + __ungetc_buf[filedes] = -1; +} + +void +__ungetc_set (int filedes, int c) +{ + if (__ungetc_buf == 0) + __ungetc_init (); + __ungetc_buf[filedes] = c; +} + +int +fdgetc (int fd) +{ + if (__ungetc_buf == 0) + __ungetc_init (); + + char c; + int i = __ungetc_buf[fd]; + if (i >= 0) + __ungetc_buf[fd] = -1; + else + { + int r = read (fd, &c, 1); + if (r < 1) + return -1; + i = c; + } + if (i < 0) + i = i + 256; + + return i; +} diff --git a/vendor/mes-libc/mes/fdgets.c b/vendor/mes-libc/mes/fdgets.c @@ -0,0 +1,40 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <stdio.h> + +char * +fdgets (char *s, int count, int fd) +{ + int c = 0; + char *p = s; + while (--count > 0 && c != '\n') + { + c = fdgetc (fd); + if (c == EOF) + break; + *p++ = c; + } + if (p == s && (c == EOF || count == -1)) + return 0; + *p = 0; + return s; +} diff --git a/vendor/mes-libc/mes/fdputc.c b/vendor/mes-libc/mes/fdputc.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> + +int +fdputc (int c, int fd) +{ + char *p = cast_intp_to_charp (&c); + write (fd, p, 1); + return 0; +} diff --git a/vendor/mes-libc/mes/fdputs.c b/vendor/mes-libc/mes/fdputs.c @@ -0,0 +1,30 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <string.h> + +int +fdputs (char const *s, int fd) +{ + int i = strlen (s); + write (fd, s, i); + return 0; +} diff --git a/vendor/mes-libc/mes/fdungetc.c b/vendor/mes-libc/mes/fdungetc.c @@ -0,0 +1,37 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> + +int +fdungetc (int c, int fd) +{ + if (c == -1) + return c; + else if (__ungetc_p (fd)) + { + eputs (" ***MES C LIB*** fdungetc ungetc buffer overflow fd="); + eputs (itoa (fd)); + eputs ("\n"); + assert_msg (0, "0"); + } + __ungetc_set (fd, c); + return c; +} diff --git a/vendor/mes-libc/mes/globals.c b/vendor/mes-libc/mes/globals.c @@ -0,0 +1,27 @@ +/* + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib-mini.h> + +int errno; +char **environ; +int __stdin; +int __stdout; +int __stderr; diff --git a/vendor/mes-libc/mes/itoa.c b/vendor/mes-libc/mes/itoa.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> + +char * +itoa (int x) +{ + return ntoab (x, 10, 1); +} diff --git a/vendor/mes-libc/mes/ltoa.c b/vendor/mes-libc/mes/ltoa.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> + +char * +ltoa (long x) +{ + return ntoab (x, 10, 1); +} diff --git a/vendor/mes-libc/mes/ltoab.c b/vendor/mes-libc/mes/ltoab.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> + +char * +ltoab (long x, int base) +{ + return ntoab (x, base, 1); +} diff --git a/vendor/mes-libc/mes/mes_open.c b/vendor/mes-libc/mes/mes_open.c @@ -0,0 +1,49 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <stdlib.h> + +#if SYSTEM_LIBC +#include <fcntl.h> +#include <stdarg.h> +// The Mes C Library defines and initializes these in crt1 +int __stdin = STDIN; +int __stdout = STDOUT; +int __stderr = STDERR; + +int +mes_open (char const *file_name, int flags, int mask) +{ + int filedes = open (file_name, flags, mask); + if (filedes > 2) + __ungetc_clear (filedes); + return filedes; +} + +#else // !SYSTEM_LIBC + +int +mes_open (char const *file_name, int flags, int mask) +{ + return _open3 (file_name, flags, mask); +} + +#endif // !SYSTEM_LIBC diff --git a/vendor/mes-libc/mes/ntoab.c b/vendor/mes-libc/mes/ntoab.c @@ -0,0 +1,92 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2024 Michael Forney <mforney@mforney.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <assert.h> +#include <stdlib.h> +#include <string.h> + +#if __MESC__ && __arm__ +#define __MESC__and__arm__ +#endif + +#if __TINYC__ && __arm__ && BOOTSTRAP +#define __TINYC__and__arm__and__BOOTSTRAP +#endif + +#define __not__MESC__arm__and__not__TINYC__arm__BOOTSTRAP !defined (__MESC__and__arm__) && !defined (__TINYC__and__arm__and__BOOTSTRAP) + +// FIXME: M2-Planet 1.10.0 crashes on this... +// #if __M2__ || (!defined (__MESC__and__arm__) && !defined (__TINYC__and__arm__and__BOOTSTRAP)) +#if __M2__ || __not__MESC__arm__and__not__TINYC__arm__BOOTSTRAP +size_t +__mesabi_uldiv (size_t a, size_t b, size_t *remainder) +{ + remainder[0] = a % b; + return a / b; +} +#endif + +char *__itoa_buf; + +char * +ntoab (long x, unsigned base, int signed_p) +{ + if (__itoa_buf == 0) + __itoa_buf = malloc (24); + char *p = __itoa_buf + 23; + + assert_msg (base >= 8, "base >= 8"); + + int sign_p = 0; + size_t i; + size_t u; + size_t b = base; + if (signed_p != 0 && x < 0) + { + sign_p = 1; + /* Avoid LONG_MIN */ + u = (-(x + 1)); + u = u + 1; + } + else + u = x; + + p[0] = 0; + do + { + p = p - 1; + u = __mesabi_uldiv (u, b, &i); + if (i > 9) + p[0] = 'a' + i - 10; + else + p[0] = '0' + i; + } + while (u != 0); + + if (sign_p && p[0] != '0') + { + p = p - 1; + p[0] = '-'; + } + + return p; +} diff --git a/vendor/mes-libc/mes/oputc.c b/vendor/mes-libc/mes/oputc.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> + +int +oputc (int c) +{ + return fdputc (c, __stdout); +} diff --git a/vendor/mes-libc/mes/oputs.c b/vendor/mes-libc/mes/oputs.c @@ -0,0 +1,30 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib-mini.h> +#include <string.h> + +int +oputs (char const *s) +{ + int i = strlen (s); + write (__stdout, s, i); + return 0; +} diff --git a/vendor/mes-libc/mes/search-path.c b/vendor/mes-libc/mes/search-path.c @@ -0,0 +1,66 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +char * +search_path (char const *file_name) +{ + static char buf[256]; + char *path = getenv ("PATH"); + if (__mes_debug ()) + { + eputs ("\n search-path: "); + eputs (file_name); + eputs ("\n"); + } + while (*path) + { + char *end = strchr (path, ':'); + if (!end) + end = strchr (path, '\0'); + strncpy (buf, path, end - path); + buf[end - path] = 0; + if (__mes_debug ()) + { + eputs (" dir: "); + eputs (buf); + eputs ("\n"); + } + if (buf[end - path] != '/') + strcat (buf, "/"); + strcat (buf, file_name); + if (!access (buf, X_OK)) + { + if (__mes_debug ()) + { + eputs (" found: "); + eputs (buf); + eputs ("\n"); + } + return buf; + } + path = end + 1; + } + return 0; +} diff --git a/vendor/mes-libc/mes/ultoa.c b/vendor/mes-libc/mes/ultoa.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> + +char * +ultoa (unsigned long x) +{ + return ntoab (x, 10, 1); +} diff --git a/vendor/mes-libc/mes/utoa.c b/vendor/mes-libc/mes/utoa.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> + +char * +utoa (unsigned x) +{ + return ntoab (x, 10, 0); +} diff --git a/vendor/mes-libc/patches/lib-mes-debug-proto.after b/vendor/mes-libc/patches/lib-mes-debug-proto.after @@ -0,0 +1,2 @@ +int __mes_debug (void); +void __ungetc_init (void); diff --git a/vendor/mes-libc/patches/lib-mes-debug-proto.before b/vendor/mes-libc/patches/lib-mes-debug-proto.before @@ -0,0 +1,2 @@ +int __mes_debug (); +void __ungetc_init (); diff --git a/vendor/mes-libc/patches/libmini-write-proto.after b/vendor/mes-libc/patches/libmini-write-proto.after @@ -0,0 +1 @@ +void __init_io (int argc, char **argv, char **envp); diff --git a/vendor/mes-libc/patches/libmini-write-proto.before b/vendor/mes-libc/patches/libmini-write-proto.before @@ -0,0 +1 @@ +void __init_io (); diff --git a/vendor/mes-libc/patches/libmini-write-proto2.after b/vendor/mes-libc/patches/libmini-write-proto2.after @@ -0,0 +1 @@ +ssize_t _write (int filedes, void const *buffer, size_t size); diff --git a/vendor/mes-libc/patches/libmini-write-proto2.before b/vendor/mes-libc/patches/libmini-write-proto2.before @@ -0,0 +1 @@ +ssize_t _write (); diff --git a/vendor/mes-libc/patches/malloc-max-align.after b/vendor/mes-libc/patches/malloc-max-align.after @@ -0,0 +1,5 @@ +#if !__M2__ + /* align what we give back. cc.scm has no max_align_t; 16 is the + * largest scalar alignment we hand out (long long / pointer / double). */ + __brk = (char*) (((uintptr_t) __brk + 16 - 1) & -16); +#endif diff --git a/vendor/mes-libc/patches/malloc-max-align.before b/vendor/mes-libc/patches/malloc-max-align.before @@ -0,0 +1,5 @@ +#if !__M2__ + /* align what we give back. */ + __brk = (char*) (((uintptr_t) __brk + + sizeof (max_align_t) - 1) & -sizeof (max_align_t)); +#endif diff --git a/vendor/mes-libc/patches/strstr-drop-mman.after b/vendor/mes-libc/patches/strstr-drop-mman.after @@ -0,0 +1,2 @@ +#include <stdlib.h> +#include <string.h> diff --git a/vendor/mes-libc/patches/strstr-drop-mman.before b/vendor/mes-libc/patches/strstr-drop-mman.before @@ -0,0 +1,3 @@ +#include <stdlib.h> +#include <string.h> +#include <sys/mman.h> diff --git a/vendor/mes-libc/posix/buffered-read.c b/vendor/mes-libc/posix/buffered-read.c @@ -0,0 +1,48 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <fcntl.h> + +ssize_t +read (int filedes, void *buffer, size_t size) +{ + ssize_t bytes = __buffered_read (filedes, buffer, size); + if (__mes_debug () > 4) + { + if (bytes == 1) + { + eputs ("read fd="); + eputs (itoa ((int) filedes)); + eputs (" c="); + eputc (*(char *) buffer); + eputs ("\n"); + } + else + { + eputs ("read fd="); + eputs (itoa ((int) filedes)); + eputs (" bytes="); + eputs (itoa (bytes)); + eputs ("\n"); + } + } + return bytes; +} diff --git a/vendor/mes-libc/posix/execvp.c b/vendor/mes-libc/posix/execvp.c @@ -0,0 +1,53 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <errno.h> +#include <string.h> +#include <unistd.h> + +int +execvp (char const *file_name, char *const argv[]) +{ + if (!strchr (file_name, '/')) + file_name = search_path (file_name); + if (!file_name) + { + errno = ENOENT; + return -1; + } + if (__mes_debug ()) + { + eputs (" EXEC: "); + eputs (file_name); + eputs ("\n"); + int i = 0; + while (argv[i]) + { + eputs (" arg["); + eputs (itoa (i)); + eputs ("]: "); + eputs (argv[i]); + eputs ("\n"); + i++; + } + } + return execve (file_name, argv, environ); +} diff --git a/vendor/mes-libc/posix/getcwd.c b/vendor/mes-libc/posix/getcwd.c @@ -0,0 +1,33 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019,2020,2021,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <limits.h> +#include <sys/types.h> +#include <mes/lib.h> + +char * +getcwd (char *buffer, size_t size) +{ + static char buf[PATH_MAX]; + if (buffer == 0) + buffer = buf; + return _getcwd (buffer, size); +} diff --git a/vendor/mes-libc/posix/getenv.c b/vendor/mes-libc/posix/getenv.c @@ -0,0 +1,49 @@ +/* + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <string.h> +#include <stdlib.h> + +char * +getenv (char const *s) +{ + /* eputs ("\ngetenv s="); eputs (s); eputs ("\n"); */ + char **p = environ; + char *q; + int length = strlen (s); + + while (p[0] != 0) + { + /* eputs ("getenv p[0]="); eputs (p[0]); eputs ("\n"); */ + if (strncmp (s, p[0], length) == 0) + { + /* eputs ("found!\n"); */ + q = p[0] + length; + if (q[0] == '=') + return q + 1; + } + /* else */ + /* eputs ("not found!\n"); */ + p = p + M2_PTR_SIZE; + } + + return 0; +} diff --git a/vendor/mes-libc/posix/open.c b/vendor/mes-libc/posix/open.c @@ -0,0 +1,54 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <fcntl.h> +#include <stdarg.h> + +int +_open2 (char const *file_name, int flags) +{ + int mask = 0777; + return _open3 (file_name, flags, mask); +} + +#if __M2__ +int +open (char const *file_name, int flags, int mask) +{ + return _open3 (file_name, flags, mask); +} +#else // !__M2__ +int +open (char const *file_name, int flags, ...) +{ + if (flags & O_CREAT) + { + va_list ap; + va_start (ap, flags); + int mask = va_arg (ap, int); + int r = _open3 (file_name, flags, mask); + va_end (ap); + return r; + } + else + return _open2 (file_name, flags); +} +#endif // !__M2__ diff --git a/vendor/mes-libc/posix/sbrk.c b/vendor/mes-libc/posix/sbrk.c @@ -0,0 +1,36 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <unistd.h> +#include <stdlib.h> + +#if __SBRK_CHAR_PTRDIFF +char * +sbrk (ptrdiff_t) +#else +void * +sbrk (intptr_t delta) +#endif +{ + if (delta >= 0) + return malloc (delta); + return __brk; +} diff --git a/vendor/mes-libc/posix/write.c b/vendor/mes-libc/posix/write.c @@ -0,0 +1,41 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <errno.h> +#include <stdio.h> +#include <unistd.h> + +ssize_t +write (int filedes, void const *buffer, size_t size) +{ + size_t skip = __buffered_read_clear (filedes); + if (skip) + lseek (filedes, -skip, SEEK_CUR); + int r = _write (filedes, buffer, size); + if (r < 0) + { + errno = -r; + r = -1; + } + else + errno = 0; + return r; +} diff --git a/vendor/mes-libc/stdio/clearerr.c b/vendor/mes-libc/stdio/clearerr.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <errno.h> +#include <stdio.h> + +void +clearerr (FILE * stream) +{ + errno = 0; +} diff --git a/vendor/mes-libc/stdio/fclose.c b/vendor/mes-libc/stdio/fclose.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> +#include <unistd.h> + +int +fclose (FILE * stream) +{ + int fd = (long) stream; + return close (fd); +} diff --git a/vendor/mes-libc/stdio/fdopen.c b/vendor/mes-libc/stdio/fdopen.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> + +FILE * +fdopen (int fd, char const *mode) +{ + return (FILE *) (long) fd; +} diff --git a/vendor/mes-libc/stdio/feof.c b/vendor/mes-libc/stdio/feof.c @@ -0,0 +1,30 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> + +int +feof (FILE * stream) +{ + int c = fgetc (stream); + if (c != EOF) + ungetc (c, stream); + return c == EOF; +} diff --git a/vendor/mes-libc/stdio/ferror.c b/vendor/mes-libc/stdio/ferror.c @@ -0,0 +1,30 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> + +int +ferror (FILE * stream) +{ + int fd = (long) stream; + if (fd == -1) + return -1; + return 0; +} diff --git a/vendor/mes-libc/stdio/fflush.c b/vendor/mes-libc/stdio/fflush.c @@ -0,0 +1,32 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> +#include <sys/stat.h> +#include <unistd.h> + +int +fflush (FILE * stream) +{ + int filedes = (long) stream; + if (filedes < 3) + return 0; + return fsync (filedes); +} diff --git a/vendor/mes-libc/stdio/fgetc.c b/vendor/mes-libc/stdio/fgetc.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> + +int +fgetc (FILE * stream) +{ + return fdgetc ((long) stream); +} diff --git a/vendor/mes-libc/stdio/fgets.c b/vendor/mes-libc/stdio/fgets.c @@ -0,0 +1,28 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <stdio.h> + +char * +fgets (char *s, int count, FILE * stream) +{ + return fdgets (s, count, (int) (long) stream); +} diff --git a/vendor/mes-libc/stdio/fileno.c b/vendor/mes-libc/stdio/fileno.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> + +int +fileno (FILE * stream) +{ + return (int) (long) stream; +} diff --git a/vendor/mes-libc/stdio/fopen.c b/vendor/mes-libc/stdio/fopen.c @@ -0,0 +1,74 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2018 Jeremiah Orians <jeremiah@pdp10.guru> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <assert.h> +#include <fcntl.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +FILE * +fopen (char const *file_name, char const *opentype) +{ + if (__mes_debug ()) + { + eputs ("fopen "); + eputs (file_name); + eputs (" "); + eputs (opentype); + eputs ("\n"); + } + + int fd; + int mode = 0600; + if ((opentype[0] == 'a' || !strcmp (opentype, "r+")) && !access (file_name, O_RDONLY)) + { + int flags = O_RDWR; + if (opentype[0] == 'a') + flags |= O_APPEND; + fd = _open3 (file_name, flags, mode); + } + else if (opentype[0] == 'w' || opentype[0] == 'a' || !strcmp (opentype, "r+")) + { + char *plus_p = strchr (opentype, '+'); + int flags = plus_p ? O_RDWR | O_CREAT : O_WRONLY | O_CREAT | O_TRUNC; + fd = _open3 (file_name, flags, mode); + } + else + fd = _open3 (file_name, O_RDONLY, 0); + + if (__mes_debug ()) + { + eputs (" => fd="); + eputs (itoa (fd)); + eputs ("\n"); + } + + if (!fd) + { + eputs (" ***MES LIB C*** fopen of stdin: signal me in band\n"); + assert (0); + } + if (fd < 0) + fd = 0; + return (FILE *) (long) fd; +} diff --git a/vendor/mes-libc/stdio/fprintf.c b/vendor/mes-libc/stdio/fprintf.c @@ -0,0 +1,33 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <stdarg.h> +#include <stdio.h> + +int +fprintf (FILE * stream, char const *format, ...) +{ + va_list ap; + va_start (ap, format); + int r = vfprintf (stream, format, ap); + va_end (ap); + return r; +} diff --git a/vendor/mes-libc/stdio/fputc.c b/vendor/mes-libc/stdio/fputc.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> + +int +fputc (int c, FILE * stream) +{ + return fdputc (c, (long) stream); +} diff --git a/vendor/mes-libc/stdio/fputs.c b/vendor/mes-libc/stdio/fputs.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> + +int +fputs (char const *s, FILE * stream) +{ + return fdputs (s, (long) stream); +} diff --git a/vendor/mes-libc/stdio/fread.c b/vendor/mes-libc/stdio/fread.c @@ -0,0 +1,76 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +int +__fungetc_p (FILE * stream) +{ + return __ungetc_p ((int) (long) stream); +} + +size_t +fread (void *data, size_t size, size_t count, FILE * stream) +{ + if (!size || !count) + return 0; + + size_t todo = size * count; + char *buf = (char *) data; + + int bytes = 0; + while (__fungetc_p (stream) && todo-- && ++bytes) + *buf++ = fgetc (stream); + int filedes = (long) stream; + if (todo) + { + int r = read (filedes, buf, todo); + if (r < 0 && !bytes) + bytes = r; + else + bytes += r; + } + + if (__mes_debug ()) + { + static char debug_buf[4096]; + eputs ("fread fd="); + eputs (itoa (filedes)); + eputs (" bytes="); + eputs (itoa (bytes)); + eputs ("\n"); + if (bytes > 0 && bytes < sizeof (debug_buf)) + { + strncpy (debug_buf, data, bytes); + buf[bytes] = 0; + eputs ("fread buf="); + eputs (debug_buf); + eputs ("\n"); + } + } + + if (bytes > 0) + return bytes / size; + + return 0; +} diff --git a/vendor/mes-libc/stdio/fseek.c b/vendor/mes-libc/stdio/fseek.c @@ -0,0 +1,41 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <stdio.h> +#include <unistd.h> + +int +fseek (FILE * stream, long offset, int whence) +{ + int filedes = (long) stream; + off_t pos = lseek (filedes, offset, whence); + if (__mes_debug ()) + { + eputs ("fread fd="); + eputs (itoa (filedes)); + eputs (" =>"); + eputs (itoa (pos)); + eputs ("\n"); + } + if (pos >= 0) + return 0; + return -1; +} diff --git a/vendor/mes-libc/stdio/ftell.c b/vendor/mes-libc/stdio/ftell.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <fcntl.h> +#include <stdio.h> +#include <unistd.h> + +long +ftell (FILE * stream) +{ + return lseek ((int) (long) stream, 0, SEEK_CUR); +} diff --git a/vendor/mes-libc/stdio/fwrite.c b/vendor/mes-libc/stdio/fwrite.c @@ -0,0 +1,52 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <stdio.h> +#include <unistd.h> + +size_t +fwrite (void const *data, size_t size, size_t count, FILE * stream) +{ + if (__mes_debug () > 1) + { + eputs ("fwrite "); + eputs (itoa ((int) (long) stream)); + eputs (" "); + eputs (itoa (size)); + eputs ("\n"); + } + + if (!size || !count) + return 0; + int filedes = (long) stream; + int bytes = write (filedes, data, size * count); + + if (__mes_debug () > 2) + { + eputs (" => "); + eputs (itoa (bytes)); + eputs ("\n"); + } + + if (bytes > 0) + return bytes / size; + return 0; +} diff --git a/vendor/mes-libc/stdio/getc.c b/vendor/mes-libc/stdio/getc.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> + +int +getc (FILE * stream) +{ + return fdgetc ((long) stream); +} diff --git a/vendor/mes-libc/stdio/perror.c b/vendor/mes-libc/stdio/perror.c @@ -0,0 +1,30 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <errno.h> +#include <stdio.h> +#include <string.h> + +void +perror (char const *message) +{ + fprintf (stderr, "%s: %s\n", strerror (errno), message); +} diff --git a/vendor/mes-libc/stdio/printf.c b/vendor/mes-libc/stdio/printf.c @@ -0,0 +1,39 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <stdarg.h> +#include <stdio.h> + +int +printf (char const *format, ...) +{ + va_list ap; + int r; +#if __GNUC__ && __x86_64__ && !SYSTEM_LIBC +#define __FUNCTION_ARGS 1 + ap += (__FOO_VARARGS + (__FUNCTION_ARGS << 1)) << 3; +#undef __FUNCTION_ARGS +#endif + va_start (ap, format); + r = vprintf (format, ap); + va_end (ap); + return r; +} diff --git a/vendor/mes-libc/stdio/putc.c b/vendor/mes-libc/stdio/putc.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> + +int +putc (int c, FILE * stream) +{ + return fdputc (c, (long) stream); +} diff --git a/vendor/mes-libc/stdio/remove.c b/vendor/mes-libc/stdio/remove.c @@ -0,0 +1,34 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> +#include <sys/stat.h> +#include <unistd.h> + +int +remove (char const *file_name) +{ + struct stat buf; + if (stat (file_name, &buf) < 0) + return -1; + if (S_ISDIR (buf.st_mode)) + return rmdir (file_name); + return unlink (file_name); +} diff --git a/vendor/mes-libc/stdio/snprintf.c b/vendor/mes-libc/stdio/snprintf.c @@ -0,0 +1,39 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <stdarg.h> +#include <stdio.h> + +int +snprintf (char *str, size_t size, char const *format, ...) +{ + va_list ap; + int r; +#if __GNUC__ && __x86_64__ && !SYSTEM_LIBC +#define __FUNCTION_ARGS 3 + ap += (__FOO_VARARGS + (__FUNCTION_ARGS << 1)) << 3; +#undef __FUNCTION_ARGS +#endif + va_start (ap, format); + r = vsnprintf (str, size, format, ap); + va_end (ap); + return r; +} diff --git a/vendor/mes-libc/stdio/sprintf.c b/vendor/mes-libc/stdio/sprintf.c @@ -0,0 +1,39 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <stdarg.h> +#include <stdio.h> + +int +sprintf (char *str, char const *format, ...) +{ + va_list ap; + int r; +#if __GNUC__ && __x86_64__ && !SYSTEM_LIBC +#define __FUNCTION_ARGS 2 + ap += (__FOO_VARARGS + (__FUNCTION_ARGS << 1)) << 3; +#undef __FUNCTION_ARGS +#endif + va_start (ap, format); + r = vsprintf (str, format, ap); + va_end (ap); + return r; +} diff --git a/vendor/mes-libc/stdio/ungetc.c b/vendor/mes-libc/stdio/ungetc.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> + +int +ungetc (int c, FILE * stream) +{ + return fdungetc (c, (long) stream); +} diff --git a/vendor/mes-libc/stdio/vfprintf.c b/vendor/mes-libc/stdio/vfprintf.c @@ -0,0 +1,252 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <stdarg.h> +#include <stdio.h> +#include <string.h> + +int +vfprintf (FILE * f, char const *format, va_list ap) +{ + int fd = (long) f; + char const *p = format; + int count = 0; + while (*p) + if (*p != '%') + { + count++; + fputc (*p++, f); + } + else + { + p++; + char c = *p; + int left_p = 0; + int precision = -1; + int width = -1; + if (c == '-') + { + left_p = 1; + c = *++p; + } + char pad = ' '; + if (c == ' ') + { + pad = c; + c = *p++; + } + if (c == '0') + { + pad = c; + c = *p++; + } + if (c >= '0' && c <= '9') + { + width = abtol (&p, 10); + c = *p; + } + else if (c == '*') + { + width = va_arg (ap, int); + c = *++p; + } + if (c == '.') + { + c = *++p; + if (c >= '0' && c <= '9') + { + precision = abtol (&p, 10); + c = *p; + } + else if (c == '*') + { + precision = va_arg (ap, int); + c = *++p; + } + } + if (c == 'l') + c = *++p; + if (c == 'l') + { + eputs ("vfprintf: skipping second: l\n"); + c = *++p; + } + switch (c) + { + case '%': + { + fputc (*p, f); + count++; + break; + } + case 'c': + { + char _c; + _c = va_arg (ap, long); + fputc (_c, f); + break; + } + case 'd': + case 'i': + case 'o': + case 'u': + case 'x': + case 'X': + { + long d = va_arg (ap, long); + int base = c == 'o' ? 8 : c == 'x' || c == 'X' ? 16 : 10; + char *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X'); + if (c == 'X') + strupr (s); + int length = strlen (s); + if (precision == -1) + precision = length; + if (!left_p) + { + while (width-- > precision) + { + fputc (pad, f); + count++; + } + while (precision > length) + { + fputc ('0', f); + precision--; + width--; + count++; + } + } + while (*s) + { + if (precision-- <= 0) + break; + width--; + fputc (*s++, f); + count++; + } + while (width > 0) + { + width--; + fputc (pad, f); + count++; + } + break; + } + case 's': + { + char *s = va_arg (ap, char *); + int length = strlen (s); + if (precision == -1) + precision = length; + if (!left_p) + { + while (width-- > precision) + { + fputc (pad, f); + count++; + } + while (precision > length) + { + fputc (' ', f); + precision--; + width--; + count++; + } + } + while (*s) + { + if (precision-- <= 0) + break; + width--; + fputc (*s++, f); + count++; + } + while (width > 0) + { + width--; + fputc (pad, f); + count++; + } + break; + } + case 'f': + case 'e': + case 'E': + case 'g': + case 'G': + { + double d = va_arg8 (ap, double); + char *s = dtoab (d, 10, 1); + if (c == 'E' || c == 'G') + strupr (s); + int length = strlen (s); + if (precision == -1) + precision = length; + if (!left_p) + { + while (width-- > precision) + { + fputc (pad, f); + count++; + } + while (precision > length) + { + fputc (' ', f); + precision--; + width--; + count++; + } + } + while (*s) + { + if (precision-- <= 0) + break; + width--; + fputc (*s++, f); + count++; + } + while (width > 0) + { + width--; + fputc (pad, f); + count++; + } + break; + } + case 'n': + { + int *n = va_arg (ap, int *); + *n = count; + break; + } + default: + { + eputs ("vfprintf: not supported: %:"); + eputc (c); + eputs ("\n"); + p++; + } + } + p++; + } + va_end (ap); + return 0; +} diff --git a/vendor/mes-libc/stdio/vprintf.c b/vendor/mes-libc/stdio/vprintf.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <stdarg.h> +#include <stdio.h> + +int +vprintf (char const *format, va_list ap) +{ + return vfprintf (stdout, format, ap); +} diff --git a/vendor/mes-libc/stdio/vsnprintf.c b/vendor/mes-libc/stdio/vsnprintf.c @@ -0,0 +1,275 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <ctype.h> +#include <stdarg.h> +#include <string.h> + +int +vsnprintf (char *str, size_t size, char const *format, va_list ap) +{ + char const *p = format; + int count = 0; + char c; + while (*p) + if (*p != '%') + { + c = *p++; + if (count < size) + *str++ = c; + count++; + } + else + { + p++; + c = *p; + int left_p = 0; + int precision = -1; + int width = -1; + if (c == '-') + { + left_p = 1; + c = *++p; + } + char pad = ' '; + if (c == ' ') + { + pad = c; + c = *p++; + } + if (c == '0') + { + pad = c; + c = *p++; + } + if (c >= '0' && c <= '9') + { + width = abtol (&p, 10); + c = *p; + } + else if (c == '*') + { + width = va_arg (ap, long); + c = *++p; + } + if (c == '.') + { + c = *++p; + if (c >= '0' && c <= '9') + { + precision = abtol (&p, 10); + c = *p; + } + else if (c == '*') + { + precision = va_arg (ap, long); + c = *++p; + } + } + if (c == 'l') + c = *++p; + if (c == 'l') + c = *++p; + if (c == 'l') + { + eputs ("vsnprintf: skipping second: l\n"); + c = *++p; + } + switch (c) + { + case '%': + { + if (count < size) + *str++ = *p; + count++; + break; + } + case 'c': + { + c = va_arg (ap, long); + if (count < size) + *str++ = c; + count++; + break; + } + case 'd': + case 'i': + case 'o': + case 'u': + case 'x': + case 'X': + { + long d = va_arg (ap, long); + int base = c == 'o' ? 8 : c == 'x' || c == 'X' ? 16 : 10; + char *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X'); + if (c == 'X') + strupr (s); + int length = strlen (s); + if (precision == -1) + precision = length; + if (!left_p) + { + while (width-- > precision) + { + if (count < size) + *str++ = pad; + count++; + } + while (precision > length) + { + if (count < size) + *str++ = '0'; + precision--; + width--; + count++; + } + } + while (*s) + { + if (precision-- <= 0) + break; + width--; + c = *s++; + if (count < size) + *str++ = c; + count++; + } + while (width > 0) + { + width--; + if (count < size) + *str++ = pad; + count++; + } + break; + } + case 's': + { + char *s = va_arg (ap, char *); + int length = s ? strlen (s) : 0; + if (precision == -1) + precision = length; + if (!left_p) + { + while (width-- > precision) + { + if (count < size) + *str++ = pad; + count++; + } + while (width > length) + { + if (count < size) + *str++ = ' '; + precision--; + width--; + count++; + } + } + while (s && *s) + { + if (precision-- <= 0) + break; + width--; + c = *s++; + if (count < size) + *str++ = c; + count++; + } + while (width > 0) + { + width--; + if (count < size) + *str++ = pad; + count++; + } + break; + } + case 'f': + case 'e': + case 'E': + case 'g': + case 'G': + { + double d = va_arg8 (ap, double); + char *s = dtoab (d, 10, 1); + if (c == 'E' || c == 'G') + strupr (s); + int length = strlen (s); + if (precision == -1) + precision = length; + if (!left_p) + { + while (width-- > precision) + { + if (count < size) + *str++ = pad; + count++; + } + while (precision > length) + { + if (count < size) + *str++ = ' '; + precision--; + width--; + count++; + } + } + while (*s) + { + if (precision-- <= 0) + break; + width--; + c = *s++; + if (count < size) + *str++ = c; + count++; + } + while (width > 0) + { + width--; + if (count < size) + *str++ = pad; + count++; + } + break; + } + case 'n': + { + int *n = va_arg (ap, int *); + *n = count; + break; + } + default: + { + eputs ("vsnprintf: not supported: %:"); + eputc (c); + eputs ("\n"); + p++; + } + } + p++; + } + va_end (ap); + if (count < size) + *str = 0; + return count; +} diff --git a/vendor/mes-libc/stdio/vsprintf.c b/vendor/mes-libc/stdio/vsprintf.c @@ -0,0 +1,28 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <limits.h> +#include <stdarg.h> + +int +vsprintf (char *str, char const *format, va_list ap) +{ + return vsnprintf (str, LONG_MAX, format, ap); +} diff --git a/vendor/mes-libc/stdlib/__exit.c b/vendor/mes-libc/stdlib/__exit.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> + +int +__exit (int status) +{ + exit (status); +} diff --git a/vendor/mes-libc/stdlib/abort.c b/vendor/mes-libc/stdlib/abort.c @@ -0,0 +1,32 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <signal.h> + +void +abort (void) +{ + if (raise (SIGABRT) < 0) /* could not raise SIGABRT */ + { + /* Fail in any way possible */ + unsigned char* x = (unsigned char*) 0; + *x = 2; + } +} diff --git a/vendor/mes-libc/stdlib/atoi.c b/vendor/mes-libc/stdlib/atoi.c @@ -0,0 +1,28 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> + +int +atoi (char const *string) +{ + char const *p = string; + return abtol (&p, 0); +} diff --git a/vendor/mes-libc/stdlib/atol.c b/vendor/mes-libc/stdlib/atol.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> + +int +atol (char const *s) +{ + return atoi (s); +} diff --git a/vendor/mes-libc/stdlib/calloc.c b/vendor/mes-libc/stdlib/calloc.c @@ -0,0 +1,31 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> +#include <string.h> + +void * +calloc (size_t nmemb, size_t size) +{ + size_t count = nmemb * size; + void *p = malloc (count); + memset (p, 0, count); + return p; +} diff --git a/vendor/mes-libc/stdlib/exit.c b/vendor/mes-libc/stdlib/exit.c @@ -0,0 +1,35 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> + +#if !__M2__ +void (*__call_at_exit) (void); +#endif + +void +exit (int code) +{ +#if !__M2__ + if (__call_at_exit) + (*__call_at_exit) (); +#endif + _exit (code); +} diff --git a/vendor/mes-libc/stdlib/free.c b/vendor/mes-libc/stdlib/free.c @@ -0,0 +1,26 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> + +void +free (void *ptr) +{ +} diff --git a/vendor/mes-libc/stdlib/puts.c b/vendor/mes-libc/stdlib/puts.c @@ -0,0 +1,28 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> + +int +puts (char const *s) +{ + oputs (s); + return oputs ("\n"); +} diff --git a/vendor/mes-libc/stdlib/qsort.c b/vendor/mes-libc/stdlib/qsort.c @@ -0,0 +1,80 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright © 2021 Paul Dersey <pdersey@gmail.com> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> +#include <string.h> + +void +qswap (void *a, void *b, size_t size) +{ + char *pa = a; + char *pb = b; + do + { + char tmp = *pa; + *pa++ = *pb; + *pb++ = tmp; + } while (--size > 0); +} + +size_t +qpart (void *base, size_t count, size_t size, int (*compare) (void const *, void const *)) +{ + void *p = base + count * size; + size_t i = 0; + for (size_t j = 0; j < count; j++) + { + int c = compare (base + j * size, p); + if (c < 0) + { +#if 1 //__x86_64__ + qswap (base + i * size, base + j * size, size); +#else + int p1 = base + i * size; + int p2 = base + j * size; + qswap (p1, p2, size); +#endif + i++; + } + else if (c == 0) + i++; + } + if (compare (base + count * size, base + i * size) < 0) + qswap (base + i * size, base + count * size, size); + return i; +} + +void +qsort (void *base, size_t count, size_t size, int (*compare) (void const *, void const *)) +{ + if (count > 1) + { + int p = qpart (base, count - 1, size, compare); + qsort (base, p, size, compare); +#if 1 //__x86_64__ + qsort (base + p * size, count - p, size, compare); +#else + int p1 = base + p * size; + int p2 = count - p; + qsort (p1, p2, size, compare); +#endif + } +} diff --git a/vendor/mes-libc/stdlib/realloc.c b/vendor/mes-libc/stdlib/realloc.c @@ -0,0 +1,34 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> +#include <string.h> + +void * +realloc (void *ptr, size_t size) +{ + void *new = malloc (size); + if (ptr != 0 && new != 0) + { + memcpy (new, ptr, size); + free (ptr); + } + return new; +} diff --git a/vendor/mes-libc/stdlib/strtof.c b/vendor/mes-libc/stdlib/strtof.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> + +float +strtof (char const *string, char **tailptr) +{ + return strtod (string, tailptr); +} diff --git a/vendor/mes-libc/stdlib/strtol.c b/vendor/mes-libc/stdlib/strtol.c @@ -0,0 +1,40 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <stdlib.h> +#include <string.h> + +long +strtol (char const *string, char **tailptr, int base) +{ + if (!strncmp (string, "0x", 2)) + { + string += 2; + base = 16; + } + if (tailptr) + { + *tailptr = (char *) string; + return abtol ((char const **) tailptr, base); + } + char **p = (char **) &string; + return abtol ((char const **) p, base); +} diff --git a/vendor/mes-libc/stdlib/strtoll.c b/vendor/mes-libc/stdlib/strtoll.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> + +long long int +strtoll (char const *string, char **tailptr, int base) +{ + return strtol (string, tailptr, base); +} diff --git a/vendor/mes-libc/stdlib/strtoul.c b/vendor/mes-libc/stdlib/strtoul.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> + +unsigned long +strtoul (char const *string, char **tailptr, int base) +{ + return strtol (string, tailptr, base); +} diff --git a/vendor/mes-libc/stdlib/strtoull.c b/vendor/mes-libc/stdlib/strtoull.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> + +unsigned long long +strtoull (char const *string, char **tailptr, int base) +{ + return strtol (string, tailptr, base); +} diff --git a/vendor/mes-libc/string/memchr.c b/vendor/mes-libc/string/memchr.c @@ -0,0 +1,37 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> + +void * +memchr (void const *block, int c, size_t size) +{ + char const *p = block; + + while (size != 0) + { + size = size - 1; + if (c == p[0]) + return (void*) p; + p = p + 1; + } + + return 0; +} diff --git a/vendor/mes-libc/string/memcmp.c b/vendor/mes-libc/string/memcmp.c @@ -0,0 +1,40 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> + +int +memcmp (void const *s1, void const *s2, size_t size) +{ + if (size == 0) + return 0; + + char const *a = s1; + char const *b = s2; + + while (a[0] == b[0] && size > 1) + { + size = size - 1; + a = a + 1; + b = b + 1; + } + + return a[0] - b[0]; +} diff --git a/vendor/mes-libc/string/memcpy.c b/vendor/mes-libc/string/memcpy.c @@ -0,0 +1,44 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <string.h> + +char * +_memcpy (char *dest, char const *src, size_t n) +{ + char *p = dest; + + while (n != 0) + { + n = n - 1; + dest[0] = src[0]; + dest = dest + 1; + src = src + 1; + } + + return p; +} + +void * +memcpy (void *dest, void const *src, size_t n) +{ + return _memcpy (dest, src, n); +} diff --git a/vendor/mes-libc/string/memmem.c b/vendor/mes-libc/string/memmem.c @@ -0,0 +1,60 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 1997--2015,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * Copyright (C) 1997--2015,2018 Han-Wen Nienhuys <hanwen@xs4all.nl> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> + +/** locate a substring. #memmem# finds the first occurrence of + #needle# in #haystack#. This is not ANSI-C. + + The prototype is not in accordance with the Linux Programmer's + Manual v1.15, but it is with /usr/include/string.h */ + +unsigned char * +_memmem (unsigned char const *haystack, int haystack_len, unsigned char const *needle, int needle_len) +{ + unsigned char const *end_haystack = haystack + haystack_len - needle_len + 1; + unsigned char const *end_needle = needle + needle_len; + + /* Ahhh ... Some minimal lowlevel stuff. This *is* nice; Varation + is the spice of life */ + while (haystack < end_haystack) + { + unsigned char const *subneedle = needle; + unsigned char const *subhaystack = haystack; + while (subneedle < end_needle) + if (*subneedle++ != *subhaystack++) + goto next; + + /* Completed the needle. Gotcha. */ + return (unsigned char *) haystack; + next: + haystack++; + } + return 0; +} + +void * +memmem (void const *haystack, int haystack_len, void const *needle, int needle_len) +{ + unsigned char const *haystack_byte_c = (unsigned char const *) haystack; + unsigned char const *needle_byte_c = (unsigned char const *) needle; + return _memmem (haystack_byte_c, haystack_len, needle_byte_c, needle_len); +} diff --git a/vendor/mes-libc/string/memmove.c b/vendor/mes-libc/string/memmove.c @@ -0,0 +1,33 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> + +void * +memmove (void *dest, void const *src, size_t n) +{ + if (dest < src) + return memcpy (dest, src, n); + char *p = dest + n; + char const *q = src + n; + while (n--) + *--p = *--q; + return dest; +} diff --git a/vendor/mes-libc/string/memset.c b/vendor/mes-libc/string/memset.c @@ -0,0 +1,40 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> + +char * +_memset (char *s, int c, size_t n) +{ + char *p = s; + while (n != 0) + { + n = n - 1; + s[0] = c; + s = s + 1; + } + return p; +} + +void * +memset (void *s, int c, size_t n) +{ + return _memset (s, c, n); +} diff --git a/vendor/mes-libc/string/strcat.c b/vendor/mes-libc/string/strcat.c @@ -0,0 +1,31 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> + +char * +strcat (char *to, char const *from) +{ + char *p = strchr (to, '\0'); + while (*from) + *p++ = *from++; + *p = 0; + return to; +} diff --git a/vendor/mes-libc/string/strchr.c b/vendor/mes-libc/string/strchr.c @@ -0,0 +1,34 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> + +char * +strchr (char const *s, int c) +{ + char const *p = s; + while (*p || !c) + { + if (c == *p) + return (char *) p; + p++; + } + return 0; +} diff --git a/vendor/mes-libc/string/strcmp.c b/vendor/mes-libc/string/strcmp.c @@ -0,0 +1,33 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> + +int +strcmp (char const *a, char const *b) +{ + while (a[0] != 0 && b[0] != 0 && a[0] == b[0]) + { + a = a + 1; + b = b + 1; + } + + return a[0] - b[0]; +} diff --git a/vendor/mes-libc/string/strcpy.c b/vendor/mes-libc/string/strcpy.c @@ -0,0 +1,37 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> + +char * +strcpy (char *dest, char const *src) +{ + char *p = dest; + + while (src[0] != 0) + { + p[0] = src[0]; + p = p + 1; + src = src + 1; + } + p[0] = 0; + + return dest; +} diff --git a/vendor/mes-libc/string/strcspn.c b/vendor/mes-libc/string/strcspn.c @@ -0,0 +1,33 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> + +size_t +strcspn (char const *string, char const *stopset) +{ + char *p = (char *) string; + while (*p) + if (strchr (stopset, *p)) + break; + else + p++; + return p - string; +} diff --git a/vendor/mes-libc/string/strdup.c b/vendor/mes-libc/string/strdup.c @@ -0,0 +1,32 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> +#include <string.h> + +char * +strdup (char const *s) +{ + size_t length = strlen (s) + 1; + char *p = (char *) malloc (length); + if (p) + return memcpy (p, s, length); + return 0; +} diff --git a/vendor/mes-libc/string/strerror.c b/vendor/mes-libc/string/strerror.c @@ -0,0 +1,81 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> +#include <string.h> + +char *sys_errlist[] = { + "error 00", + "error 01", + "error 02", + "error 03", + "error 04", + "error 05", + "error 06", + "error 07", + "error 08", + "error 09", + "error 10", + "error 11", + "error 12", + "error 13", + "error 14", + "error 15", + "error 16", + "error 17", + "error 18", + "error 19", + "error 20", + "error 21", + "error 22", + "error 23", + "error 24", + "error 25", + "error 26", + "error 27", + "error 28", + "error 29", + "error 30", + "error 31", + "error 32", + "error 33", + "error 34", + "error 35", + "error 36", + "error 37", + "error 38", + "error 39", +}; + +int sys_nerr = 39; + +char * +strerror (int errnum) +{ + if (__mes_debug ()) + { + eputs ("strerror errnum="); + eputs (itoa (errnum)); + eputs ("\n"); + } + if (errnum > 0 && errnum <= sys_nerr) + return sys_errlist[errnum]; + return "sterror: unknown error"; +} diff --git a/vendor/mes-libc/string/strlen.c b/vendor/mes-libc/string/strlen.c @@ -0,0 +1,32 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <mes/lib.h> + +size_t +strlen (char const *s) +{ + int i = 0; + + while (s[i] != 0) + i = i + 1; + + return i; +} diff --git a/vendor/mes-libc/string/strncat.c b/vendor/mes-libc/string/strncat.c @@ -0,0 +1,33 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> + +char * +strncat (char *to, char const *from, size_t size) +{ + if (size == 0) + return to; + char *p = strchr (to, '\0'); + while (*from && size-- > 0) + *p++ = *from++; + *p = 0; + return to; +} diff --git a/vendor/mes-libc/string/strncmp.c b/vendor/mes-libc/string/strncmp.c @@ -0,0 +1,37 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> + +int +strncmp (char const *a, char const *b, size_t size) +{ + if (size == 0) + return 0; + + while (a[0] != 0 && b[0] != 0 && a[0] == b[0] && size > 1) + { + size = size - 1; + a = a + 1; + b = b + 1; + } + + return a[0] - b[0]; +} diff --git a/vendor/mes-libc/string/strncpy.c b/vendor/mes-libc/string/strncpy.c @@ -0,0 +1,36 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> + +char * +strncpy (char *to, char const *from, size_t size) +{ + if (size == 0) + return to; + char *p = to; + while (*from && size--) + *p++ = *from++; + if (*from) + size++; + while (size--) + *p++ = 0; + return to; +} diff --git a/vendor/mes-libc/string/strpbrk.c b/vendor/mes-libc/string/strpbrk.c @@ -0,0 +1,33 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> + +char * +strpbrk (char const *string, char const *stopset) +{ + char *p = (char *) string; + while (*p) + if (strchr (stopset, *p)) + break; + else + p++; + return p; +} diff --git a/vendor/mes-libc/string/strrchr.c b/vendor/mes-libc/string/strrchr.c @@ -0,0 +1,40 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> + +char * +strrchr (char const *s, int c) +{ + int n = strlen (s); + if (!n) + return 0; + char const *p = s + n; + if (!*p && !c) + return (char *) p; + p--; + while (n-- && (*p || !c)) + { + if (c == *p) + return (char *) p; + p--; + } + return 0; +} diff --git a/vendor/mes-libc/string/strspn.c b/vendor/mes-libc/string/strspn.c @@ -0,0 +1,33 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> + +size_t +strspn (char const *string, char const *skipset) +{ + char *p = (char *) string; + while (*p) + if (!strchr (skipset, *p)) + break; + else + p++; + return p - string; +} diff --git a/vendor/mes-libc/string/strstr.c b/vendor/mes-libc/string/strstr.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> +#include <string.h> +#include <sys/mman.h> + +char * +strstr (char const *haystack, char const *needle) +{ + return memmem (haystack, strlen (haystack), needle, strlen (needle)); +} diff --git a/vendor/mes-libc/string/strupr.c b/vendor/mes-libc/string/strupr.c @@ -0,0 +1,34 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <ctype.h> +#include <string.h> + +char * +strupr (char *string) +{ + char *p = string; + while (*p) + { + *p = toupper (*p); + p++; + } + return string; +} diff --git a/vendor/mes-libc/unified-libc.c b/vendor/mes-libc/unified-libc.c @@ -0,0 +1,151 @@ +/* unified-libc.c — single translation unit gathering every vendored + * mes-libc .c plus lispcc-syscall.c. The host preprocessor flattens + * the whole thing to libc.flat.c, which cc.scm compiles to libc.P1pp. + * + * Order matters in a few specific places: + * 1. lispcc-syscall.c declares the extern sys_* P1pp labels and + * defines _read / _write / _open3 / close / lseek / brk / unlink / + * _exit. It comes early so later layers see the prototypes. + * 2. mes/globals.c defines errno / __stdin etc. as tentative + * definitions; mes/mes_open.c later assigns them initial values. + * Tentative-then-initialized is a standard C resolution; cc.scm + * follows the C linkage rule (commit 6488cca). + * 3. linux/malloc.c provides the allocator and the __brk pointer + * that posix/sbrk.c re-exports. + * + * Everything else is order-independent — each mes .c is a self-contained + * function or two with its own header includes. + */ + +#include <mes/lib.h> + +/* ---- low-level: P1pp syscall wrappers + thin posix glue --------- */ +#include "lispcc-syscall.c" + +/* ---- ctype ------------------------------------------------------ */ +#include "ctype/isalnum.c" +#include "ctype/isalpha.c" +#include "ctype/isascii.c" +#include "ctype/iscntrl.c" +#include "ctype/isdigit.c" +#include "ctype/isgraph.c" +#include "ctype/islower.c" +#include "ctype/isnumber.c" +#include "ctype/isprint.c" +#include "ctype/ispunct.c" +#include "ctype/isspace.c" +#include "ctype/isupper.c" +#include "ctype/isxdigit.c" +#include "ctype/tolower.c" +#include "ctype/toupper.c" + +/* ---- string ----------------------------------------------------- */ +#include "string/memchr.c" +#include "string/memcmp.c" +#include "string/memcpy.c" +#include "string/memmem.c" +#include "string/memmove.c" +#include "string/memset.c" +#include "string/strcat.c" +#include "string/strchr.c" +#include "string/strcmp.c" +#include "string/strcpy.c" +#include "string/strcspn.c" +#include "string/strdup.c" +#include "string/strerror.c" +#include "string/strlen.c" +#include "string/strncat.c" +#include "string/strncmp.c" +#include "string/strncpy.c" +#include "string/strpbrk.c" +#include "string/strrchr.c" +#include "string/strspn.c" +#include "string/strstr.c" +#include "string/strupr.c" + +/* ---- mes runtime ------------------------------------------------ */ +#include "mes/globals.c" +#include "mes/cast.c" +#include "mes/__assert_fail.c" +#include "mes/abtol.c" +#include "mes/dtoab.c" +#include "mes/eputc.c" +#include "mes/eputs.c" +#include "mes/fdgetc.c" +#include "mes/fdgets.c" +#include "mes/fdputc.c" +#include "mes/fdputs.c" +#include "mes/fdungetc.c" +#include "mes/__buffered_read.c" +#include "mes/__init_io.c" +#include "mes/__mes_debug.c" +#include "mes/itoa.c" +#include "mes/ltoa.c" +#include "mes/ltoab.c" +#include "mes/mes_open.c" +#include "mes/ntoab.c" +#include "mes/oputc.c" +#include "mes/oputs.c" +#include "mes/search-path.c" +#include "mes/ultoa.c" +#include "mes/utoa.c" + +/* ---- stdlib ----------------------------------------------------- */ +#include "stdlib/__exit.c" +#include "stdlib/abort.c" +#include "stdlib/atoi.c" +#include "stdlib/atol.c" +#include "stdlib/calloc.c" +#include "stdlib/exit.c" +#include "stdlib/free.c" +#include "stdlib/puts.c" +#include "stdlib/qsort.c" +#include "stdlib/realloc.c" +#include "stdlib/strtof.c" +#include "stdlib/strtol.c" +#include "stdlib/strtoll.c" +#include "stdlib/strtoul.c" +#include "stdlib/strtoull.c" + +/* ---- linux (allocator only; the rest replaced by lispcc-syscall.c) */ +#include "linux/malloc.c" + +/* ---- posix ------------------------------------------------------ */ +#include "posix/buffered-read.c" +#include "posix/execvp.c" +#include "posix/getcwd.c" +#include "posix/getenv.c" +#include "posix/open.c" +#include "posix/sbrk.c" +#include "posix/write.c" + +/* ---- stdio ------------------------------------------------------ */ +#include "stdio/clearerr.c" +#include "stdio/fclose.c" +#include "stdio/fdopen.c" +#include "stdio/feof.c" +#include "stdio/ferror.c" +#include "stdio/fflush.c" +#include "stdio/fgetc.c" +#include "stdio/fgets.c" +#include "stdio/fileno.c" +#include "stdio/fopen.c" +#include "stdio/fprintf.c" +#include "stdio/fputc.c" +#include "stdio/fputs.c" +#include "stdio/fread.c" +#include "stdio/fseek.c" +#include "stdio/ftell.c" +#include "stdio/fwrite.c" +#include "stdio/getc.c" +#include "stdio/perror.c" +#include "stdio/printf.c" +#include "stdio/putc.c" +#include "stdio/remove.c" +#include "stdio/snprintf.c" +#include "stdio/sprintf.c" +#include "stdio/ungetc.c" +#include "stdio/vfprintf.c" +#include "stdio/vprintf.c" +#include "stdio/vsnprintf.c" +#include "stdio/vsprintf.c"