diff --git a/Makefile b/Makefile index 41ab868ed..24b380bc9 100644 --- a/Makefile +++ b/Makefile @@ -59,8 +59,9 @@ # # build/config.mk -SHELL = build/bootstrap/cocmd.com -HOSTS ?= freebsd openbsd netbsd rhel7 rhel5 win7 win10 xnu +SHELL = build/bootstrap/cocmd.com +HOSTS ?= freebsd openbsd netbsd rhel7 rhel5 win7 win10 xnu +MAKEFLAGS += --no-builtin-rules .SUFFIXES: .DELETE_ON_ERROR: @@ -313,6 +314,7 @@ COSMOPOLITAN_OBJECTS = \ LIBC_NEXGEN32E COSMOPOLITAN_HEADERS = \ + APE \ LIBC \ LIBC_ALG \ LIBC_BITS \ @@ -350,10 +352,11 @@ COSMOPOLITAN_HEADERS = \ o/$(MODE)/cosmopolitan.a: \ $(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_A_OBJS)) -o/cosmopolitan.h: \ - o/$(MODE)/tool/build/rollup.com \ - libc/integral/normalize.inc \ - $(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_HDRS)) +o/cosmopolitan.h: \ + o/$(MODE)/tool/build/rollup.com \ + libc/integral/normalize.inc \ + $(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_HDRS)) \ + $(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_INCS)) $(file >$@.args,libc/integral/normalize.inc $(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_HDRS))) @$(COMPILE) -AROLLUP -T$@ o/$(MODE)/tool/build/rollup.com @$@.args >$@ diff --git a/ape/ape.mk b/ape/ape.mk index 14b0880b3..661bd2d0f 100644 --- a/ape/ape.mk +++ b/ape/ape.mk @@ -15,38 +15,38 @@ PKGS += APE -APE = o/$(MODE)/ape/ape.o \ +APE = o/$(MODE)/ape/ape.o \ o/$(MODE)/ape/ape.lds -APE_NO_MODIFY_SELF = \ - o/$(MODE)/ape/ape.lds \ +APE_NO_MODIFY_SELF = \ + o/$(MODE)/ape/ape.lds \ o/$(MODE)/ape/ape-no-modify-self.o -APE_COPY_SELF = \ - o/$(MODE)/ape/ape.lds \ +APE_COPY_SELF = \ + o/$(MODE)/ape/ape.lds \ o/$(MODE)/ape/ape-copy-self.o -APELINK = \ - $(COMPILE) \ - -ALINK.ape \ - $(LINK) \ - $(LINKARGS) \ +APELINK = \ + $(COMPILE) \ + -ALINK.ape \ + $(LINK) \ + $(LINKARGS) \ $(OUTPUT_OPTION) -APE_LOADER_FLAGS = \ - -DNDEBUG \ - -iquote. \ - -Wall \ - -Wextra \ - -fpie \ - -Os \ - -ffreestanding \ - -mgeneral-regs-only \ - -mno-red-zone \ - -fno-ident \ - -fno-gnu-unique \ - -c \ - $(OUTPUT_OPTION) \ +APE_LOADER_FLAGS = \ + -DNDEBUG \ + -iquote. \ + -Wall \ + -Wextra \ + -fpie \ + -Os \ + -ffreestanding \ + -mgeneral-regs-only \ + -mno-red-zone \ + -fno-ident \ + -fno-gnu-unique \ + -c \ + $(OUTPUT_OPTION) \ $< APE_FILES := $(wildcard ape/*.*) @@ -58,32 +58,76 @@ APE_SRCS = $(APE_SRCS_C) $(APE_SRCS_S) APE_OBJS = $(APE_SRCS_S:%.S=o/$(MODE)/%.o) APE_CHECKS = $(APE_HDRS:%=o/%.ok) -o/$(MODE)/ape/ape.lds: \ - ape/ape.lds \ - ape/macros.internal.h \ - libc/dce.h \ +o/$(MODE)/ape/ape.lds: \ + ape/ape.lds \ + ape/macros.internal.h \ + ape/relocations.h \ + libc/bits/bits.h \ + libc/calls/struct/timespec.h \ + libc/dce.h \ + libc/elf/def.h \ + libc/elf/pf2prot.internal.h \ + libc/macros.internal.h \ + libc/nt/pedef.internal.h \ + libc/str/str.h \ libc/zip.h -o/ape/idata.inc: \ - ape/idata.internal.h \ +o/ape/idata.inc: \ + ape/idata.internal.h \ ape/relocations.h -o/$(MODE)/ape/ape-no-modify-self.o: \ - ape/ape.S \ +o/$(MODE)/ape/ape-no-modify-self.o: \ + ape/ape.S \ + ape/macros.internal.h \ + ape/notice.inc \ + ape/relocations.h \ + libc/dce.h \ + libc/elf/def.h \ + libc/intrin/asancodes.h \ + libc/macho.internal.h \ + libc/macros-cpp.internal.inc \ + libc/macros.internal.h \ + libc/macros.internal.inc \ + libc/nexgen32e/uart.internal.h \ + libc/nexgen32e/vidya.internal.h \ + libc/nt/pedef.internal.h \ + libc/runtime/e820.internal.h \ + libc/runtime/mman.internal.h \ + libc/runtime/pc.internal.h \ + libc/runtime/symbolic.h \ + libc/sysv/consts/prot.h \ o/$(MODE)/ape/ape.elf - @$(COMPILE) \ - -AOBJECTIFY.S \ - $(OBJECTIFY.S) \ - $(OUTPUT_OPTION) \ - -DAPE_NO_MODIFY_SELF \ + @$(COMPILE) \ + -AOBJECTIFY.S \ + $(OBJECTIFY.S) \ + $(OUTPUT_OPTION) \ + -DAPE_NO_MODIFY_SELF \ -DAPE_LOADER='"o/$(MODE)/ape/ape.elf"' $< -o/$(MODE)/ape/ape-copy-self.o: \ - ape/ape.S - @$(COMPILE) \ - -AOBJECTIFY.S \ - $(OBJECTIFY.S) \ - $(OUTPUT_OPTION) \ +o/$(MODE)/ape/ape-copy-self.o: \ + ape/ape.S \ + ape/macros.internal.h \ + ape/notice.inc \ + ape/relocations.h \ + libc/dce.h \ + libc/elf/def.h \ + libc/intrin/asancodes.h \ + libc/macho.internal.h \ + libc/macros-cpp.internal.inc \ + libc/macros.internal.h \ + libc/macros.internal.inc \ + libc/nexgen32e/uart.internal.h \ + libc/nexgen32e/vidya.internal.h \ + libc/nt/pedef.internal.h \ + libc/runtime/e820.internal.h \ + libc/runtime/mman.internal.h \ + libc/runtime/pc.internal.h \ + libc/runtime/symbolic.h \ + libc/sysv/consts/prot.h + @$(COMPILE) \ + -AOBJECTIFY.S \ + $(OBJECTIFY.S) \ + $(OUTPUT_OPTION) \ -DAPE_NO_MODIFY_SELF $< o/$(MODE)/ape/loader.o: ape/loader.c @@ -103,23 +147,23 @@ o/$(MODE)/ape/loader-xnu-clang.asm: ape/loader.c o/$(MODE)/ape/ape.elf: o/$(MODE)/ape/ape.elf.dbg o/$(MODE)/ape/ape.macho: o/$(MODE)/ape/ape.macho.dbg -o/$(MODE)/ape/ape.elf.dbg: \ - o/$(MODE)/ape/loader.o \ - o/$(MODE)/ape/loader-elf.o \ +o/$(MODE)/ape/ape.elf.dbg: \ + o/$(MODE)/ape/loader.o \ + o/$(MODE)/ape/loader-elf.o \ ape/loader.lds @$(ELFLINK) -z max-page-size=0x10 -o/$(MODE)/ape/ape.macho.dbg: \ - o/$(MODE)/ape/loader-xnu.o \ - o/$(MODE)/ape/loader-macho.o \ +o/$(MODE)/ape/ape.macho.dbg: \ + o/$(MODE)/ape/loader-xnu.o \ + o/$(MODE)/ape/loader-macho.o \ ape/loader-macho.lds @$(ELFLINK) -z max-page-size=0x10 .PHONY: o/$(MODE)/ape -o/$(MODE)/ape: $(APE_CHECKS) \ - o/$(MODE)/ape/ape.o \ - o/$(MODE)/ape/ape.lds \ - o/$(MODE)/ape/ape.elf \ - o/$(MODE)/ape/ape.macho \ - o/$(MODE)/ape/ape-copy-self.o \ +o/$(MODE)/ape: $(APE_CHECKS) \ + o/$(MODE)/ape/ape.o \ + o/$(MODE)/ape/ape.lds \ + o/$(MODE)/ape/ape.elf \ + o/$(MODE)/ape/ape.macho \ + o/$(MODE)/ape/ape-copy-self.o \ o/$(MODE)/ape/ape-no-modify-self.o diff --git a/build/bootstrap/package.com b/build/bootstrap/package.com index b5b0e8790..d07ae145b 100755 Binary files a/build/bootstrap/package.com and b/build/bootstrap/package.com differ diff --git a/build/rules.mk b/build/rules.mk index 503136ce7..e1e022e04 100644 --- a/build/rules.mk +++ b/build/rules.mk @@ -29,7 +29,6 @@ o/%.o: %.cc ; @$(COMPILE) -AOBJECTIFY.cxx $(OBJECTIFY.cxx o/%.o: o/%.cc ; @$(COMPILE) -AOBJECTIFY.cxx $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $< o/%.lds: %.lds ; @$(COMPILE) -APREPROCESS $(PREPROCESS.lds) $(OUTPUT_OPTION) $< o/%.inc: %.h ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) -D__ASSEMBLER__ -P $< -o/%.h.ok: %.h ; @$(COMPILE) -ACHECK.h $(COMPILE.c) -xc -g0 -o $@ $< o/%.okk: % ; @$(COMPILE) -ACHECK.h $(COMPILE.cxx) -xc++ -g0 -o $@ $< o/%.greg.o: %.greg.c ; @$(COMPILE) -AOBJECTIFY.greg $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $< o/%.zip.o: o/% ; @$(COMPILE) -AZIPOBJ $(ZIPOBJ) $(ZIPOBJ_FLAGS) $(OUTPUT_OPTION) $< @@ -58,8 +57,6 @@ o/$(MODE)/%.s: o/$(MODE)/%.i ; @$(COMPILE) -ACOMPILE.i $(COMPILE.i) $(OUTP o/$(MODE)/%.o: %.cc ; @$(COMPILE) -AOBJECTIFY.cxx $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $< o/$(MODE)/%.o: o/$(MODE)/%.cc ; @$(COMPILE) -AOBJECTIFY.cxx $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $< o/$(MODE)/%.lds: %.lds ; @$(COMPILE) -APREPROCESS $(PREPROCESS.lds) $(OUTPUT_OPTION) $< -o/$(MODE)/%.h.ok: %.h ; @$(COMPILE) -ACHECK.h $(COMPILE.c) -xc -g0 -o $@ $< -o/$(MODE)/%.hh.ok: %.hh ; @$(COMPILE) -ACHECK.h $(COMPILE.cxx) -xc++ -g0 -o $@ $< o/$(MODE)/%.okk: % ; @$(COMPILE) -ACHECK.h $(COMPILE.cxx) -xc++ -g0 -o $@ $< o/$(MODE)/%.cxx.o: %.c ; @$(COMPILE) -AOBJECTIFY.cxx $(OBJECTIFY.cxx) -xc++ $(OUTPUT_OPTION) $< o/$(MODE)/%.o: %.greg.c ; @$(COMPILE) -AOBJECTIFY.greg $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $< @@ -104,3 +101,19 @@ o/$(MODE)/%.lua: %.lua o/$(MODE)/third_party/lua/luac.com o/$(MODE)/%.lua.runs: %.lua o/$(MODE)/tool/net/redbean.com @$(COMPILE) -ALUA -tT$@ o/$(MODE)/tool/net/redbean.com $(LUAFLAGS) -i $< + +o/$(MODE)/%: o/$(MODE)/%.com o/$(MODE)/tool/build/cp.com o/$(MODE)/tool/build/assimilate.com + @$(COMPILE) -ACP -T$@ o/$(MODE)/tool/build/cp.com $< $@ + @$(COMPILE) -AASSIMILATE -T$@ o/$(MODE)/tool/build/assimilate.com $@ + +# TODO(jart): find a way to generate dependencies +# or alternatively disable sandboxing +o/%.h.ok: %.h + @$(COMPILE) -ACHECK.h -T$@ build/bootstrap/touch.com $@ +# @$(COMPILE) -ACHECK.h $(COMPILE.c) -xc -g0 -o $@ $< +o/$(MODE)/%.h.ok: %.h + @$(COMPILE) -ACHECK.h -T$@ build/bootstrap/touch.com $@ +# @$(COMPILE) -ACHECK.h $(COMPILE.c) -xc -g0 -o $@ $< +o/$(MODE)/%.hh.ok: %.hh + @$(COMPILE) -ACHECK.h -T$@ build/bootstrap/touch.com $@ +# @$(COMPILE) -ACHECK.h $(COMPILE.cxx) -xc++ -g0 -o $@ $< diff --git a/libc/dce.h b/libc/dce.h index 9b80e4d06..04b102d20 100644 --- a/libc/dce.h +++ b/libc/dce.h @@ -1,6 +1,5 @@ #ifndef COSMOPOLITAN_LIBC_DCE_H_ #define COSMOPOLITAN_LIBC_DCE_H_ -#include "libc/nexgen32e/kcpuids.h" /*─────────────────────────────────────────────────────────────────────────────╗ │ cosmopolitan § autotune » dead code elimination │ ╚─────────────────────────────────────────────────────────────────────────────*/ diff --git a/libc/integral/lp64arg.inc b/libc/integral/lp64arg.inc index 669ec7c04..b5c53dd7c 100644 --- a/libc/integral/lp64arg.inc +++ b/libc/integral/lp64arg.inc @@ -1,4 +1,15 @@ -#include "libc/runtime/valist.h" +/* variadic arguments for chibicc */ + +/* */ +struct __va_list { + uint32_t gp_offset; + uint32_t fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +/* */ + +void *__va_arg(struct __va_list *, size_t, unsigned, unsigned); #define __GNUC_VA_LIST 1 #define __gnuc_va_list va_list diff --git a/libc/mem/unveil.c b/libc/mem/unveil.c index d774d3df8..bb7a3f02c 100644 --- a/libc/mem/unveil.c +++ b/libc/mem/unveil.c @@ -34,6 +34,7 @@ #include "libc/mem/mem.h" #include "libc/nexgen32e/threaded.h" #include "libc/runtime/internal.h" +#include "libc/runtime/runtime.h" #include "libc/str/path.h" #include "libc/str/str.h" #include "libc/sysv/consts/at.h" @@ -124,7 +125,9 @@ static int unveil_init(void) { if (errno == EOPNOTSUPP) errno = ENOSYS; return -1; } - if (rc < 2) State.fs_mask &= ~LANDLOCK_ACCESS_FS_REFER; + if (rc < 2) { + State.fs_mask &= ~LANDLOCK_ACCESS_FS_REFER; + } const struct landlock_ruleset_attr attr = { .handled_access_fs = State.fs_mask, }; @@ -326,6 +329,7 @@ static int sys_unveil_linux(const char *path, const char *permissions) { * @raise EPERM if unveil() is called after locking * @note on Linux this function requires Linux Kernel 5.13+ * @see [1] https://docs.kernel.org/userspace-api/landlock.html + * @threadsafe */ int unveil(const char *path, const char *permissions) { int rc; diff --git a/libc/runtime/enable_tls.c b/libc/runtime/enable_tls.c index 7bd2d3f24..7f154ba3d 100644 --- a/libc/runtime/enable_tls.c +++ b/libc/runtime/enable_tls.c @@ -59,7 +59,16 @@ extern unsigned char __tls_add_nt_rax[]; _Alignas(long) static char __static_tls[5008]; /** - * Enables thread local storage. + * Enables thread local storage for main process. + * + * %fs Linux/BSDs + * │ + * _Thread_local │ __get_tls() + * ┌───┬──────────┬──────────┼───┐ + * │pad│ .tdata │ .tbss │tib│ + * └───┴──────────┴──────────┼───┘ + * │ + * Windows/Mac %gs * * This function is always called by the core runtime to guarantee TLS * is always available to your program. You must build your code using @@ -85,19 +94,6 @@ _Alignas(long) static char __static_tls[5008]; * and your `errno` variable also won't be thread safe anymore. */ privileged void __enable_tls(void) { - STRACE("__enable_tls()"); - - // allocate tls memory for main process - // - // %fs Linux/BSDs - // │ - // _Thread_local │ __get_tls() - // ┌───┬──────────┬──────────┼───┐ - // │pad│ .tdata │ .tbss │tib│ - // └───┴──────────┴──────────┼───┘ - // │ - // Windows/Mac %gs - // size_t siz; cthread_t tib; char *mem, *tls; @@ -179,11 +175,6 @@ privileged void __enable_tls(void) { // // 65 48 8b 0R4 25 30 00 00 00 mov %gs:0x30,%R // - // Whereas on Windows we'll replace it with this: - // - // 0f 1f 40 00 fatnop4 - // e8 xx xx xx xx call __tls_mov_nt_%R - // // Since we have no idea where the TLS instructions exist in the // binary, we need to disassemble the whole program image. This'll // potentially take a few milliseconds for some larger programs. @@ -264,6 +255,5 @@ privileged void __enable_tls(void) { } // we are now allowed to use tls - // setting this variable __tls_enabled = true; } diff --git a/libc/runtime/valist.c b/libc/runtime/valist.c index ea8e764d2..6be81ce3b 100644 --- a/libc/runtime/valist.c +++ b/libc/runtime/valist.c @@ -17,7 +17,15 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/macros.internal.h" -#include "libc/runtime/valist.h" + +/* */ +struct __va_list { + uint32_t gp_offset; + uint32_t fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +/* */ static void *__va_arg_mem(struct __va_list *ap, size_t sz, size_t align) { void *r = (void *)ROUNDUP((intptr_t)ap->overflow_arg_area, align); diff --git a/libc/runtime/valist.h b/libc/runtime/valist.h deleted file mode 100644 index 73ae2cc2c..000000000 --- a/libc/runtime/valist.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_RUNTIME_VALIST_H_ -#define COSMOPOLITAN_LIBC_RUNTIME_VALIST_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -struct __va_list { - uint32_t gp_offset; - uint32_t fp_offset; - void *overflow_arg_area; - void *reg_save_area; -}; - -void *__va_arg(struct __va_list *, size_t, unsigned, unsigned); - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_RUNTIME_VALIST_H_ */ diff --git a/libc/sock/syslog.c b/libc/sock/syslog.c index 5bb1eec61..414c23e04 100644 --- a/libc/sock/syslog.c +++ b/libc/sock/syslog.c @@ -27,7 +27,6 @@ #include "libc/macros.internal.h" #include "libc/nt/events.h" #include "libc/nt/runtime.h" -#include "libc/runtime/valist.h" #include "libc/sock/sock.h" #include "libc/sock/syslog.h" #include "libc/stdio/stdio.h" diff --git a/libc/testlib/testlib.mk b/libc/testlib/testlib.mk index 9f71f865d..52427f57d 100644 --- a/libc/testlib/testlib.mk +++ b/libc/testlib/testlib.mk @@ -24,6 +24,7 @@ LIBC_TESTLIB_A_HDRS = \ libc/testlib/fastrandomstring.h \ libc/testlib/hyperion.h \ libc/testlib/moby.h \ + libc/testlib/ugly.h \ libc/testlib/testlib.h LIBC_TESTLIB_A_SRCS_S = \ diff --git a/test/libc/calls/execve_test.c b/test/libc/calls/execve_test.c deleted file mode 100644 index 5a083707e..000000000 --- a/test/libc/calls/execve_test.c +++ /dev/null @@ -1,363 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2022 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/assert.h" -#include "libc/calls/calls.h" -#include "libc/dce.h" -#include "libc/intrin/kprintf.h" -#include "libc/mem/io.h" -#include "libc/runtime/runtime.h" -#include "libc/stdio/stdio.h" -#include "libc/sysv/consts/o.h" -#include "libc/testlib/ezbench.h" -#include "libc/testlib/testlib.h" - -STATIC_YOINK("zip_uri_support"); - -int ws, pid; -char testlib_enable_tmp_setup_teardown; - -__attribute__((__constructor__)) static void init(void) { - pledge("stdio rpath wpath cpath fattr proc exec", 0); - errno = 0; -} - -bool UsingBinfmtMisc(void) { - return fileexists("/proc/sys/fs/binfmt_misc/APE"); -} - -// see: #431 -// todo(jart): figure out what is wrong with github actions -// thetanil: same issue reproducible on my debian 5.10 -// bool HasMzHeader(const char *path) { -// char buf[2] = {0}; -// open(path, O_RDONLY); -// read(3, buf, 2); -// close(3); -// return buf[0] == 'M' && buf[1] == 'Z'; -// } - -void Extract(const char *from, const char *to, int mode) { - ASSERT_SYS(0, 3, open(from, O_RDONLY), "%s %s", from, to); - ASSERT_SYS(0, 4, creat(to, mode)); - ASSERT_NE(-1, _copyfd(3, 4, -1)); - EXPECT_SYS(0, 0, close(4)); - EXPECT_SYS(0, 0, close(3)); -} - -void SetUp(void) { - ASSERT_SYS(0, 0, mkdir("tmp", 0755)); - ASSERT_SYS(0, 0, mkdir("bin", 0755)); - Extract("/zip/tiny64.elf", "bin/tiny64.elf", 0755); - // Extract("/zip/pylife.com", "bin/pylife.com", 0755); - Extract("/zip/life-nomod.com", "bin/life-nomod.com", 0755); - Extract("/zip/life-classic.com", "bin/life-classic.com", 0755); - setenv("TMPDIR", "tmp", true); - if (IsOpenbsd()) { - // printf is in /usr/bin/printf on openbsd... - setenv("PATH", "/bin:/usr/bin", true); - } else if (!IsWindows()) { - setenv("PATH", "/bin", true); - } -} - -//////////////////////////////////////////////////////////////////////////////// - -TEST(execve, system_elf) { - if (!IsLinux()) return; - ws = system("bin/tiny64.elf"); - EXPECT_TRUE(WIFEXITED(ws)); - EXPECT_EQ(42, WEXITSTATUS(ws)); - system("cp bin/tiny64.elf /tmp/tiny64.elf"); -} - -TEST(execve, fork_elf) { - if (!IsLinux()) return; - ASSERT_NE(-1, (pid = fork())); - if (!pid) { - execl("bin/tiny64.elf", "bin/tiny64.elf", 0); - _Exit(127); - } - ASSERT_EQ(pid, wait(&ws)); - EXPECT_TRUE(WIFEXITED(ws)); - EXPECT_EQ(42, WEXITSTATUS(ws)); -} - -TEST(execve, vfork_elf) { - if (!IsLinux()) return; - ASSERT_NE(-1, (pid = vfork())); - if (!pid) { - execl("bin/tiny64.elf", "bin/tiny64.elf", 0); - _Exit(127); - } - ASSERT_EQ(pid, wait(&ws)); - EXPECT_TRUE(WIFEXITED(ws)); - EXPECT_EQ(42, WEXITSTATUS(ws)); -} - -//////////////////////////////////////////////////////////////////////////////// - -TEST(execve, system_apeNoModifySelf) { - if (IsWindows()) return; // todo(jart): wut - for (int i = 0; i < 2; ++i) { - ws = system("bin/life-nomod.com"); - EXPECT_TRUE(WIFEXITED(ws)); - EXPECT_EQ(42, WEXITSTATUS(ws)); - // see: HasMzHeader() - // EXPECT_TRUE(HasMzHeader("bin/life-nomod.com")); - system("cp bin/life-nomod.com /tmp/life-nomod.com"); - } -} - -TEST(execve, fork_apeNoModifySelf) { - for (int i = 0; i < 2; ++i) { - ASSERT_NE(-1, (pid = fork())); - if (!pid) { - execl("bin/life-nomod.com", "bin/life-nomod.com", 0); - _Exit(127); - } - ASSERT_EQ(pid, wait(&ws)); - EXPECT_TRUE(WIFEXITED(ws)); - EXPECT_EQ(42, WEXITSTATUS(ws)); - // see: HasMzHeader() - // EXPECT_TRUE(HasMzHeader("bin/life-nomod.com")); - } -} - -TEST(execve, vfork_apeNoModifySelf) { - for (int i = 0; i < 2; ++i) { - ASSERT_NE(-1, (pid = vfork())); - if (!pid) { - execl("bin/life-nomod.com", "bin/life-nomod.com", 0); - _Exit(127); - } - ASSERT_EQ(pid, wait(&ws)); - EXPECT_TRUE(WIFEXITED(ws)); - EXPECT_EQ(42, WEXITSTATUS(ws)); - // see: HasMzHeader() - // EXPECT_TRUE(HasMzHeader("bin/life-nomod.com")); - } -} - -//////////////////////////////////////////////////////////////////////////////// - -TEST(execve, system_apeClassic) { - if (IsWindows()) return; // todo(jart): wut - for (int i = 0; i < 2; ++i) { - system("bin/life-classic.com"); - EXPECT_TRUE(WIFEXITED(ws)); - EXPECT_EQ(42, WEXITSTATUS(ws)); - // see: HasMzHeader() - // if (UsingBinfmtMisc()) { - // EXPECT_TRUE(HasMzHeader("bin/life-classic.com")); - // } - } -} - -TEST(execve, fork_apeClassic) { - for (int i = 0; i < 2; ++i) { - ASSERT_NE(-1, (pid = fork())); - if (!pid) { - execl("bin/life-classic.com", "bin/life-classic.com", 0); - _Exit(127); - } - ASSERT_EQ(pid, wait(&ws)); - EXPECT_TRUE(WIFEXITED(ws)); - EXPECT_EQ(42, WEXITSTATUS(ws)); - // see: HasMzHeader() - // if (UsingBinfmtMisc()) { - // EXPECT_TRUE(HasMzHeader("bin/life-classic.com")); - // } - } -} - -TEST(execve, vfork_apeClassic) { - for (int i = 0; i < 2; ++i) { - ASSERT_NE(-1, (pid = vfork())); - if (!pid) { - execl("bin/life-classic.com", "bin/life-classic.com", 0); - _Exit(127); - } - ASSERT_EQ(pid, wait(&ws)); - EXPECT_TRUE(WIFEXITED(ws)); - EXPECT_EQ(42, WEXITSTATUS(ws)); - // see: HasMzHeader() - // if (UsingBinfmtMisc()) { - // EXPECT_TRUE(HasMzHeader("bin/life-classic.com")); - // } - } -} - -//////////////////////////////////////////////////////////////////////////////// -#if 0 // not worth depending on THIRD_PARTY_PYTHON for this test - -TEST(execve, system_apeNoMod3mb) { - if (IsWindows()) return; // todo(jart): wut - for (int i = 0; i < 2; ++i) { - system("bin/pylife.com"); - EXPECT_TRUE(WIFEXITED(ws)); - EXPECT_EQ(42, WEXITSTATUS(ws)); - EXPECT_TRUE(HasMzHeader("bin/pylife.com")); - } -} - -TEST(execve, fork_apeNoMod3mb) { - for (int i = 0; i < 2; ++i) { - ASSERT_NE(-1, (pid = fork())); - if (!pid) { - execl("bin/pylife.com", "bin/pylife.com", 0); - _Exit(127); - } - ASSERT_EQ(pid, wait(&ws)); - EXPECT_TRUE(WIFEXITED(ws)); - EXPECT_EQ(42, WEXITSTATUS(ws)); - EXPECT_TRUE(HasMzHeader("bin/pylife.com")); - } -} - -TEST(execve, vfork_apeNoMod3mb) { - for (int i = 0; i < 2; ++i) { - ASSERT_NE(-1, (pid = vfork())); - if (!pid) { - execl("bin/pylife.com", "bin/pylife.com", 0); - _Exit(127); - } - ASSERT_EQ(pid, wait(&ws)); - EXPECT_TRUE(WIFEXITED(ws)); - EXPECT_EQ(42, WEXITSTATUS(ws)); - EXPECT_TRUE(HasMzHeader("bin/pylife.com")); - } -} - -#endif -//////////////////////////////////////////////////////////////////////////////// - -void SystemElf(void) { - system("bin/tiny64.elf"); -} - -void ForkElf(void) { - if (!(pid = fork())) { - execl("bin/tiny64.elf", "bin/tiny64.elf", 0); - _Exit(127); - } - waitpid(pid, 0, 0); -} - -void VforkElf(void) { - if (!(pid = vfork())) { - execl("bin/tiny64.elf", "bin/tiny64.elf", 0); - _Exit(127); - } - waitpid(pid, 0, 0); -} - -//////////////////////////////////////////////////////////////////////////////// - -void SystemNoMod(void) { - system("bin/life-nomod.com"); -} - -void ForkNoMod(void) { - if (!(pid = fork())) { - execl("bin/life-nomod.com", "bin/life-nomod.com", 0); - _Exit(127); - } - waitpid(pid, 0, 0); -} - -void VforkNoMod(void) { - if (!(pid = vfork())) { - execl("bin/life-nomod.com", "bin/life-nomod.com", 0); - _Exit(127); - } - waitpid(pid, 0, 0); -} - -//////////////////////////////////////////////////////////////////////////////// - -void SystemClassic(void) { - system("bin/life-classic.com"); -} - -void ForkClassic(void) { - if (!(pid = fork())) { - execl("bin/life-classic.com", "bin/life-classic.com", 0); - _Exit(127); - } - waitpid(pid, 0, 0); -} - -void VforkClassic(void) { - if (!(pid = vfork())) { - execl("bin/life-classic.com", "bin/life-classic.com", 0); - _Exit(127); - } - waitpid(pid, 0, 0); -} - -//////////////////////////////////////////////////////////////////////////////// - -void SystemNoMod3mb(void) { - system("bin/life-nomod.com"); -} - -void ForkNoMod3mb(void) { - if (!(pid = fork())) { - execl("bin/life-nomod.com", "bin/life-nomod.com", 0); - _Exit(127); - } - waitpid(pid, 0, 0); -} - -void VforkNoMod3mb(void) { - if (!(pid = vfork())) { - execl("bin/life-nomod.com", "bin/life-nomod.com", 0); - _Exit(127); - } - waitpid(pid, 0, 0); -} - -BENCH(execve, bench1) { - if (IsLinux()) { - EZBENCH2("ForkElf", donothing, ForkElf()); - EZBENCH2("VforkElf", donothing, VforkElf()); - EZBENCH2("SystemElf", donothing, SystemElf()); - kprintf("\n"); - } - - EZBENCH2("ForkApeClassic", donothing, ForkClassic()); - EZBENCH2("VforkApeClassic", donothing, VforkClassic()); - if (!IsWindows()) { - EZBENCH2("SystemApeClassic", donothing, SystemClassic()); - } - kprintf("\n"); - - EZBENCH2("ForkApeNoMod", donothing, ForkNoMod()); - EZBENCH2("VforkApeNoMod", donothing, VforkNoMod()); - if (!IsWindows()) { - EZBENCH2("SystemApeNoMod", donothing, SystemNoMod()); - } - kprintf("\n"); - - EZBENCH2("ForkNoMod3mb", donothing, ForkNoMod3mb()); - EZBENCH2("VforkNoMod3mb", donothing, VforkNoMod3mb()); - if (!IsWindows()) { - EZBENCH2("SystemNoMod3mb", donothing, SystemNoMod3mb()); - } -} diff --git a/test/libc/calls/vfork_test.c b/test/libc/calls/vfork_test.c index e2ecd9d1f..685a4ee1e 100644 --- a/test/libc/calls/vfork_test.c +++ b/test/libc/calls/vfork_test.c @@ -23,13 +23,12 @@ #include "libc/sysv/consts/o.h" #include "libc/testlib/testlib.h" -#define PATH "o/vfork_test" +char testlib_enable_tmp_setup_teardown; TEST(vfork, test) { int fd; char buf[8] = {0}; - mkdir("o", 0755); - ASSERT_NE(-1, (fd = open(PATH, O_RDWR | O_CREAT, 0644))); + ASSERT_NE(-1, (fd = open("vfork_test", O_RDWR | O_CREAT, 0644))); ASSERT_EQ(5, write(fd, "hello", 5)); ASSERT_NE(-1, lseek(fd, 0, SEEK_SET)); if (!vfork()) { @@ -44,5 +43,4 @@ TEST(vfork, test) { EXPECT_EQ(5, read(fd, buf, 5)); EXPECT_STREQ("hello", buf); EXPECT_NE(-1, close(fd)); - unlink(PATH); } diff --git a/test/libc/mem/unveil_test.c b/test/libc/mem/unveil_test.c index ffd8cc849..40029e58a 100644 --- a/test/libc/mem/unveil_test.c +++ b/test/libc/mem/unveil_test.c @@ -44,10 +44,10 @@ STATIC_YOINK("zip_uri_support"); #define EACCES_OR_ENOENT (IsOpenbsd() ? ENOENT : EACCES) -#define SPAWN() \ - { \ - int ws, pid; \ - ASSERT_NE(-1, (pid = fork())); \ +#define SPAWN(METHOD) \ + { \ + int ws, pid; \ + ASSERT_NE(-1, (pid = METHOD())); \ if (!pid) { #define EXITS(rc) \ @@ -94,7 +94,7 @@ int extract(const char *from, const char *to, int mode) { } TEST(unveil, api_differences) { - SPAWN(); + SPAWN(fork); ASSERT_SYS(0, 0, stat("/", &st)); ASSERT_SYS(0, 0, unveil(".", "rw")); if (IsOpenbsd()) { @@ -117,12 +117,12 @@ TEST(unveil, api_differences) { } TEST(unveil, rx_readOnlyPreexistingExecutable_worksFine) { - SPAWN(); + SPAWN(fork); ASSERT_SYS(0, 0, mkdir("folder", 0755)); ASSERT_SYS(0, 0, extract("/zip/life.elf", "folder/life.elf", 0755)); ASSERT_SYS(0, 0, unveil("folder", "rx")); ASSERT_SYS(0, 0, unveil(0, 0)); - SPAWN(); + SPAWN(fork); execl("folder/life.elf", "folder/life.elf", 0); kprintf("execve failed! %s\n", strerror(errno)); _Exit(127); @@ -131,24 +131,41 @@ TEST(unveil, rx_readOnlyPreexistingExecutable_worksFine) { } TEST(unveil, r_noExecutePreexistingExecutable_raisesEacces) { - SPAWN(); + SPAWN(fork); ASSERT_SYS(0, 0, mkdir("folder", 0755)); ASSERT_SYS(0, 0, extract("/zip/life.elf", "folder/life.elf", 0755)); ASSERT_SYS(0, 0, unveil("folder", "r")); ASSERT_SYS(0, 0, unveil(0, 0)); - SPAWN(); + SPAWN(fork); ASSERT_SYS(EACCES, -1, execl("folder/life.elf", "folder/life.elf", 0)); EXITS(0); EXITS(0); } +TEST(unveil, canBeUsedAgainAfterVfork) { + ASSERT_SYS(0, 0, touch("bad", 0644)); + ASSERT_SYS(0, 0, touch("good", 0644)); + SPAWN(fork); + SPAWN(vfork); + ASSERT_SYS(0, 0, unveil("bad", "r")); + ASSERT_SYS(0, 0, unveil("good", "r")); + ASSERT_SYS(0, 0, unveil(0, 0)); + ASSERT_SYS(0, 3, open("bad", 0)); + EXITS(0); + ASSERT_SYS(0, 0, unveil("good", "r")); + ASSERT_SYS(0, 0, unveil(0, 0)); + ASSERT_SYS(0, 3, open("good", 0)); + ASSERT_SYS(EACCES_OR_ENOENT, -1, open("bad", 0)); + EXITS(0); +} + TEST(unveil, rwc_createExecutableFile_isAllowedButCantBeRun) { - SPAWN(); + SPAWN(fork); ASSERT_SYS(0, 0, mkdir("folder", 0755)); ASSERT_SYS(0, 0, unveil("folder", "rwc")); ASSERT_SYS(0, 0, unveil(0, 0)); ASSERT_SYS(0, 0, extract("/zip/life.elf", "folder/life.elf", 0755)); - SPAWN(); + SPAWN(fork); ASSERT_SYS(0, 0, stat("folder/life.elf", &st)); ASSERT_SYS(EACCES, -1, execl("folder/life.elf", "folder/life.elf", 0)); EXITS(0); @@ -156,12 +173,12 @@ TEST(unveil, rwc_createExecutableFile_isAllowedButCantBeRun) { } TEST(unveil, rwcx_createExecutableFile_canAlsoBeRun) { - SPAWN(); + SPAWN(fork); ASSERT_SYS(0, 0, mkdir("folder", 0755)); ASSERT_SYS(0, 0, unveil("folder", "rwcx")); ASSERT_SYS(0, 0, unveil(0, 0)); ASSERT_SYS(0, 0, extract("/zip/life.elf", "folder/life.elf", 0755)); - SPAWN(); + SPAWN(fork); ASSERT_SYS(0, 0, stat("folder/life.elf", &st)); execl("folder/life.elf", "folder/life.elf", 0); kprintf("execve failed! %s\n", strerror(errno)); @@ -171,7 +188,7 @@ TEST(unveil, rwcx_createExecutableFile_canAlsoBeRun) { } TEST(unveil, dirfdHacking_doesntWork) { - SPAWN(); + SPAWN(fork); ASSERT_SYS(0, 0, mkdir("jail", 0755)); ASSERT_SYS(0, 0, mkdir("garden", 0755)); ASSERT_SYS(0, 0, touch("garden/secret.txt", 0644)); @@ -184,7 +201,7 @@ TEST(unveil, dirfdHacking_doesntWork) { TEST(unveil, mostRestrictivePolicy) { if (IsOpenbsd()) return; // openbsd behaves oddly; see docs - SPAWN(); + SPAWN(fork); ASSERT_SYS(0, 0, mkdir("jail", 0755)); ASSERT_SYS(0, 0, mkdir("garden", 0755)); ASSERT_SYS(0, 0, touch("garden/secret.txt", 0644)); @@ -195,7 +212,7 @@ TEST(unveil, mostRestrictivePolicy) { } TEST(unveil, overlappingDirectories_inconsistentBehavior) { - SPAWN(); + SPAWN(fork); ASSERT_SYS(0, 0, makedirs("f1/f2", 0755)); ASSERT_SYS(0, 0, extract("/zip/life.elf", "f1/f2/life.elf", 0755)); ASSERT_SYS(0, 0, unveil("f1", "x")); @@ -203,7 +220,7 @@ TEST(unveil, overlappingDirectories_inconsistentBehavior) { ASSERT_SYS(0, 0, unveil(0, 0)); if (IsOpenbsd()) { // OpenBSD favors the most restrictive policy - SPAWN(); + SPAWN(fork); ASSERT_SYS(0, 0, stat("f1/f2/life.elf", &st)); ASSERT_SYS(EACCES, -1, execl("f1/f2/life.elf", "f1/f2/life.elf", 0)); EXITS(0); @@ -214,7 +231,7 @@ TEST(unveil, overlappingDirectories_inconsistentBehavior) { // exit code of 0! find out why this is happening... // so far it's happened to MODE=rel and MODE=tiny... // - // SPAWN(); + // SPAWN(fork); // ASSERT_SYS(0, 0, stat("f1/f2/life.elf", &st)); // execl("f1/f2/life.elf", "f1/f2/life.elf", 0); // kprintf("execve failed! %s\n", strerror(errno)); @@ -225,7 +242,7 @@ TEST(unveil, overlappingDirectories_inconsistentBehavior) { } TEST(unveil, usedTwice_forbidden) { - SPAWN(); + SPAWN(fork); ASSERT_SYS(0, 0, mkdir("jail", 0755)); ASSERT_SYS(0, 0, mkdir("garden", 0755)); ASSERT_SYS(0, 0, xbarf("garden/secret.txt", "hello", 5)); @@ -288,7 +305,7 @@ TEST(unveil, usedTwice_forbidden_worksWithPledge) { TEST(unveil, lotsOfPaths) { int i, n; - SPAWN(); + SPAWN(fork); n = 100; for (i = 0; i < n; ++i) { ASSERT_SYS(0, 0, touch(xasprintf("%d", i), 0644)); @@ -305,3 +322,15 @@ TEST(unveil, lotsOfPaths) { } EXITS(0); } + +TEST(unveil, reparent) { + return; // need abi 2 :'( + SPAWN(fork); + ASSERT_SYS(0, 0, mkdir("x", 0755)); + ASSERT_SYS(0, 0, unveil("x", "rwc")); + ASSERT_SYS(0, 0, unveil(0, 0)); + ASSERT_SYS(0, 0, mkdir("x/y", 0755)); + ASSERT_SYS(0, 0, touch("x/y/z", 0644)); + ASSERT_SYS(0, 0, rename("x/y/z", "x/z")); + EXITS(0); +} diff --git a/test/libc/release/smoke.c b/test/libc/release/smoke.c index 2c7d3b4e9..71d8f1952 100644 --- a/test/libc/release/smoke.c +++ b/test/libc/release/smoke.c @@ -9,10 +9,6 @@ int main(int argc, char *argv[]) { fputs(_gc(xiso8601ts(NULL)), f); fputs(_gc(xasprintf("hello world %d %s\n", argc, s)), f); fclose(f); - rc = system("exit 42"); - CHECK_NE(-1, rc); - CHECK(WIFEXITED(rc)); - CHECK_EQ(42, WEXITSTATUS(rc)); free(s); return 0; } diff --git a/test/libc/release/smokecxx.cc b/test/libc/release/smokecxx.cc index 793bd4bc9..a31736b12 100644 --- a/test/libc/release/smokecxx.cc +++ b/test/libc/release/smokecxx.cc @@ -1,11 +1,9 @@ int main() { int rc; FILE *f; - f = fopen("/dev/null", "w"); - fprintf(f, "hello world\n"); - fclose(f); - rc = system("exit 42"); - CHECK_NE(-1, rc); - CHECK_EQ(42, WEXITSTATUS(rc)); - return 0; + int *x = new int[32]; + x[0] = 2; + x[1] = 2; + x[2] = x[0] + x[1]; + return x[2] - 4; } diff --git a/test/libc/runtime/mmap_test.c b/test/libc/runtime/mmap_test.c index 0416578c4..a081ba098 100644 --- a/test/libc/runtime/mmap_test.c +++ b/test/libc/runtime/mmap_test.c @@ -18,6 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/atomic.h" #include "libc/bits/bits.h" +#include "libc/bits/safemacros.internal.h" #include "libc/bits/xchg.internal.h" #include "libc/calls/calls.h" #include "libc/calls/ucontext.h" @@ -46,6 +47,8 @@ #include "libc/x/x.h" #include "third_party/xed/x86.h" +#define TMP firstnonnull(getenv("TMPDIR"), kTmpPath) + char testlib_enable_tmp_setup_teardown; __attribute__((__constructor__)) static void init(void) { @@ -93,7 +96,7 @@ TEST(mmap, testMapFile) { int fd; char *p; char path[PATH_MAX]; - sprintf(path, "%s%s.%ld", kTmpPath, program_invocation_short_name, lemur64()); + sprintf(path, "%s.%ld", program_invocation_short_name, lemur64()); ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644))); EXPECT_EQ(5, write(fd, "hello", 5)); EXPECT_NE(-1, fdatasync(fd)); @@ -107,7 +110,7 @@ TEST(mmap, testMapFile) { TEST(mmap, testMapFile_fdGetsClosed_makesNoDifference) { int fd; char *p, buf[16], path[PATH_MAX]; - sprintf(path, "%s%s.%ld", kTmpPath, program_invocation_short_name, lemur64()); + sprintf(path, "%s.%ld", program_invocation_short_name, lemur64()); ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644))); EXPECT_EQ(5, write(fd, "hello", 5)); EXPECT_NE(-1, fdatasync(fd)); @@ -227,8 +230,9 @@ TEST(mmap, cow) { int fd; char *p; char path[PATH_MAX]; - sprintf(path, "%s%s.%ld", kTmpPath, program_invocation_short_name, lemur64()); - ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644))); + sprintf(path, "%s.%ld", program_invocation_short_name, lemur64()); + ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644)), "%s", + path); EXPECT_EQ(5, write(fd, "hello", 5)); EXPECT_NE(-1, fdatasync(fd)); EXPECT_NE(MAP_FAILED, @@ -246,7 +250,7 @@ TEST(mmap, cowFileMapReadonlyFork) { char *p; int fd, pid, ws; char path[PATH_MAX], lol[6]; - sprintf(path, "%s%s.%ld", kTmpPath, program_invocation_short_name, lemur64()); + sprintf(path, "%s.%ld", program_invocation_short_name, lemur64()); ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644))); EXPECT_EQ(6, write(fd, "hello", 6)); EXPECT_NE(-1, close(fd)); @@ -271,7 +275,7 @@ TEST(mmap, cowFileMapFork) { char *p; int fd, pid, ws; char path[PATH_MAX], lol[6]; - sprintf(path, "%s%s.%ld", kTmpPath, program_invocation_short_name, lemur64()); + sprintf(path, "%s.%ld", program_invocation_short_name, lemur64()); ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644))); EXPECT_EQ(6, write(fd, "parnt", 6)); EXPECT_NE(-1, fdatasync(fd)); @@ -321,7 +325,7 @@ TEST(mmap, sharedFileMapFork) { char *p; int fd, pid, ws; char path[PATH_MAX], lol[6]; - sprintf(path, "%s%s.%ld", kTmpPath, program_invocation_short_name, lemur64()); + sprintf(path, "%s.%ld", program_invocation_short_name, lemur64()); ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644))); EXPECT_EQ(6, write(fd, "parnt", 6)); EXPECT_NE(-1, fdatasync(fd)); diff --git a/test/libc/stdio/popen_test.c b/test/libc/stdio/popen_test.c deleted file mode 100644 index a14216a26..000000000 --- a/test/libc/stdio/popen_test.c +++ /dev/null @@ -1,35 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2021 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/calls.h" -#include "libc/log/check.h" -#include "libc/stdio/stdio.h" -#include "libc/testlib/testlib.h" - -TEST(popen, test) { - int ws; - FILE *f; - f = popen("echo hi", "r"); - ASSERT_NE(NULL, f); - EXPECT_EQ('h', fgetc(f)); - EXPECT_EQ('i', fgetc(f)); - ws = pclose(f); - EXPECT_NE(-1, ws); - EXPECT_TRUE(WIFEXITED(ws)); - EXPECT_EQ(0, WEXITSTATUS(ws)); -} diff --git a/test/libc/stdio/test.mk b/test/libc/stdio/test.mk index 04c1627ef..c6bd57baf 100644 --- a/test/libc/stdio/test.mk +++ b/test/libc/stdio/test.mk @@ -58,6 +58,7 @@ o/$(MODE)/test/libc/stdio/%.com.dbg: \ $(TEST_LIBC_STDIO_DEPS) \ o/$(MODE)/test/libc/stdio/%.o \ o/$(MODE)/test/libc/stdio/stdio.pkg \ + o/$(MODE)/tool/build/echo.zip.o \ $(LIBC_TESTMAIN) \ $(CRT) \ $(APE_NO_MODIFY_SELF) diff --git a/test/libc/x/xslurp_test.c b/test/libc/x/xslurp_test.c index f8708f214..96982ab6c 100644 --- a/test/libc/x/xslurp_test.c +++ b/test/libc/x/xslurp_test.c @@ -22,24 +22,22 @@ #include "libc/testlib/testlib.h" #include "libc/x/x.h" +char testlib_enable_tmp_setup_teardown; + TEST(xslurp, testEmptyWithNulTerminatedStringBehavior) { size_t got; const char *data; - const char *path = gc(xjoinpaths(kTmpPath, "xslurp.txt")); - ASSERT_NE(-1, xbarf(path, "", -1)); - ASSERT_NE(NULL, (data = gc(xslurp(path, &got)))); + ASSERT_NE(-1, xbarf("xslurp.txt", "", -1)); + ASSERT_NE(NULL, (data = gc(xslurp("xslurp.txt", &got)))); ASSERT_EQ(0, got); ASSERT_STREQ("", data); - ASSERT_NE(-1, unlink(path)); } TEST(xslurp, testHyperion) { size_t got; const char *data; - const char *path = gc(xjoinpaths(kTmpPath, "xslurp.txt")); - ASSERT_NE(-1, xbarf(path, kHyperion, kHyperionSize)); - ASSERT_NE(NULL, (data = gc(xslurp(path, &got)))); + ASSERT_NE(-1, xbarf("xslurp.txt", kHyperion, kHyperionSize)); + ASSERT_NE(NULL, (data = gc(xslurp("xslurp.txt", &got)))); ASSERT_EQ(kHyperionSize, got); ASSERT_EQ(0, memcmp(data, kHyperion, kHyperionSize)); - ASSERT_NE(-1, unlink(path)); } diff --git a/third_party/bzip2/bzip2.mk b/third_party/bzip2/bzip2.mk index cc5e8a3ba..8c8e2fcde 100644 --- a/third_party/bzip2/bzip2.mk +++ b/third_party/bzip2/bzip2.mk @@ -8,6 +8,7 @@ THIRD_PARTY_BZIP2 = $(THIRD_PARTY_BZIP2_A_DEPS) $(THIRD_PARTY_BZIP2_A) THIRD_PARTY_BZIP2_A = o/$(MODE)/third_party/bzip2/bzip2.a THIRD_PARTY_BZIP2_A_FILES := $(wildcard third_party/bzip2/*) THIRD_PARTY_BZIP2_A_HDRS = $(filter %.h,$(THIRD_PARTY_BZIP2_A_FILES)) +THIRD_PARTY_BZIP2_A_INCS = $(filter %.inc,$(THIRD_PARTY_BZIP2_A_FILES)) THIRD_PARTY_BZIP2_A_SRCS = $(filter %.c,$(THIRD_PARTY_BZIP2_A_FILES)) THIRD_PARTY_BZIP2_A_OBJS = $(THIRD_PARTY_BZIP2_A_SRCS:%.c=o/$(MODE)/%.o) THIRD_PARTY_BZIP2_BINS = $(THIRD_PARTY_BZIP2_COMS) $(THIRD_PARTY_BZIP2_COMS:%=%.dbg) @@ -70,6 +71,7 @@ $(THIRD_PARTY_BZIP2_A_OBJS): \ THIRD_PARTY_BZIP2_LIBS = $(foreach x,$(THIRD_PARTY_BZIP2_ARTIFACTS),$($(x))) THIRD_PARTY_BZIP2_SRCS = $(foreach x,$(THIRD_PARTY_BZIP2_ARTIFACTS),$($(x)_SRCS)) THIRD_PARTY_BZIP2_HDRS = $(foreach x,$(THIRD_PARTY_BZIP2_ARTIFACTS),$($(x)_HDRS)) +THIRD_PARTY_BZIP2_INCS = $(foreach x,$(THIRD_PARTY_BZIP2_ARTIFACTS),$($(x)_INCS)) THIRD_PARTY_BZIP2_BINS = $(foreach x,$(THIRD_PARTY_BZIP2_ARTIFACTS),$($(x)_BINS)) THIRD_PARTY_BZIP2_CHECKS = $(foreach x,$(THIRD_PARTY_BZIP2_ARTIFACTS),$($(x)_CHECKS)) THIRD_PARTY_BZIP2_OBJS = $(foreach x,$(THIRD_PARTY_BZIP2_ARTIFACTS),$($(x)_OBJS)) diff --git a/third_party/libcxx/__mutex_base b/third_party/libcxx/__mutex_base index 62ff1e4c2..a86d710c2 100644 --- a/third_party/libcxx/__mutex_base +++ b/third_party/libcxx/__mutex_base @@ -15,7 +15,9 @@ #include "third_party/libcxx/system_error" #include "third_party/libcxx/__threading_support" -#include "libc/isystem/time.h" +#include "libc/sysv/consts/sched.h" +#include "libc/time/struct/tm.h" +#include "libc/time/time.h" #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/third_party/libcxx/string.h b/third_party/libcxx/string.h index 851bcbbd7..f896c2749 100644 --- a/third_party/libcxx/string.h +++ b/third_party/libcxx/string.h @@ -57,7 +57,8 @@ size_t strlen(const char* s); #pragma GCC system_header #endif -#include "libc/isystem/string.h" +#include "libc/alg/alg.h" +#include "libc/str/str.h" // MSVCRT, GNU libc and its derivates may already have the correct prototype in // . This macro can be defined by users if their C library provides diff --git a/third_party/libcxx/wchar.h b/third_party/libcxx/wchar.h index d0f81b8c5..259b310f6 100644 --- a/third_party/libcxx/wchar.h +++ b/third_party/libcxx/wchar.h @@ -9,7 +9,8 @@ #ifndef _LIBCPP_WCHAR_H #define _LIBCPP_WCHAR_H -#include "libc/isystem/wchar.h" +#include "libc/str/str.h" +#include "libc/time/time.h" /* wchar.h synopsis diff --git a/third_party/libcxx/wctype.h b/third_party/libcxx/wctype.h index b256d58dd..1ea8f5652 100644 --- a/third_party/libcxx/wctype.h +++ b/third_party/libcxx/wctype.h @@ -50,7 +50,8 @@ wctrans_t wctrans(const char* property); #pragma GCC system_header #endif -#include "libc/isystem/wctype.h" +#include "libc/str/str.h" +#include "libc/time/time.h" #ifdef __cplusplus diff --git a/third_party/lz4cli/lz4cli.mk b/third_party/lz4cli/lz4cli.mk index 2c1b93d19..15d9600c4 100644 --- a/third_party/lz4cli/lz4cli.mk +++ b/third_party/lz4cli/lz4cli.mk @@ -59,6 +59,9 @@ o/$(MODE)/third_party/lz4cli/lz4cli.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) +o/$(MODE)/third_party/lz4cli/lz4cli.o: \ + third_party/lz4cli/COPYING + $(THIRD_PARTY_LZ4CLI_OBJS): \ $(BUILD_FILES) \ third_party/lz4cli/lz4cli.mk diff --git a/third_party/make/dirname.h b/third_party/make/dirname.h index 52ee3a92c..dc238bdce 100644 --- a/third_party/make/dirname.h +++ b/third_party/make/dirname.h @@ -20,7 +20,7 @@ #ifndef DIRNAME_H_ # define DIRNAME_H_ 1 -# include "third_party/make/dosname.h" +#include "third_party/make/dosname.h" # ifndef DIRECTORY_SEPARATOR # define DIRECTORY_SEPARATOR '/' diff --git a/third_party/make/error.c b/third_party/make/error.c index 5fe39d0cc..064f1b1a2 100644 --- a/third_party/make/error.c +++ b/third_party/make/error.c @@ -28,7 +28,7 @@ #include "third_party/make/stdio.h" #if !_LIBC && ENABLE_NLS -# include "third_party/make/gettext.h" +#include "third_party/make/gettext.h" # define _(msgid) gettext (msgid) #endif @@ -38,11 +38,7 @@ # define _GL_ATTRIBUTE_FORMAT_PRINTF(a, b) # define _GL_ARG_NONNULL(a) #else -# include "getprogname.h" -#endif - -#if USE_UNLOCKED_IO -# include "unlocked-io.h" +#include "third_party/make/getprogname.h" #endif #ifndef _ diff --git a/third_party/make/getopt.c b/third_party/make/getopt.c index 170c82f83..62d390b08 100644 --- a/third_party/make/getopt.c +++ b/third_party/make/getopt.c @@ -31,7 +31,7 @@ this program. If not, see . */ #endif #ifdef HAVE_CONFIG_H -# include "third_party/make/config.h" +#include "third_party/make/config.h" #endif #pragma GCC diagnostic ignored "-Wredundant-decls" diff --git a/third_party/make/make.mk b/third_party/make/make.mk index 9570f1cf5..162f20a31 100644 --- a/third_party/make/make.mk +++ b/third_party/make/make.mk @@ -13,6 +13,42 @@ THIRD_PARTY_MAKE_BINS = \ THIRD_PARTY_MAKE_A = \ o/$(MODE)/third_party/make/make.a +THIRD_PARTY_MAKE_HDRS = \ + third_party/make/filename.h \ + third_party/make/dirname.h \ + third_party/make/stddef.h \ + third_party/make/error.h \ + third_party/make/gnumake.h \ + third_party/make/gettext.h \ + third_party/make/stdlib.h \ + third_party/make/xalloc.h \ + third_party/make/xalloc-oversized.h \ + third_party/make/os.h \ + third_party/make/stdint.h \ + third_party/make/fd-hook.h \ + third_party/make/job.h \ + third_party/make/unistd.h \ + third_party/make/getprogname.h \ + third_party/make/dosname.h \ + third_party/make/config.h \ + third_party/make/concat-filename.h \ + third_party/make/findprog.h \ + third_party/make/intprops.h \ + third_party/make/exitfail.h \ + third_party/make/alloca.h \ + third_party/make/hash.h \ + third_party/make/rule.h \ + third_party/make/filedef.h \ + third_party/make/fcntl.h \ + third_party/make/stdio.h \ + third_party/make/variable.h \ + third_party/make/debug.h \ + third_party/make/output.h \ + third_party/make/getopt.h \ + third_party/make/dep.h \ + third_party/make/commands.h + + THIRD_PARTY_MAKE_INCS = \ third_party/make/makeint.inc diff --git a/third_party/mbedtls/test/lib.c b/third_party/mbedtls/test/lib.c index d1dbae207..aa05669d6 100644 --- a/third_party/mbedtls/test/lib.c +++ b/third_party/mbedtls/test/lib.c @@ -90,6 +90,7 @@ int mbedtls_test_platform_setup(void) { int ret = 0; static char mybuf[2][BUFSIZ]; ShowCrashReports(); + makedirs("o/tmp", 0755); setvbuf(stdout, mybuf[0], _IOLBF, BUFSIZ); setvbuf(stderr, mybuf[1], _IOLBF, BUFSIZ); #if defined(MBEDTLS_PLATFORM_C) diff --git a/third_party/mbedtls/test/test_suite_ctr_drbg.c b/third_party/mbedtls/test/test_suite_ctr_drbg.c index 781c2093f..75537963c 100644 --- a/third_party/mbedtls/test/test_suite_ctr_drbg.c +++ b/third_party/mbedtls/test/test_suite_ctr_drbg.c @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "libc/intrin/kprintf.h" #include "third_party/mbedtls/test/test.inc" /* * *** THIS FILE WAS MACHINE GENERATED *** diff --git a/third_party/mbedtls/test/test_suite_ctr_drbg.datax b/third_party/mbedtls/test/test_suite_ctr_drbg.datax index 6f11d720b..fdc475414 100644 --- a/third_party/mbedtls/test/test_suite_ctr_drbg.datax +++ b/third_party/mbedtls/test/test_suite_ctr_drbg.datax @@ -1088,10 +1088,10 @@ depends_on:0 5:int:256 CTR_DRBG write/update seed file [#1] -7:char*:"/tmp/test_suite_ctr_drbg_seed":int:0 +7:char*:"o/tmp/test_suite_ctr_drbg_seed":int:0 CTR_DRBG write/update seed file [#2] -7:char*:"/tmp/test_suite_ctr_dbg_no_such_dir/file":exp:1 +7:char*:"o/tmp/test_suite_ctr_dbg_no_such_dir/file":exp:1 CTR_DRBG Special Behaviours 0 diff --git a/third_party/mbedtls/test/test_suite_entropy.datax b/third_party/mbedtls/test/test_suite_entropy.datax index 3742c6286..e79c01d24 100644 --- a/third_party/mbedtls/test/test_suite_entropy.datax +++ b/third_party/mbedtls/test/test_suite_entropy.datax @@ -8,10 +8,10 @@ Create NV seed_file 8 Entropy write/update seed file: good -1:char*:"/tmp/mbedtls_test_suite_entropy_seed":int:0 +1:char*:"o/tmp/mbedtls_test_suite_entropy_seed":int:0 Entropy write/update seed file: nonexistent -1:char*:"/tmp/no_such_dir/file":exp:0 +1:char*:"o/tmp/no_such_dir/file":exp:0 Entropy no sources 2 diff --git a/third_party/mbedtls/test/test_suite_hmac_drbg.misc.datax b/third_party/mbedtls/test/test_suite_hmac_drbg.misc.datax index 952f5f461..0f548f381 100644 --- a/third_party/mbedtls/test/test_suite_hmac_drbg.misc.datax +++ b/third_party/mbedtls/test/test_suite_hmac_drbg.misc.datax @@ -20,7 +20,7 @@ depends_on:2 HMAC_DRBG write/update seed file SHA-1 [#1] depends_on:0 -1:exp:0:char*:"/tmp/test_suite_hmac_drbg_seed":int:0 +1:exp:0:char*:"o/tmp/test_suite_hmac_drbg_seed":int:0 HMAC_DRBG write/update seed file SHA-1 [#2] depends_on:0 @@ -28,7 +28,7 @@ depends_on:0 HMAC_DRBG write/update seed file SHA-224 [#1] depends_on:1 -1:exp:1:char*:"/tmp/test_suite_hmac_drbg_seed":int:0 +1:exp:1:char*:"o/tmp/test_suite_hmac_drbg_seed":int:0 HMAC_DRBG write/update seed file SHA-224 [#2] depends_on:1 @@ -36,7 +36,7 @@ depends_on:1 HMAC_DRBG write/update seed file SHA-256 [#1] depends_on:1 -1:exp:2:char*:"/tmp/test_suite_hmac_drbg_seed":int:0 +1:exp:2:char*:"o/tmp/test_suite_hmac_drbg_seed":int:0 HMAC_DRBG write/update seed file SHA-256 [#2] depends_on:1 @@ -44,7 +44,7 @@ depends_on:1 HMAC_DRBG write/update seed file SHA-384 [#1] depends_on:2:3 -1:exp:3:char*:"/tmp/test_suite_hmac_drbg_seed":int:0 +1:exp:3:char*:"o/tmp/test_suite_hmac_drbg_seed":int:0 HMAC_DRBG write/update seed file SHA-384 [#2] depends_on:2:3 @@ -52,11 +52,11 @@ depends_on:2:3 HMAC_DRBG write/update seed file SHA-512 [#1] depends_on:2 -1:exp:4:char*:"/tmp/test_suite_hmac_drbg_seed":int:0 +1:exp:4:char*:"o/tmp/test_suite_hmac_drbg_seed":int:0 HMAC_DRBG write/update seed file SHA-512 [#2] depends_on:2 -1:exp:4:char*:"/tmp/test_suite_hmac_drbg_no_such_dir/file":exp:5 +1:exp:4:char*:"o/tmp/test_suite_hmac_drbg_no_such_dir/file":exp:5 HMAC_DRBG from buffer SHA-1 depends_on:0 diff --git a/third_party/mbedtls/test/test_suite_mpi.datax b/third_party/mbedtls/test/test_suite_mpi.datax index 8ff9cf855..dfca3724d 100644 --- a/third_party/mbedtls/test/test_suite_mpi.datax +++ b/third_party/mbedtls/test/test_suite_mpi.datax @@ -95,7 +95,7 @@ Test mbedtls_mpi_read_file #3 (Input too big) 8:int:10:char*:"/zip/third_party/mbedtls/test/data/mpi_too_big":hex:"":exp:2 Base test mbedtls_mpi_write_file #1 -9:int:10:char*:"56125680981752282334141896320372489490613963693556392520816017892111350604111697682705498319512049040516698827829292076808006940873974979584527073481012636016353913462376755556720019831187364993587901952757307830896531678727717924":int:16:char*:"/tmp/test_suite_mpi_write" +9:int:10:char*:"56125680981752282334141896320372489490613963693556392520816017892111350604111697682705498319512049040516698827829292076808006940873974979584527073481012636016353913462376755556720019831187364993587901952757307830896531678727717924":int:16:char*:"o/tmp/test_suite_mpi_write" Base test mbedtls_mpi_lsb #1 12:int:10:char*:"56125680981752282334141896320372489490613963693556392520816017892111350604111697682705498319512049040516698827829292076808006940873974979584527073481012636016353913462376755556720019831187364993587901952757307830896531678727717924":int:2 diff --git a/third_party/python/Lib/test/support/__init__.py b/third_party/python/Lib/test/support/__init__.py index 4a2c857f3..701def0e7 100644 --- a/third_party/python/Lib/test/support/__init__.py +++ b/third_party/python/Lib/test/support/__init__.py @@ -1049,7 +1049,7 @@ def temp_cwd(name='tempcwd', quiet=False): only a warning is raised and the original CWD is used. """ - with temp_dir(path=name, quiet=quiet) as temp_path: + with temp_dir(quiet=quiet) as temp_path: with change_cwd(temp_path, quiet=quiet) as cwd_dir: yield cwd_dir diff --git a/third_party/python/Lib/test/test_tarfile.py b/third_party/python/Lib/test/test_tarfile.py index d7fede0fb..b5c8ddb28 100644 --- a/third_party/python/Lib/test/test_tarfile.py +++ b/third_party/python/Lib/test/test_tarfile.py @@ -2607,8 +2607,9 @@ class NumericOwnerTest(unittest.TestCase): # because the uname and gname in the test file are 'root', and extract() # will look them up using pwd and grp to find their uid and gid, which we # test here to be 0. - @unittest.skipUnless(root_is_uid_gid_0(), - 'uid=0,gid=0 must be named "root"') + # [jart] tests shouldn't read /etc/passwd lool + # @unittest.skipUnless(root_is_uid_gid_0(), + # 'uid=0,gid=0 must be named "root"') @unittest.mock.patch('os.chown') @unittest.mock.patch('os.chmod') @unittest.mock.patch('os.geteuid') diff --git a/third_party/python/Modules/_elementtree.c b/third_party/python/Modules/_elementtree.c index d5ce7ff0b..facf6be28 100644 --- a/third_party/python/Modules/_elementtree.c +++ b/third_party/python/Modules/_elementtree.c @@ -17,12 +17,14 @@ #include "third_party/python/Include/object.h" #include "third_party/python/Include/objimpl.h" #include "third_party/python/Include/pycapsule.h" +#include "third_party/python/Include/pyexpat.h" #include "third_party/python/Include/pyhash.h" #include "third_party/python/Include/pystate.h" #include "third_party/python/Include/sliceobject.h" #include "third_party/python/Include/structmember.h" #include "third_party/python/Include/warnings.h" #include "third_party/python/Include/yoink.h" +#include "third_party/python/Modules/expat/expat.h" /* clang-format off */ PYTHON_PROVIDE("_elementtree"); @@ -2772,9 +2774,6 @@ _elementtree_TreeBuilder_start_impl(TreeBuilderObject *self, PyObject *tag, /* ==================================================================== */ /* the expat interface */ -#include "third_party/python/Modules/expat/expat.h" -#include "third_party/python/Include/pyexpat.h" - /* The PyExpat_CAPI structure is an immutable dispatch table, so it can be * cached globally without being in per-module state. */ diff --git a/third_party/python/Objects/typeobject.c b/third_party/python/Objects/typeobject.c index 8b664b7bf..c23c1ea1f 100644 --- a/third_party/python/Objects/typeobject.c +++ b/third_party/python/Objects/typeobject.c @@ -33,6 +33,11 @@ #include "third_party/python/Include/weakrefobject.h" /* clang-format off */ +static const short slotoffsets[] = { + -1, /* invalid slot */ +#include "third_party/python/Objects/typeslots.inc" +}; + /* Type object implementation */ /* Support type attribute cache */ @@ -2791,11 +2796,6 @@ error: return NULL; } -static const short slotoffsets[] = { - -1, /* invalid slot */ -#include "typeslots.inc" -}; - PyObject * PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) { diff --git a/third_party/python/python.mk b/third_party/python/python.mk index 8aeac821e..2e28cc282 100644 --- a/third_party/python/python.mk +++ b/third_party/python/python.mk @@ -4194,6 +4194,39 @@ $(THIRD_PARTY_PYTHON_PYTEST_A_DATA_OBJS): ZIPOBJ_FLAGS += -P.python -C3 o/$(MODE)/third_party/python/Python/ceval.o: QUOTA = -C64 -M1024m -L300 o/$(MODE)/third_party/python/Objects/unicodeobject.o: QUOTA += -C64 -M1024m -L300 +o/$(MODE)/third_party/python/Objects/unicodeobject.o: \ + third_party/python/Objects/unicodeobject.c \ + third_party/python/Objects/stringlib/localeutil.inc \ + third_party/python/Objects/stringlib/unicode_format.inc \ + third_party/python/Objects/stringlib/asciilib.inc \ + third_party/python/Objects/stringlib/codecs.inc \ + third_party/python/Objects/stringlib/undef.inc \ + third_party/python/Objects/stringlib/ucs1lib.inc \ + third_party/python/Objects/stringlib/codecs.inc \ + third_party/python/Objects/stringlib/undef.inc \ + third_party/python/Objects/stringlib/ucs2lib.inc \ + third_party/python/Objects/stringlib/codecs.inc \ + third_party/python/Objects/stringlib/undef.inc \ + third_party/python/Objects/stringlib/ucs4lib.inc \ + third_party/python/Objects/stringlib/codecs.inc \ + third_party/python/Objects/stringlib/undef.inc + +o/$(MODE)/third_party/python/Modules/_elementtree.o: \ + third_party/python/Modules/_elementtree.c \ + third_party/python/Modules/clinic/_elementtree.inc + +o/$(MODE)/third_party/python/Modules/_io/bufferedio.o: \ + third_party/python/Modules/_io/bufferedio.c \ + third_party/python/Modules/_io/clinic/bufferedio.inc + +o/$(MODE)/third_party/python/Modules/_io/textio.o: \ + third_party/python/Modules/_io/textio.c \ + third_party/python/Modules/_io/clinic/textio.inc + +o/$(MODE)/third_party/python/Modules/_sre.o: \ + third_party/python/Modules/_sre.c \ + third_party/python/Modules/clinic/_sre.inc + o/$(MODE)/third_party/python/Parser/asdl_c.o: PYFLAGS += -m $(THIRD_PARTY_PYTHON_PYTEST_PYMAINS_OBJS): PYFLAGS += -t -P.python -C3 $(THIRD_PARTY_PYTHON_PYTEST_TODOS:%.py=o/$(MODE)/%.o): PYFLAGS += -t -P.python -C3 @@ -4348,7 +4381,6 @@ o/$(MODE)/third_party/python/chibicc.inc: \ libc/nexgen32e/kcpuids.h \ libc/runtime/runtime.h \ libc/runtime/symbolic.h \ - libc/runtime/valist.h \ libc/stdio/stdio.h \ libc/str/str.h \ libc/unicode/unicode.h \ diff --git a/third_party/sqlite3/alter.shell.c b/third_party/sqlite3/alter.shell.c new file mode 100644 index 000000000..ed1d873b3 --- /dev/null +++ b/third_party/sqlite3/alter.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/alter.c" diff --git a/third_party/sqlite3/analyze.shell.c b/third_party/sqlite3/analyze.shell.c new file mode 100644 index 000000000..9ea40006c --- /dev/null +++ b/third_party/sqlite3/analyze.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/analyze.c" diff --git a/third_party/sqlite3/appendvfs.shell.c b/third_party/sqlite3/appendvfs.shell.c new file mode 100644 index 000000000..2b18660d5 --- /dev/null +++ b/third_party/sqlite3/appendvfs.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/appendvfs.c" diff --git a/third_party/sqlite3/attach.shell.c b/third_party/sqlite3/attach.shell.c new file mode 100644 index 000000000..dfe7d6d71 --- /dev/null +++ b/third_party/sqlite3/attach.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/attach.c" diff --git a/third_party/sqlite3/auth.shell.c b/third_party/sqlite3/auth.shell.c new file mode 100644 index 000000000..bbe9c2806 --- /dev/null +++ b/third_party/sqlite3/auth.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/auth.c" diff --git a/third_party/sqlite3/backup.shell.c b/third_party/sqlite3/backup.shell.c new file mode 100644 index 000000000..107773467 --- /dev/null +++ b/third_party/sqlite3/backup.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/backup.c" diff --git a/third_party/sqlite3/bitvec.shell.c b/third_party/sqlite3/bitvec.shell.c new file mode 100644 index 000000000..8cb4930a5 --- /dev/null +++ b/third_party/sqlite3/bitvec.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/bitvec.c" diff --git a/third_party/sqlite3/btmutex.shell.c b/third_party/sqlite3/btmutex.shell.c new file mode 100644 index 000000000..caa2b7eac --- /dev/null +++ b/third_party/sqlite3/btmutex.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/btmutex.c" diff --git a/third_party/sqlite3/btree.shell.c b/third_party/sqlite3/btree.shell.c new file mode 100644 index 000000000..2d435907d --- /dev/null +++ b/third_party/sqlite3/btree.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/btree.c" diff --git a/third_party/sqlite3/build.shell.c b/third_party/sqlite3/build.shell.c new file mode 100644 index 000000000..72dfebe73 --- /dev/null +++ b/third_party/sqlite3/build.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/build.c" diff --git a/third_party/sqlite3/callback.shell.c b/third_party/sqlite3/callback.shell.c new file mode 100644 index 000000000..de758a552 --- /dev/null +++ b/third_party/sqlite3/callback.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/callback.c" diff --git a/third_party/sqlite3/complete.shell.c b/third_party/sqlite3/complete.shell.c new file mode 100644 index 000000000..f27e9d9e7 --- /dev/null +++ b/third_party/sqlite3/complete.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/complete.c" diff --git a/third_party/sqlite3/completion.shell.c b/third_party/sqlite3/completion.shell.c new file mode 100644 index 000000000..7e168358a --- /dev/null +++ b/third_party/sqlite3/completion.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/completion.c" diff --git a/third_party/sqlite3/ctime.shell.c b/third_party/sqlite3/ctime.shell.c new file mode 100644 index 000000000..f7336a562 --- /dev/null +++ b/third_party/sqlite3/ctime.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/ctime.c" diff --git a/third_party/sqlite3/date.shell.c b/third_party/sqlite3/date.shell.c new file mode 100644 index 000000000..fc7f656ec --- /dev/null +++ b/third_party/sqlite3/date.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/date.c" diff --git a/third_party/sqlite3/dbdata.shell.c b/third_party/sqlite3/dbdata.shell.c new file mode 100644 index 000000000..49a5461e5 --- /dev/null +++ b/third_party/sqlite3/dbdata.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/dbdata.c" diff --git a/third_party/sqlite3/dbpage.shell.c b/third_party/sqlite3/dbpage.shell.c new file mode 100644 index 000000000..e0d6fb570 --- /dev/null +++ b/third_party/sqlite3/dbpage.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/dbpage.c" diff --git a/third_party/sqlite3/dbstat.shell.c b/third_party/sqlite3/dbstat.shell.c new file mode 100644 index 000000000..71c1471bc --- /dev/null +++ b/third_party/sqlite3/dbstat.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/dbstat.c" diff --git a/third_party/sqlite3/decimal.shell.c b/third_party/sqlite3/decimal.shell.c new file mode 100644 index 000000000..96118f74e --- /dev/null +++ b/third_party/sqlite3/decimal.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/decimal.c" diff --git a/third_party/sqlite3/delete.shell.c b/third_party/sqlite3/delete.shell.c new file mode 100644 index 000000000..20e73c4ae --- /dev/null +++ b/third_party/sqlite3/delete.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/delete.c" diff --git a/third_party/sqlite3/dog.py b/third_party/sqlite3/dog.py new file mode 100644 index 000000000..a1c5df0fa --- /dev/null +++ b/third_party/sqlite3/dog.py @@ -0,0 +1,120 @@ +sauce = ''' +alter +analyze +appendvfs +attach +auth +backup +bitvec +btmutex +btree +build +callback +complete +completion +ctime +date +dbdata +dbpage +dbstat +decimal +delete +expr +fault +fileio +fkey +fts3 +fts3_aux +fts3_expr +fts3_hash +fts3_icu +fts3_porter +fts3_snippet +fts3_tokenize_vtab +fts3_tokenizer +fts3_tokenizer1 +fts3_unicode +fts3_unicode2 +fts3_write +fts5 +func +global +hash +icu +ieee754 +insert +json1 +legacy +loadext +main +malloc +mem0 +mem1 +mem2 +mem3 +mem5 +memdb +memjournal +memtrace +mutex +mutex_noop +mutex_unix +notify +opcodes +os +os_unix +os_win +pager +parse +pcache +pcache1 +pragma +prepare +printf +random +resolve +rowset +rtree +select +series +shathree +shell +sqlar +sqlite3expert +sqlite3rbu +sqlite3session +status +stmt +table +threads +tokenize +treeview +trigger +uint +update +upsert +userauth +utf +util +vacuum +vdbe +vdbeapi +vdbeaux +vdbeblob +vdbemem +vdbesort +vdbetrace +vdbevtab +vtab +wal +walker +where +wherecode +whereexpr +window +zipfile +'''.split() + +for s in sauce: + with open('third_party/sqlite3/%s.shell.c' % (s), 'w') as f: + f.write('#include "third_party/sqlite3/%s.c"\n' % (s)) diff --git a/third_party/sqlite3/expr.shell.c b/third_party/sqlite3/expr.shell.c new file mode 100644 index 000000000..8441b1415 --- /dev/null +++ b/third_party/sqlite3/expr.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/expr.c" diff --git a/third_party/sqlite3/fault.shell.c b/third_party/sqlite3/fault.shell.c new file mode 100644 index 000000000..0f07bab5c --- /dev/null +++ b/third_party/sqlite3/fault.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fault.c" diff --git a/third_party/sqlite3/fileio.c b/third_party/sqlite3/fileio.c index dbe14d3ce..4619ebb05 100644 --- a/third_party/sqlite3/fileio.c +++ b/third_party/sqlite3/fileio.c @@ -1,3 +1,18 @@ +#include "libc/assert.h" +#include "libc/calls/calls.h" +#include "libc/calls/struct/dirent.h" +#include "libc/calls/struct/stat.h" +#include "libc/calls/struct/stat.macros.h" +#include "libc/calls/weirdtypes.h" +#include "libc/errno.h" +#include "libc/stdio/stdio.h" +#include "libc/str/str.h" +#include "libc/sysv/consts/at.h" +#include "libc/sysv/consts/s.h" +#include "libc/time/time.h" +#include "third_party/sqlite3/sqlite3ext.h" +// clang-format off + /* ** 2014-06-13 ** @@ -73,21 +88,6 @@ ** And the paths returned in the "name" column of the table are also ** relative to directory $dir. */ -#include "libc/assert.h" -#include "libc/calls/calls.h" -#include "libc/calls/struct/dirent.h" -#include "libc/calls/struct/stat.h" -#include "libc/calls/struct/stat.macros.h" -#include "libc/calls/weirdtypes.h" -#include "libc/errno.h" -#include "libc/isystem/unistd.h" -#include "libc/stdio/stdio.h" -#include "libc/str/str.h" -#include "libc/sysv/consts/at.h" -#include "libc/sysv/consts/s.h" -#include "libc/time/time.h" -#include "third_party/sqlite3/sqlite3ext.h" -// clang-format off SQLITE_EXTENSION_INIT1 diff --git a/third_party/sqlite3/fileio.shell.c b/third_party/sqlite3/fileio.shell.c new file mode 100644 index 000000000..784b16498 --- /dev/null +++ b/third_party/sqlite3/fileio.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fileio.c" diff --git a/third_party/sqlite3/fkey.shell.c b/third_party/sqlite3/fkey.shell.c new file mode 100644 index 000000000..acf186d62 --- /dev/null +++ b/third_party/sqlite3/fkey.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fkey.c" diff --git a/third_party/sqlite3/fts3.shell.c b/third_party/sqlite3/fts3.shell.c new file mode 100644 index 000000000..616df65d6 --- /dev/null +++ b/third_party/sqlite3/fts3.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fts3.c" diff --git a/third_party/sqlite3/fts3_aux.shell.c b/third_party/sqlite3/fts3_aux.shell.c new file mode 100644 index 000000000..1ec3e53b0 --- /dev/null +++ b/third_party/sqlite3/fts3_aux.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fts3_aux.c" diff --git a/third_party/sqlite3/fts3_expr.shell.c b/third_party/sqlite3/fts3_expr.shell.c new file mode 100644 index 000000000..f06d16ade --- /dev/null +++ b/third_party/sqlite3/fts3_expr.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fts3_expr.c" diff --git a/third_party/sqlite3/fts3_hash.shell.c b/third_party/sqlite3/fts3_hash.shell.c new file mode 100644 index 000000000..fe05adf61 --- /dev/null +++ b/third_party/sqlite3/fts3_hash.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fts3_hash.c" diff --git a/third_party/sqlite3/fts3_icu.shell.c b/third_party/sqlite3/fts3_icu.shell.c new file mode 100644 index 000000000..49b5c15ce --- /dev/null +++ b/third_party/sqlite3/fts3_icu.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fts3_icu.c" diff --git a/third_party/sqlite3/fts3_porter.shell.c b/third_party/sqlite3/fts3_porter.shell.c new file mode 100644 index 000000000..1cff45cc1 --- /dev/null +++ b/third_party/sqlite3/fts3_porter.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fts3_porter.c" diff --git a/third_party/sqlite3/fts3_snippet.shell.c b/third_party/sqlite3/fts3_snippet.shell.c new file mode 100644 index 000000000..99e77d1eb --- /dev/null +++ b/third_party/sqlite3/fts3_snippet.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fts3_snippet.c" diff --git a/third_party/sqlite3/fts3_tokenize_vtab.shell.c b/third_party/sqlite3/fts3_tokenize_vtab.shell.c new file mode 100644 index 000000000..53bb0d44b --- /dev/null +++ b/third_party/sqlite3/fts3_tokenize_vtab.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fts3_tokenize_vtab.c" diff --git a/third_party/sqlite3/fts3_tokenizer.shell.c b/third_party/sqlite3/fts3_tokenizer.shell.c new file mode 100644 index 000000000..354ab7e63 --- /dev/null +++ b/third_party/sqlite3/fts3_tokenizer.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fts3_tokenizer.c" diff --git a/third_party/sqlite3/fts3_tokenizer1.shell.c b/third_party/sqlite3/fts3_tokenizer1.shell.c new file mode 100644 index 000000000..c4020ca1e --- /dev/null +++ b/third_party/sqlite3/fts3_tokenizer1.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fts3_tokenizer1.c" diff --git a/third_party/sqlite3/fts3_unicode.shell.c b/third_party/sqlite3/fts3_unicode.shell.c new file mode 100644 index 000000000..2f95f2448 --- /dev/null +++ b/third_party/sqlite3/fts3_unicode.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fts3_unicode.c" diff --git a/third_party/sqlite3/fts3_unicode2.shell.c b/third_party/sqlite3/fts3_unicode2.shell.c new file mode 100644 index 000000000..9da1a45fe --- /dev/null +++ b/third_party/sqlite3/fts3_unicode2.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fts3_unicode2.c" diff --git a/third_party/sqlite3/fts3_write.shell.c b/third_party/sqlite3/fts3_write.shell.c new file mode 100644 index 000000000..655a490f6 --- /dev/null +++ b/third_party/sqlite3/fts3_write.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fts3_write.c" diff --git a/third_party/sqlite3/fts5.c b/third_party/sqlite3/fts5.c index 583d4ada0..49a46ea16 100644 --- a/third_party/sqlite3/fts5.c +++ b/third_party/sqlite3/fts5.c @@ -1,3 +1,10 @@ +#include "libc/assert.h" +#include "libc/assert.h" +#include "libc/math.h" +#include "libc/stdio/stdio.h" +#include "libc/str/str.h" +#include "third_party/sqlite3/sqlite3.h" +#include "third_party/sqlite3/sqlite3ext.h" /* clang-format off */ @@ -34,8 +41,6 @@ #ifndef _FTS5_H #define _FTS5_H -#include "third_party/sqlite3/sqlite3.h" - #ifdef __cplusplus extern "C" { #endif @@ -604,12 +609,8 @@ struct fts5_api { #ifndef _FTS5INT_H #define _FTS5INT_H -/* #include "third_party/sqlite3/fts5.h" */ -#include "third_party/sqlite3/sqlite3ext.h" SQLITE_EXTENSION_INIT1 -#include "libc/assert.h" -#include "libc/str/str.h" #ifndef SQLITE_AMALGAMATION @@ -1478,9 +1479,6 @@ static void sqlite3Fts5UnicodeAscii(u8*, u8*); /************ Begin %include sections from the grammar ************************/ #line 47 "fts5parse.y" -/* #include "third_party/sqlite3/fts5Int.h" */ -/* #include "third_party/sqlite3/fts5parse.h" */ - /* ** Disable all error recovery processing in the parser push-down ** automaton. @@ -1807,8 +1805,6 @@ struct fts5yyParser { typedef struct fts5yyParser fts5yyParser; #ifndef NDEBUG -#include "libc/assert.h" -#include "libc/stdio/stdio.h" static FILE *fts5yyTraceFILE = 0; static char *fts5yyTracePrompt = 0; #endif /* NDEBUG */ @@ -3013,9 +3009,6 @@ static int sqlite3Fts5ParserFallback(int iToken){ ****************************************************************************** */ -/* #include "third_party/sqlite3/fts5Int.h" */ -#include "libc/math.h" /* amalgamator: keep */ - /* ** Object used to iterate through all "coalesced phrase instances" in ** a single column of the current row. If the phrase instances in the diff --git a/third_party/sqlite3/fts5.shell.c b/third_party/sqlite3/fts5.shell.c new file mode 100644 index 000000000..09366eca9 --- /dev/null +++ b/third_party/sqlite3/fts5.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/fts5.c" diff --git a/third_party/sqlite3/func.shell.c b/third_party/sqlite3/func.shell.c new file mode 100644 index 000000000..a5fbce298 --- /dev/null +++ b/third_party/sqlite3/func.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/func.c" diff --git a/third_party/sqlite3/global.shell.c b/third_party/sqlite3/global.shell.c new file mode 100644 index 000000000..a1954d323 --- /dev/null +++ b/third_party/sqlite3/global.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/global.c" diff --git a/third_party/sqlite3/hash.shell.c b/third_party/sqlite3/hash.shell.c new file mode 100644 index 000000000..c7a83c94a --- /dev/null +++ b/third_party/sqlite3/hash.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/hash.c" diff --git a/third_party/sqlite3/icu.shell.c b/third_party/sqlite3/icu.shell.c new file mode 100644 index 000000000..31742ff8a --- /dev/null +++ b/third_party/sqlite3/icu.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/icu.c" diff --git a/third_party/sqlite3/ieee754.shell.c b/third_party/sqlite3/ieee754.shell.c new file mode 100644 index 000000000..a107e8fab --- /dev/null +++ b/third_party/sqlite3/ieee754.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/ieee754.c" diff --git a/third_party/sqlite3/insert.shell.c b/third_party/sqlite3/insert.shell.c new file mode 100644 index 000000000..4ede33db1 --- /dev/null +++ b/third_party/sqlite3/insert.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/insert.c" diff --git a/third_party/sqlite3/json1.shell.c b/third_party/sqlite3/json1.shell.c new file mode 100644 index 000000000..360532429 --- /dev/null +++ b/third_party/sqlite3/json1.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/json1.c" diff --git a/third_party/sqlite3/legacy.shell.c b/third_party/sqlite3/legacy.shell.c new file mode 100644 index 000000000..dd086fccb --- /dev/null +++ b/third_party/sqlite3/legacy.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/legacy.c" diff --git a/third_party/sqlite3/loadext.shell.c b/third_party/sqlite3/loadext.shell.c new file mode 100644 index 000000000..623c094ed --- /dev/null +++ b/third_party/sqlite3/loadext.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/loadext.c" diff --git a/third_party/sqlite3/main.shell.c b/third_party/sqlite3/main.shell.c new file mode 100644 index 000000000..9c64591ad --- /dev/null +++ b/third_party/sqlite3/main.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/main.c" diff --git a/third_party/sqlite3/malloc.shell.c b/third_party/sqlite3/malloc.shell.c new file mode 100644 index 000000000..1414533da --- /dev/null +++ b/third_party/sqlite3/malloc.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/malloc.c" diff --git a/third_party/sqlite3/mem0.shell.c b/third_party/sqlite3/mem0.shell.c new file mode 100644 index 000000000..e2359bdc9 --- /dev/null +++ b/third_party/sqlite3/mem0.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/mem0.c" diff --git a/third_party/sqlite3/mem1.shell.c b/third_party/sqlite3/mem1.shell.c new file mode 100644 index 000000000..184de31de --- /dev/null +++ b/third_party/sqlite3/mem1.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/mem1.c" diff --git a/third_party/sqlite3/mem2.shell.c b/third_party/sqlite3/mem2.shell.c new file mode 100644 index 000000000..82c610c14 --- /dev/null +++ b/third_party/sqlite3/mem2.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/mem2.c" diff --git a/third_party/sqlite3/mem3.shell.c b/third_party/sqlite3/mem3.shell.c new file mode 100644 index 000000000..2f3d9ca53 --- /dev/null +++ b/third_party/sqlite3/mem3.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/mem3.c" diff --git a/third_party/sqlite3/mem5.shell.c b/third_party/sqlite3/mem5.shell.c new file mode 100644 index 000000000..9ea6e5128 --- /dev/null +++ b/third_party/sqlite3/mem5.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/mem5.c" diff --git a/third_party/sqlite3/memdb.shell.c b/third_party/sqlite3/memdb.shell.c new file mode 100644 index 000000000..ff2082835 --- /dev/null +++ b/third_party/sqlite3/memdb.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/memdb.c" diff --git a/third_party/sqlite3/memjournal.shell.c b/third_party/sqlite3/memjournal.shell.c new file mode 100644 index 000000000..7c49b3f91 --- /dev/null +++ b/third_party/sqlite3/memjournal.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/memjournal.c" diff --git a/third_party/sqlite3/memtrace.shell.c b/third_party/sqlite3/memtrace.shell.c new file mode 100644 index 000000000..6487dd70d --- /dev/null +++ b/third_party/sqlite3/memtrace.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/memtrace.c" diff --git a/third_party/sqlite3/mutex.shell.c b/third_party/sqlite3/mutex.shell.c new file mode 100644 index 000000000..891776fca --- /dev/null +++ b/third_party/sqlite3/mutex.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/mutex.c" diff --git a/third_party/sqlite3/mutex_noop.shell.c b/third_party/sqlite3/mutex_noop.shell.c new file mode 100644 index 000000000..297e7ed14 --- /dev/null +++ b/third_party/sqlite3/mutex_noop.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/mutex_noop.c" diff --git a/third_party/sqlite3/mutex_unix.shell.c b/third_party/sqlite3/mutex_unix.shell.c new file mode 100644 index 000000000..25631f19a --- /dev/null +++ b/third_party/sqlite3/mutex_unix.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/mutex_unix.c" diff --git a/third_party/sqlite3/notify.shell.c b/third_party/sqlite3/notify.shell.c new file mode 100644 index 000000000..e841089a6 --- /dev/null +++ b/third_party/sqlite3/notify.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/notify.c" diff --git a/third_party/sqlite3/opcodes.shell.c b/third_party/sqlite3/opcodes.shell.c new file mode 100644 index 000000000..d470da195 --- /dev/null +++ b/third_party/sqlite3/opcodes.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/opcodes.c" diff --git a/third_party/sqlite3/os.shell.c b/third_party/sqlite3/os.shell.c new file mode 100644 index 000000000..9d62ab209 --- /dev/null +++ b/third_party/sqlite3/os.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/os.c" diff --git a/third_party/sqlite3/os_unix.c b/third_party/sqlite3/os_unix.c index 83bc2d745..4af85669f 100644 --- a/third_party/sqlite3/os_unix.c +++ b/third_party/sqlite3/os_unix.c @@ -96,7 +96,6 @@ #include "libc/calls/struct/flock.h" #include "libc/calls/weirdtypes.h" #include "libc/errno.h" -#include "libc/isystem/unistd.h" #include "libc/runtime/sysconf.h" #include "libc/sysv/consts/f.h" #include "libc/sysv/consts/map.h" diff --git a/third_party/sqlite3/os_unix.shell.c b/third_party/sqlite3/os_unix.shell.c new file mode 100644 index 000000000..f17c84ef9 --- /dev/null +++ b/third_party/sqlite3/os_unix.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/os_unix.c" diff --git a/third_party/sqlite3/os_win.shell.c b/third_party/sqlite3/os_win.shell.c new file mode 100644 index 000000000..7ae5fd5d4 --- /dev/null +++ b/third_party/sqlite3/os_win.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/os_win.c" diff --git a/third_party/sqlite3/pager.shell.c b/third_party/sqlite3/pager.shell.c new file mode 100644 index 000000000..94b752256 --- /dev/null +++ b/third_party/sqlite3/pager.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/pager.c" diff --git a/third_party/sqlite3/parse.shell.c b/third_party/sqlite3/parse.shell.c new file mode 100644 index 000000000..93b0c0e22 --- /dev/null +++ b/third_party/sqlite3/parse.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/parse.c" diff --git a/third_party/sqlite3/pcache.shell.c b/third_party/sqlite3/pcache.shell.c new file mode 100644 index 000000000..fb7b604a0 --- /dev/null +++ b/third_party/sqlite3/pcache.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/pcache.c" diff --git a/third_party/sqlite3/pcache1.shell.c b/third_party/sqlite3/pcache1.shell.c new file mode 100644 index 000000000..1fa0503d3 --- /dev/null +++ b/third_party/sqlite3/pcache1.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/pcache1.c" diff --git a/third_party/sqlite3/pragma.shell.c b/third_party/sqlite3/pragma.shell.c new file mode 100644 index 000000000..bde2f2ceb --- /dev/null +++ b/third_party/sqlite3/pragma.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/pragma.c" diff --git a/third_party/sqlite3/prepare.shell.c b/third_party/sqlite3/prepare.shell.c new file mode 100644 index 000000000..dcb5f5110 --- /dev/null +++ b/third_party/sqlite3/prepare.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/prepare.c" diff --git a/third_party/sqlite3/printf.shell.c b/third_party/sqlite3/printf.shell.c new file mode 100644 index 000000000..bc4baee2d --- /dev/null +++ b/third_party/sqlite3/printf.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/printf.c" diff --git a/third_party/sqlite3/random.shell.c b/third_party/sqlite3/random.shell.c new file mode 100644 index 000000000..eb0b3ba3b --- /dev/null +++ b/third_party/sqlite3/random.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/random.c" diff --git a/third_party/sqlite3/resolve.shell.c b/third_party/sqlite3/resolve.shell.c new file mode 100644 index 000000000..a77164292 --- /dev/null +++ b/third_party/sqlite3/resolve.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/resolve.c" diff --git a/third_party/sqlite3/rowset.shell.c b/third_party/sqlite3/rowset.shell.c new file mode 100644 index 000000000..3c1a53986 --- /dev/null +++ b/third_party/sqlite3/rowset.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/rowset.c" diff --git a/third_party/sqlite3/rtree.shell.c b/third_party/sqlite3/rtree.shell.c new file mode 100644 index 000000000..396f59d20 --- /dev/null +++ b/third_party/sqlite3/rtree.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/rtree.c" diff --git a/third_party/sqlite3/select.shell.c b/third_party/sqlite3/select.shell.c new file mode 100644 index 000000000..be276a733 --- /dev/null +++ b/third_party/sqlite3/select.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/select.c" diff --git a/third_party/sqlite3/series.shell.c b/third_party/sqlite3/series.shell.c new file mode 100644 index 000000000..c2e84dcd7 --- /dev/null +++ b/third_party/sqlite3/series.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/series.c" diff --git a/third_party/sqlite3/shathree.shell.c b/third_party/sqlite3/shathree.shell.c new file mode 100644 index 000000000..88e565d30 --- /dev/null +++ b/third_party/sqlite3/shathree.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/shathree.c" diff --git a/third_party/sqlite3/shell.c b/third_party/sqlite3/shell.c index 165cafbfe..388e4a149 100644 --- a/third_party/sqlite3/shell.c +++ b/third_party/sqlite3/shell.c @@ -31,58 +31,6 @@ ** This file contains code to implement the "sqlite" command line ** utility for accessing SQLite databases. */ -#if (defined(_WIN32) || defined(WIN32)) && !defined(_CRT_SECURE_NO_WARNINGS) -/* This needs to come before any includes for MSVC compiler */ -#define _CRT_SECURE_NO_WARNINGS -#endif - -/* -** Determine if we are dealing with WinRT, which provides only a subset of -** the full Win32 API. -*/ -#if !defined(SQLITE_OS_WINRT) -# define SQLITE_OS_WINRT 0 -#endif - -/* -** Warning pragmas copied from msvc.h in the core. -*/ -#if defined(_MSC_VER) -#pragma warning(disable : 4054) -#pragma warning(disable : 4055) -#pragma warning(disable : 4100) -#pragma warning(disable : 4127) -#pragma warning(disable : 4130) -#pragma warning(disable : 4152) -#pragma warning(disable : 4189) -#pragma warning(disable : 4206) -#pragma warning(disable : 4210) -#pragma warning(disable : 4232) -#pragma warning(disable : 4244) -#pragma warning(disable : 4305) -#pragma warning(disable : 4306) -#pragma warning(disable : 4702) -#pragma warning(disable : 4706) -#endif /* defined(_MSC_VER) */ - -/* -** No support for loadable extensions in VxWorks. -*/ -#if (defined(__RTP__) || defined(_WRS_KERNEL)) && !SQLITE_OMIT_LOAD_EXTENSION -# define SQLITE_OMIT_LOAD_EXTENSION 1 -#endif - -/* -** Enable large-file support for fopen() and friends on unix. -*/ -#ifndef SQLITE_DISABLE_LFS -# define _LARGE_FILE 1 -# ifndef _FILE_OFFSET_BITS -# define _FILE_OFFSET_BITS 64 -# endif -# define _LARGEFILE_SOURCE 1 -#endif - #include "libc/assert.h" #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" @@ -102,23 +50,23 @@ #include "third_party/sqlite3/sqlite3expert.h" #include "third_party/zlib/zlib.h" #include "third_party/sqlite3/sqlite3.h" +#include "libc/str/str.h" +#include "third_party/musl/passwd.h" +#include "libc/calls/calls.h" +#include "libc/calls/weirdtypes.h" +#include "libc/calls/calls.h" +#include "third_party/linenoise/linenoise.h" +#include "libc/sysv/consts/rusage.h" +#include "libc/time/time.h" +#if SQLITE_USER_AUTHENTICATION +#include "third_party/sqlite3/sqlite3userauth.inc" +#endif typedef sqlite3_int64 i64; typedef sqlite3_uint64 u64; typedef unsigned char u8; -#if SQLITE_USER_AUTHENTICATION -#include "third_party/sqlite3/sqlite3userauth.inc" -#endif -#include "libc/str/str.h" -#if !defined(_WIN32) && !defined(WIN32) -#if !defined(__RTP__) && !defined(_WRS_KERNEL) -#include "third_party/musl/passwd.h" -#endif -#endif #if (!defined(_WIN32) && !defined(WIN32)) || defined(__MINGW32__) -#include "libc/calls/calls.h" -#include "libc/isystem/unistd.h" #define GETPID getpid #if defined(__MINGW32__) #define DIRENT dirent @@ -129,8 +77,6 @@ typedef unsigned char u8; #else # define GETPID (int)GetCurrentProcessId #endif -#include "libc/calls/weirdtypes.h" -#include "libc/calls/calls.h" #if HAVE_READLINE # include @@ -150,7 +96,6 @@ typedef unsigned char u8; # define shell_readline(X) readline(X) #elif HAVE_LINENOISE -#include "third_party/linenoise/linenoise.h" #define shell_add_history(X) linenoiseHistoryAdd(X) #define shell_read_history(X) linenoiseHistoryLoad(X) @@ -225,8 +170,6 @@ static sqlite3_int64 timeOfDay(void){ } #if !defined(_WIN32) && !defined(WIN32) && !defined(__minux) -#include "libc/sysv/consts/rusage.h" -#include "libc/time/time.h" /* Saved resource information for the beginning of an operation */ static struct rusage sBegin; /* CPU time at start */ diff --git a/third_party/sqlite3/shell.c.in b/third_party/sqlite3/shell.c.in index 92b660cd6..bca9bba10 100644 --- a/third_party/sqlite3/shell.c.in +++ b/third_party/sqlite3/shell.c.in @@ -65,29 +65,18 @@ # define _LARGEFILE_SOURCE 1 #endif -#include -#include -#include -#include -#include "sqlite3.h" typedef sqlite3_int64 i64; typedef sqlite3_uint64 u64; typedef unsigned char u8; #if SQLITE_USER_AUTHENTICATION # include "sqlite3userauth.inc" #endif -#include -#include #if !defined(_WIN32) && !defined(WIN32) -# include # if !defined(__RTP__) && !defined(_WRS_KERNEL) -# include # endif #endif #if (!defined(_WIN32) && !defined(WIN32)) || defined(__MINGW32__) -# include -# include # define GETPID getpid # if defined(__MINGW32__) # define DIRENT dirent diff --git a/third_party/sqlite3/sqlar.shell.c b/third_party/sqlite3/sqlar.shell.c new file mode 100644 index 000000000..cac08a8e9 --- /dev/null +++ b/third_party/sqlite3/sqlar.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/sqlar.c" diff --git a/third_party/sqlite3/sqlite3.mk b/third_party/sqlite3/sqlite3.mk index e2d6b4925..340bc76df 100644 --- a/third_party/sqlite3/sqlite3.mk +++ b/third_party/sqlite3/sqlite3.mk @@ -20,6 +20,7 @@ THIRD_PARTY_SQLITE3 = $(THIRD_PARTY_SQLITE3_A_DEPS) $(THIRD_PARTY_SQLITE3_A) THIRD_PARTY_SQLITE3_A = o/$(MODE)/third_party/sqlite3/libsqlite3.a THIRD_PARTY_SQLITE3_A_FILES := $(wildcard third_party/sqlite3/*) THIRD_PARTY_SQLITE3_A_HDRS = $(filter %.h,$(THIRD_PARTY_SQLITE3_A_FILES)) +THIRD_PARTY_SQLITE3_A_INCS = $(filter %.inc,$(THIRD_PARTY_SQLITE3_A_FILES)) THIRD_PARTY_SQLITE3_A_SRCS_C = $(filter %.c,$(THIRD_PARTY_SQLITE3_A_FILES)) THIRD_PARTY_SQLITE3_A_SRCS_T = $(filter %.inc,$(THIRD_PARTY_SQLITE3_A_FILES)) THIRD_PARTY_SQLITE3_BINS = $(THIRD_PARTY_SQLITE3_COMS) $(THIRD_PARTY_SQLITE3_COMS:%=%.dbg) @@ -29,10 +30,10 @@ THIRD_PARTY_SQLITE3_A_SRCS = \ $(THIRD_PARTY_SQLITE3_A_SRCS_T) THIRD_PARTY_SQLITE3_A_OBJS = \ - $(filter-out %/shell.o,$(THIRD_PARTY_SQLITE3_A_SRCS_C:%.c=o/$(MODE)/%.o)) + $(filter-out %shell.o,$(THIRD_PARTY_SQLITE3_A_SRCS_C:%.c=o/$(MODE)/%.o)) THIRD_PARTY_SQLITE3_SHELL_OBJS = \ - $(THIRD_PARTY_SQLITE3_A_SRCS_C:%.c=o/$(MODE)/%.shell.o) + $(filter %shell.o,$(THIRD_PARTY_SQLITE3_A_SRCS_C:%.c=o/$(MODE)/%.o)) THIRD_PARTY_SQLITE3_COMS = \ o/$(MODE)/third_party/sqlite3/sqlite3.com @@ -71,11 +72,11 @@ THIRD_PARTY_SQLITE3_A_DEPS := \ o/$(MODE)/third_party/sqlite3/sqlite3.com.dbg: \ $(THIRD_PARTY_SQLITE3_A_DEPS) \ $(THIRD_PARTY_SQLITE3_SHELL_OBJS) \ - o/$(MODE)/third_party/sqlite3/shell.shell.o \ + o/$(MODE)/third_party/sqlite3/shell.o \ o/$(MODE)/third_party/sqlite3/shell.pkg \ $(CRT) \ $(APE_NO_MODIFY_SELF) - -@$(APELINK) + @$(APELINK) o/$(MODE)/third_party/sqlite3/sqlite3.com: \ o/$(MODE)/third_party/sqlite3/sqlite3.com.dbg \ @@ -167,7 +168,7 @@ o//third_party/sqlite3/vdbe.o: \ OVERRIDE_CFLAGS += \ -Os -o/$(MODE)/third_party/sqlite3/shell.shell.o: \ +o/$(MODE)/third_party/sqlite3/shell.o: \ OVERRIDE_CFLAGS += \ -DSTACK_FRAME_UNLIMITED @@ -184,18 +185,26 @@ o/$(MODE)/third_party/sqlite3/parse.o: \ OVERRIDE_CFLAGS += \ -fpie -o/$(MODE)/%.shell.o: %.c o/$(MODE)/%.o - @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) $(OUTPUT_OPTION) $< - -o/$(MODE)/third_party/sqlite3/shell.shell.o: QUOTA = -M512m -C16 -L180 +o/$(MODE)/third_party/sqlite3/shell.o: QUOTA = -M512m -C16 -L180 o/$(MODE)/third_party/sqlite3/vdbe.o: QUOTA = -M1024m o/$(MODE)/third_party/sqlite3/vdbe.shell.o: QUOTA = -M1024m o/$(MODE)/third_party/sqlite3/fts5.o: QUOTA = -M512m -C16 o/$(MODE)/third_party/sqlite3/fts5.shell.o: QUOTA = -M512m -C16 -L180 +o/$(MODE)/third_party/sqlite3/rtree.o: \ + third_party/sqlite3/rtree.c \ + third_party/sqlite3/geopoly.inc \ + third_party/gdtoa/gdtoa.h + +o/$(MODE)/third_party/sqlite3/rtree.shell.o: \ + third_party/sqlite3/rtree.shell.c \ + third_party/sqlite3/geopoly.inc \ + third_party/gdtoa/gdtoa.h + THIRD_PARTY_SQLITE3_LIBS = $(foreach x,$(THIRD_PARTY_SQLITE3_ARTIFACTS),$($(x))) THIRD_PARTY_SQLITE3_SRCS = $(foreach x,$(THIRD_PARTY_SQLITE3_ARTIFACTS),$($(x)_SRCS)) THIRD_PARTY_SQLITE3_HDRS = $(foreach x,$(THIRD_PARTY_SQLITE3_ARTIFACTS),$($(x)_HDRS)) +THIRD_PARTY_SQLITE3_INCS = $(foreach x,$(THIRD_PARTY_SQLITE3_ARTIFACTS),$($(x)_INCS)) THIRD_PARTY_SQLITE3_CHECKS = $(foreach x,$(THIRD_PARTY_SQLITE3_ARTIFACTS),$($(x)_CHECKS)) THIRD_PARTY_SQLITE3_OBJS = $(foreach x,$(THIRD_PARTY_SQLITE3_ARTIFACTS),$($(x)_OBJS)) diff --git a/third_party/sqlite3/sqlite3expert.shell.c b/third_party/sqlite3/sqlite3expert.shell.c new file mode 100644 index 000000000..e7a07c8f0 --- /dev/null +++ b/third_party/sqlite3/sqlite3expert.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/sqlite3expert.c" diff --git a/third_party/sqlite3/sqlite3rbu.shell.c b/third_party/sqlite3/sqlite3rbu.shell.c new file mode 100644 index 000000000..e08e0cb3c --- /dev/null +++ b/third_party/sqlite3/sqlite3rbu.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/sqlite3rbu.c" diff --git a/third_party/sqlite3/sqlite3session.shell.c b/third_party/sqlite3/sqlite3session.shell.c new file mode 100644 index 000000000..f317e451c --- /dev/null +++ b/third_party/sqlite3/sqlite3session.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/sqlite3session.c" diff --git a/third_party/sqlite3/sqliteInt.inc b/third_party/sqlite3/sqliteInt.inc index 7ec44642d..48a868c6d 100644 --- a/third_party/sqlite3/sqliteInt.inc +++ b/third_party/sqlite3/sqliteInt.inc @@ -1193,6 +1193,13 @@ typedef struct With With; typedef int VList; typedef u32 Pgno; +/* +** Enable SQLITE_ENABLE_EXPLAIN_COMMENTS if SQLITE_DEBUG is turned on. +*/ +#if !defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) && defined(SQLITE_DEBUG) +# define SQLITE_ENABLE_EXPLAIN_COMMENTS 1 +#endif + /* ** Defer sourcing vdbe.h and btree.h until after the "u8" and ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque diff --git a/third_party/sqlite3/status.shell.c b/third_party/sqlite3/status.shell.c new file mode 100644 index 000000000..4791a6adf --- /dev/null +++ b/third_party/sqlite3/status.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/status.c" diff --git a/third_party/sqlite3/stmt.shell.c b/third_party/sqlite3/stmt.shell.c new file mode 100644 index 000000000..dc4e9b8d1 --- /dev/null +++ b/third_party/sqlite3/stmt.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/stmt.c" diff --git a/third_party/sqlite3/table.shell.c b/third_party/sqlite3/table.shell.c new file mode 100644 index 000000000..01d8c6a03 --- /dev/null +++ b/third_party/sqlite3/table.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/table.c" diff --git a/third_party/sqlite3/threads.shell.c b/third_party/sqlite3/threads.shell.c new file mode 100644 index 000000000..f0ce99218 --- /dev/null +++ b/third_party/sqlite3/threads.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/threads.c" diff --git a/third_party/sqlite3/tokenize.shell.c b/third_party/sqlite3/tokenize.shell.c new file mode 100644 index 000000000..42f65cb63 --- /dev/null +++ b/third_party/sqlite3/tokenize.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/tokenize.c" diff --git a/third_party/sqlite3/treeview.shell.c b/third_party/sqlite3/treeview.shell.c new file mode 100644 index 000000000..8968376a5 --- /dev/null +++ b/third_party/sqlite3/treeview.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/treeview.c" diff --git a/third_party/sqlite3/trigger.shell.c b/third_party/sqlite3/trigger.shell.c new file mode 100644 index 000000000..6cd1138d4 --- /dev/null +++ b/third_party/sqlite3/trigger.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/trigger.c" diff --git a/third_party/sqlite3/uint.shell.c b/third_party/sqlite3/uint.shell.c new file mode 100644 index 000000000..ad28396bb --- /dev/null +++ b/third_party/sqlite3/uint.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/uint.c" diff --git a/third_party/sqlite3/update.shell.c b/third_party/sqlite3/update.shell.c new file mode 100644 index 000000000..74c7da8d0 --- /dev/null +++ b/third_party/sqlite3/update.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/update.c" diff --git a/third_party/sqlite3/upsert.shell.c b/third_party/sqlite3/upsert.shell.c new file mode 100644 index 000000000..d5c34d903 --- /dev/null +++ b/third_party/sqlite3/upsert.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/upsert.c" diff --git a/third_party/sqlite3/userauth.shell.c b/third_party/sqlite3/userauth.shell.c new file mode 100644 index 000000000..541a0f56d --- /dev/null +++ b/third_party/sqlite3/userauth.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/userauth.c" diff --git a/third_party/sqlite3/utf.shell.c b/third_party/sqlite3/utf.shell.c new file mode 100644 index 000000000..0548bae95 --- /dev/null +++ b/third_party/sqlite3/utf.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/utf.c" diff --git a/third_party/sqlite3/util.shell.c b/third_party/sqlite3/util.shell.c new file mode 100644 index 000000000..57c1df4e6 --- /dev/null +++ b/third_party/sqlite3/util.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/util.c" diff --git a/third_party/sqlite3/vacuum.shell.c b/third_party/sqlite3/vacuum.shell.c new file mode 100644 index 000000000..25781dce4 --- /dev/null +++ b/third_party/sqlite3/vacuum.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/vacuum.c" diff --git a/third_party/sqlite3/vdbe.shell.c b/third_party/sqlite3/vdbe.shell.c new file mode 100644 index 000000000..9724dc871 --- /dev/null +++ b/third_party/sqlite3/vdbe.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/vdbe.c" diff --git a/third_party/sqlite3/vdbeapi.shell.c b/third_party/sqlite3/vdbeapi.shell.c new file mode 100644 index 000000000..5ac9ccf3c --- /dev/null +++ b/third_party/sqlite3/vdbeapi.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/vdbeapi.c" diff --git a/third_party/sqlite3/vdbeaux.shell.c b/third_party/sqlite3/vdbeaux.shell.c new file mode 100644 index 000000000..ea0c7b971 --- /dev/null +++ b/third_party/sqlite3/vdbeaux.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/vdbeaux.c" diff --git a/third_party/sqlite3/vdbeblob.shell.c b/third_party/sqlite3/vdbeblob.shell.c new file mode 100644 index 000000000..82297569b --- /dev/null +++ b/third_party/sqlite3/vdbeblob.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/vdbeblob.c" diff --git a/third_party/sqlite3/vdbemem.shell.c b/third_party/sqlite3/vdbemem.shell.c new file mode 100644 index 000000000..9d53115a3 --- /dev/null +++ b/third_party/sqlite3/vdbemem.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/vdbemem.c" diff --git a/third_party/sqlite3/vdbesort.shell.c b/third_party/sqlite3/vdbesort.shell.c new file mode 100644 index 000000000..0c487de1a --- /dev/null +++ b/third_party/sqlite3/vdbesort.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/vdbesort.c" diff --git a/third_party/sqlite3/vdbetrace.shell.c b/third_party/sqlite3/vdbetrace.shell.c new file mode 100644 index 000000000..b4af282ed --- /dev/null +++ b/third_party/sqlite3/vdbetrace.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/vdbetrace.c" diff --git a/third_party/sqlite3/vdbevtab.shell.c b/third_party/sqlite3/vdbevtab.shell.c new file mode 100644 index 000000000..001d48b24 --- /dev/null +++ b/third_party/sqlite3/vdbevtab.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/vdbevtab.c" diff --git a/third_party/sqlite3/vtab.shell.c b/third_party/sqlite3/vtab.shell.c new file mode 100644 index 000000000..8415afeda --- /dev/null +++ b/third_party/sqlite3/vtab.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/vtab.c" diff --git a/third_party/sqlite3/wal.shell.c b/third_party/sqlite3/wal.shell.c new file mode 100644 index 000000000..edebe71fd --- /dev/null +++ b/third_party/sqlite3/wal.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/wal.c" diff --git a/third_party/sqlite3/walker.shell.c b/third_party/sqlite3/walker.shell.c new file mode 100644 index 000000000..56ea9cf79 --- /dev/null +++ b/third_party/sqlite3/walker.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/walker.c" diff --git a/third_party/sqlite3/where.shell.c b/third_party/sqlite3/where.shell.c new file mode 100644 index 000000000..3b5511ffc --- /dev/null +++ b/third_party/sqlite3/where.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/where.c" diff --git a/third_party/sqlite3/wherecode.shell.c b/third_party/sqlite3/wherecode.shell.c new file mode 100644 index 000000000..328b2b1ad --- /dev/null +++ b/third_party/sqlite3/wherecode.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/wherecode.c" diff --git a/third_party/sqlite3/whereexpr.shell.c b/third_party/sqlite3/whereexpr.shell.c new file mode 100644 index 000000000..8c01261a2 --- /dev/null +++ b/third_party/sqlite3/whereexpr.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/whereexpr.c" diff --git a/third_party/sqlite3/window.shell.c b/third_party/sqlite3/window.shell.c new file mode 100644 index 000000000..290a325c9 --- /dev/null +++ b/third_party/sqlite3/window.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/window.c" diff --git a/third_party/sqlite3/zipfile.shell.c b/third_party/sqlite3/zipfile.shell.c new file mode 100644 index 000000000..6a6d94529 --- /dev/null +++ b/third_party/sqlite3/zipfile.shell.c @@ -0,0 +1 @@ +#include "third_party/sqlite3/zipfile.c" diff --git a/third_party/zip/crypt.c b/third_party/zip/crypt.c index 8ca9871fe..5e0155f9b 100644 --- a/third_party/zip/crypt.c +++ b/third_party/zip/crypt.c @@ -1,4 +1,9 @@ /* clang-format off */ +#define ZCRYPT_INTERNAL +#include "third_party/zip/zip.h" +#include "third_party/zip/crypt.h" +#include "third_party/zip/ttyio.h" +#include "libc/rand/rand.h" /* Copyright (c) 1990-2008 Info-ZIP. All rights reserved. @@ -30,12 +35,6 @@ version without encryption capabilities). */ -#define ZCRYPT_INTERNAL -#include "third_party/zip/zip.h" -#include "third_party/zip/crypt.h" -#include "third_party/zip/ttyio.h" -#include "libc/rand/rand.h" - #if CRYPT #ifndef FALSE diff --git a/third_party/zip/crypt_.c b/third_party/zip/crypt_.c new file mode 100644 index 000000000..9606c2739 --- /dev/null +++ b/third_party/zip/crypt_.c @@ -0,0 +1,2 @@ +#define UTIL +#include "third_party/zip/crypt.c" diff --git a/third_party/zip/fileio_.c b/third_party/zip/fileio_.c new file mode 100644 index 000000000..45b0f6665 --- /dev/null +++ b/third_party/zip/fileio_.c @@ -0,0 +1,2 @@ +#define UTIL +#include "third_party/zip/fileio.c" diff --git a/third_party/zip/unix.c b/third_party/zip/unix.c index 453c3fad4..dbdc2eaca 100644 --- a/third_party/zip/unix.c +++ b/third_party/zip/unix.c @@ -1,4 +1,14 @@ /* clang-format off */ +#include "libc/calls/struct/dirent.h" +#include "libc/calls/calls.h" +#include "libc/sysv/consts/s.h" +#include "third_party/zip/zip.h" +#include "libc/time/time.h" +#include "libc/calls/struct/stat.macros.h" +#include "libc/calls/calls.h" +#include "third_party/zip/osdep.h" +#include "libc/sysv/consts/dt.h" + /* unix/unix.c - Zip 3 @@ -9,15 +19,6 @@ If, for some reason, all these files are missing, the Info-ZIP license also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html */ -#include "libc/calls/struct/dirent.h" -#include "libc/calls/calls.h" -#include "libc/sysv/consts/s.h" -#include "third_party/zip/zip.h" -#include "libc/time/time.h" -#include "libc/calls/struct/stat.macros.h" -#include "libc/calls/calls.h" -#include "third_party/zip/osdep.h" -#include "libc/sysv/consts/dt.h" #ifndef UTIL /* the companion #endif is a bit of ways down ... */ diff --git a/third_party/zip/unix_.c b/third_party/zip/unix_.c new file mode 100644 index 000000000..2a9554609 --- /dev/null +++ b/third_party/zip/unix_.c @@ -0,0 +1,2 @@ +#define UTIL +#include "third_party/zip/unix.c" diff --git a/third_party/zip/util_.c b/third_party/zip/util_.c new file mode 100644 index 000000000..4a30a0f04 --- /dev/null +++ b/third_party/zip/util_.c @@ -0,0 +1,2 @@ +#define UTIL +#include "third_party/zip/util.c" diff --git a/third_party/zip/zip.h b/third_party/zip/zip.h index 9b0e6f926..c493a86c3 100644 --- a/third_party/zip/zip.h +++ b/third_party/zip/zip.h @@ -1,81 +1,6 @@ -/* clang-format off */ -/* - zip.h - Zip 3 - -/---------------------------------------------------------------------/ - -Info-ZIP Licence - -This is version 2007-Mar-4 of the Info-ZIP license. -The definitive version of this document should be available at -ftp://ftp.info-zip.org/pub/infozip/license.html indefinitely and -a copy at http://www.info-zip.org/pub/infozip/license.html. - - -Copyright (c) 1990-2008 Info-ZIP. All rights reserved. - -For the purposes of this copyright and license, "Info-ZIP" is defined as -the following set of individuals: - - Mark Adler, John Bush, Karl Davis, Harald Denker, Jean-Michel Dubois, - Jean-loup Gailly, Hunter Goatley, Ed Gordon, Ian Gorman, Chris Herborth, - Dirk Haase, Greg Hartwig, Robert Heath, Jonathan Hudson, Paul Kienitz, - David Kirschbaum, Johnny Lee, Onno van der Linden, Igor Mandrichenko, - Steve P. Miller, Sergio Monesi, Keith Owens, George Petrov, Greg Roelofs, - Kai Uwe Rommel, Steve Salisbury, Dave Smith, Steven M. Schweda, - Christian Spieler, Cosmin Truta, Antoine Verheijen, Paul von Behren, - Rich Wales, Mike White. - -This software is provided "as is," without warranty of any kind, express -or implied. In no event shall Info-ZIP or its contributors be held liable -for any direct, indirect, incidental, special or consequential damages -arising out of the use of or inability to use this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the above disclaimer and the following restrictions: - - 1. Redistributions of source code (in whole or in part) must retain - the above copyright notice, definition, disclaimer, and this list - of conditions. - - 2. Redistributions in binary form (compiled executables and libraries) - must reproduce the above copyright notice, definition, disclaimer, - and this list of conditions in documentation and/or other materials - provided with the distribution. The sole exception to this condition - is redistribution of a standard UnZipSFX binary (including SFXWiz) as - part of a self-extracting archive; that is permitted without inclusion - of this license, as long as the normal SFX banner has not been removed - from the binary or disabled. - - 3. Altered versions--including, but not limited to, ports to new operating - systems, existing ports with new graphical interfaces, versions with - modified or added functionality, and dynamic, shared, or static library - versions not from Info-ZIP--must be plainly marked as such and must not - be misrepresented as being the original source or, if binaries, - compiled from the original source. Such altered versions also must not - be misrepresented as being Info-ZIP releases--including, but not - limited to, labeling of the altered versions with the names "Info-ZIP" - (or any variation thereof, including, but not limited to, different - capitalizations), "Pocket UnZip," "WiZ" or "MacZip" without the - explicit permission of Info-ZIP. Such altered versions are further - prohibited from misrepresentative use of the Zip-Bugs or Info-ZIP - e-mail addresses or the Info-ZIP URL(s), such as to imply Info-ZIP - will provide support for the altered versions. - - 4. Info-ZIP retains the right to use the names "Info-ZIP," "Zip," "UnZip," - "UnZipSFX," "WiZ," "Pocket UnZip," "Pocket Zip," and "MacZip" for its - own source and binary releases. - -/---------------------------------------------------------------------/ - -*/ - -/* - * zip.h by Mark Adler - */ #ifndef __zip_h #define __zip_h 1 +/* clang-format off */ #define ZIP /* for crypt.c: include zip password functions, not unzip */ @@ -88,6 +13,9 @@ typedef unsigned long ulg; /* unsigned 32-bit value */ /* Set up portability */ #include "third_party/zip/tailor.h" +/* Error return codes and PERR macro */ +#include "third_party/zip/ziperr.h" + /* In the utilities, the crc32() function is only used for UNICODE_SUPPORT. */ #if defined(UTIL) && !defined(UNICODE_SUPPORT) # define CRC_TABLE_ONLY @@ -273,9 +201,6 @@ struct plist { #define ZP_PW_ENTER 0 /* request for encryption password */ #define ZP_PW_VERIFY 1 /* request for reentering password */ -/* Error return codes and PERR macro */ -#include "third_party/zip/ziperr.h" - #if 0 /* Optimization: use the (const) result of crc32(0L,NULL,0) */ # define CRCVAL_INITIAL crc32(0L, (uch *)NULL, 0) # if 00 /* not used, should be removed !! */ @@ -870,13 +795,6 @@ void bi_init OF((char *, unsigned int, int)); # endif #endif /* WIN32 */ -#if (defined(WINDLL) || defined(DLL_ZIPAPI)) -/*--------------------------------------------------------------------------- - Prototypes for public Zip API (DLL) functions. - ---------------------------------------------------------------------------*/ -#include "third_party/zip/api.h" -#endif /* WINDLL || DLL_ZIPAPI */ - /* WIN32_OEM */ #ifdef WIN32 diff --git a/third_party/zip/zip.mk b/third_party/zip/zip.mk index 74cfffd5e..98f3d7aa0 100644 --- a/third_party/zip/zip.mk +++ b/third_party/zip/zip.mk @@ -5,7 +5,7 @@ PKGS += THIRD_PARTY_ZIP THIRD_PARTY_ZIP_FILES := $(wildcard third_party/zip/*) THIRD_PARTY_ZIP_SRCS = $(filter %.c,$(THIRD_PARTY_ZIP_FILES)) -#THIRD_PARTY_ZIP_HDRS = $(filter %.h,$(THIRD_PARTY_ZIP_FILES)) +THIRD_PARTY_ZIP_HDRS = $(filter %.h,$(THIRD_PARTY_ZIP_FILES)) THIRD_PARTY_ZIP_INCS = $(filter %.inc,$(THIRD_PARTY_ZIP_FILES)) THIRD_PARTY_ZIP_COMS = \ @@ -163,14 +163,6 @@ o/$(MODE)/third_party/zip/zipup.o: \ -DZIP64_SUPPORT \ -DBZIP2_SUPPORT -o/$(MODE)/third_party/zip/crypt_.o \ -o/$(MODE)/third_party/zip/unix_.o \ -o/$(MODE)/third_party/zip/zipfile_.o \ -o/$(MODE)/third_party/zip/fileio_.o \ -o/$(MODE)/third_party/zip/util_.o: \ - OVERRIDE_CPPFLAGS += \ - -DUTIL - o/$(MODE)/third_party/zip/zip.o \ o/$(MODE)/third_party/zip/zipsplit.o \ o/$(MODE)/third_party/zip/fileio.o \ @@ -178,11 +170,6 @@ o/$(MODE)/third_party/zip/fileio_.o: \ OVERRIDE_CPPFLAGS += \ -DSTACK_FRAME_UNLIMITED -o/$(MODE)/third_party/zip/%_.o: \ - third_party/zip/%.c \ - o/$(MODE)/third_party/zip/%.o - @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) $(OUTPUT_OPTION) $< - .PHONY: o/$(MODE)/third_party/zip o/$(MODE)/third_party/zip: \ $(THIRD_PARTY_ZIP_BINS) \ diff --git a/third_party/zip/zipfile_.c b/third_party/zip/zipfile_.c new file mode 100644 index 000000000..702f9c2a3 --- /dev/null +++ b/third_party/zip/zipfile_.c @@ -0,0 +1,2 @@ +#define UTIL +#include "third_party/zip/zipfile.c" diff --git a/third_party/zlib/gz/gz.mk b/third_party/zlib/gz/gz.mk index aa83ff83d..306d14d3f 100644 --- a/third_party/zlib/gz/gz.mk +++ b/third_party/zlib/gz/gz.mk @@ -8,6 +8,7 @@ THIRD_PARTY_ZLIB_GZ = $(THIRD_PARTY_ZLIB_GZ_A_DEPS) $(THIRD_PARTY_ZLIB_GZ_A) THIRD_PARTY_ZLIB_GZ_A = o/$(MODE)/third_party/zlib/gz/gz.a THIRD_PARTY_ZLIB_GZ_A_FILES := $(wildcard third_party/zlib/gz/*) THIRD_PARTY_ZLIB_GZ_A_HDRS = $(filter %.h,$(THIRD_PARTY_ZLIB_GZ_A_FILES)) +THIRD_PARTY_ZLIB_GZ_A_INCS = $(filter %.inc,$(THIRD_PARTY_ZLIB_GZ_A_FILES)) THIRD_PARTY_ZLIB_GZ_A_SRCS = $(filter %.c,$(THIRD_PARTY_ZLIB_GZ_A_FILES)) THIRD_PARTY_ZLIB_GZ_A_OBJS = $(THIRD_PARTY_ZLIB_GZ_A_SRCS:%.c=o/$(MODE)/%.o) @@ -47,6 +48,7 @@ $(THIRD_PARTY_ZLIB_GZ_OBJS): \ THIRD_PARTY_ZLIB_GZ_LIBS = $(foreach x,$(THIRD_PARTY_ZLIB_GZ_ARTIFACTS),$($(x))) THIRD_PARTY_ZLIB_GZ_SRCS = $(foreach x,$(THIRD_PARTY_ZLIB_GZ_ARTIFACTS),$($(x)_SRCS)) THIRD_PARTY_ZLIB_GZ_HDRS = $(foreach x,$(THIRD_PARTY_ZLIB_GZ_ARTIFACTS),$($(x)_HDRS)) +THIRD_PARTY_ZLIB_GZ_INCS = $(foreach x,$(THIRD_PARTY_ZLIB_GZ_ARTIFACTS),$($(x)_INCS)) THIRD_PARTY_ZLIB_GZ_BINS = $(foreach x,$(THIRD_PARTY_ZLIB_GZ_ARTIFACTS),$($(x)_BINS)) THIRD_PARTY_ZLIB_GZ_CHECKS = $(foreach x,$(THIRD_PARTY_ZLIB_GZ_ARTIFACTS),$($(x)_CHECKS)) THIRD_PARTY_ZLIB_GZ_OBJS = $(foreach x,$(THIRD_PARTY_ZLIB_GZ_ARTIFACTS),$($(x)_OBJS)) diff --git a/third_party/zlib/zlib.mk b/third_party/zlib/zlib.mk index 1b3b08dd5..fd38e8bba 100644 --- a/third_party/zlib/zlib.mk +++ b/third_party/zlib/zlib.mk @@ -7,8 +7,7 @@ THIRD_PARTY_ZLIB_ARTIFACTS += THIRD_PARTY_ZLIB_A THIRD_PARTY_ZLIB = $(THIRD_PARTY_ZLIB_A_DEPS) $(THIRD_PARTY_ZLIB_A) THIRD_PARTY_ZLIB_A = o/$(MODE)/third_party/zlib/zlib.a THIRD_PARTY_ZLIB_A_FILES := $(wildcard third_party/zlib/*) -THIRD_PARTY_ZLIB_A_HDRS = third_party/zlib/zlib.h third_party/zlib/puff.h -THIRD_PARTY_ZLIB_A_HDRS_ALL = $(filter %.h,$(THIRD_PARTY_ZLIB_A_FILES)) +THIRD_PARTY_ZLIB_A_HDRS = $(filter %.h,$(THIRD_PARTY_ZLIB_A_FILES)) THIRD_PARTY_ZLIB_A_SRCS_S = $(filter %.S,$(THIRD_PARTY_ZLIB_A_FILES)) THIRD_PARTY_ZLIB_A_SRCS_C = $(filter %.c,$(THIRD_PARTY_ZLIB_A_FILES)) @@ -22,7 +21,7 @@ THIRD_PARTY_ZLIB_A_OBJS = \ THIRD_PARTY_ZLIB_A_CHECKS = \ $(THIRD_PARTY_ZLIB_A).pkg \ - $(THIRD_PARTY_ZLIB_A_HDRS_ALL:%=o/$(MODE)/%.ok) + $(THIRD_PARTY_ZLIB_A_HDRS:%=o/$(MODE)/%.ok) THIRD_PARTY_ZLIB_A_DIRECTDEPS = \ LIBC_INTRIN \ @@ -61,7 +60,6 @@ o/$(MODE)/third_party/zlib/adler32.o: \ THIRD_PARTY_ZLIB_LIBS = $(foreach x,$(THIRD_PARTY_ZLIB_ARTIFACTS),$($(x))) THIRD_PARTY_ZLIB_SRCS = $(foreach x,$(THIRD_PARTY_ZLIB_ARTIFACTS),$($(x)_SRCS)) THIRD_PARTY_ZLIB_HDRS = $(foreach x,$(THIRD_PARTY_ZLIB_ARTIFACTS),$($(x)_HDRS)) -THIRD_PARTY_ZLIB_HDRS_ALL = $(foreach x,$(THIRD_PARTY_ZLIB_ARTIFACTS),$($(x)_HDRS_ALL)) THIRD_PARTY_ZLIB_BINS = $(foreach x,$(THIRD_PARTY_ZLIB_ARTIFACTS),$($(x)_BINS)) THIRD_PARTY_ZLIB_CHECKS = $(foreach x,$(THIRD_PARTY_ZLIB_ARTIFACTS),$($(x)_CHECKS)) THIRD_PARTY_ZLIB_OBJS = $(foreach x,$(THIRD_PARTY_ZLIB_ARTIFACTS),$($(x)_OBJS)) diff --git a/tool/build/assimilate.c b/tool/build/assimilate.c index 06ab70324..87209d262 100644 --- a/tool/build/assimilate.c +++ b/tool/build/assimilate.c @@ -63,8 +63,10 @@ APE shell script format. This is useful on UNIX operating systems when\n\ you want to use your APE programs as script interpreter or for setuid.\n\ " -#define MODE_ELF 1 -#define MODE_MACHO 2 +#define MODE_NATIVE 0 +#define MODE_ELF 1 +#define MODE_MACHO 2 +#define MODE_PE 3 int g_mode; bool g_force; @@ -94,11 +96,13 @@ void GetOpts(int argc, char *argv[]) { exit(64); } } - if (!g_mode) { + if (g_mode == MODE_NATIVE) { if (IsXnu()) { g_mode = MODE_MACHO; - } else { + } else if (IsLinux() || IsFreebsd() || IsNetbsd() || IsOpenbsd()) { g_mode = MODE_ELF; + } else { + g_mode = MODE_PE; } } } @@ -233,6 +237,20 @@ void Assimilate(void) { kprintf("%s: mmap failed: %m\n", prog); exit(16); } + if (g_mode == MODE_PE) { + if (READ16LE(p) == READ16LE("MZ")) { + if (!g_force) { + kprintf("%s: program is already an elf binary\n", prog); + if (g_mode != MODE_ELF) { + exitcode = 1; + } + } + goto Finish; + } else { + kprintf("%s: currently cannot back-convert to pe\n", prog); + exit(17); + } + } if (READ32LE(p) == READ32LE("\177ELF")) { if (!g_force) { kprintf("%s: program is already an elf binary\n", prog); diff --git a/tool/build/build.mk b/tool/build/build.mk index db81a22e5..3d7a7cdbf 100644 --- a/tool/build/build.mk +++ b/tool/build/build.mk @@ -85,14 +85,6 @@ o/$(MODE)/tool/build/%.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) -o/$(MODE)/tool/build/blinkenlights.com.dbg: \ - $(TOOL_BUILD_DEPS) \ - o/$(MODE)/tool/build/build.pkg \ - o/$(MODE)/tool/build/blinkenlights.o \ - $(CRT) \ - $(APE_NO_MODIFY_SELF) - @$(APELINK) - .PRECIOUS: o/$(MODE)/tool/build/blinkenlights.com o/$(MODE)/tool/build/blinkenlights.com: \ o/$(MODE)/tool/build/blinkenlights.com.dbg \ @@ -104,50 +96,27 @@ o/$(MODE)/tool/build/blinkenlights.com: \ @$(COMPILE) -AZIP -T$@ o/$(MODE)/third_party/zip/zip.com -9qj $@ \ o/$(MODE)/tool/build/.blinkenlights/.symtab -o/$(MODE)/tool/build/ar.com.dbg: \ - $(TOOL_BUILD_DEPS) \ - o/$(MODE)/tool/build/build.pkg \ - o/$(MODE)/tool/build/ar.o \ - $(CRT) \ - $(APE_NO_MODIFY_SELF) - @$(APELINK) - -o/$(MODE)/tool/build/package.com.dbg: \ - $(TOOL_BUILD_DEPS) \ - o/$(MODE)/tool/build/build.pkg \ - o/$(MODE)/tool/build/package.o \ - $(CRT) \ - $(APE_NO_MODIFY_SELF) - @$(APELINK) - -o/$(MODE)/tool/build/mkdeps.com.dbg: \ - $(TOOL_BUILD_DEPS) \ - o/$(MODE)/tool/build/build.pkg \ - o/$(MODE)/tool/build/mkdeps.o \ - $(CRT) \ - $(APE_NO_MODIFY_SELF) - @$(APELINK) - -o/$(MODE)/tool/build/compile.com.dbg: \ - $(TOOL_BUILD_DEPS) \ - o/$(MODE)/tool/build/build.pkg \ - o/$(MODE)/tool/build/compile.o \ - $(CRT) \ - $(APE_NO_MODIFY_SELF) - @$(APELINK) - -o/$(MODE)/tool/build/zipobj.com.dbg: \ - $(TOOL_BUILD_DEPS) \ - o/$(MODE)/tool/build/build.pkg \ - o/$(MODE)/tool/build/zipobj.o \ - $(CRT) \ - $(APE_NO_MODIFY_SELF) - @$(APELINK) - o/$(MODE)/tool/build/emulator.o: \ OVERRIDE_COPTS += \ -fno-sanitize=pointer-overflow +o/$(MODE)/tool/build/mkdir.zip.o: o/$(MODE)/tool/build/mkdir + @$(COMPILE) -AZIPOBJ $(ZIPOBJ) $(ZIPOBJ_FLAGS) -0 -B -Pbin $(OUTPUT_OPTION) $< +o/$(MODE)/tool/build/chmod.zip.o: o/$(MODE)/tool/build/chmod + @$(COMPILE) -AZIPOBJ $(ZIPOBJ) $(ZIPOBJ_FLAGS) -0 -B -Pbin $(OUTPUT_OPTION) $< +o/$(MODE)/tool/build/cp.zip.o: o/$(MODE)/tool/build/cp + @$(COMPILE) -AZIPOBJ $(ZIPOBJ) $(ZIPOBJ_FLAGS) -0 -B -Pbin $(OUTPUT_OPTION) $< +o/$(MODE)/tool/build/mv.zip.o: o/$(MODE)/tool/build/mv + @$(COMPILE) -AZIPOBJ $(ZIPOBJ) $(ZIPOBJ_FLAGS) -0 -B -Pbin $(OUTPUT_OPTION) $< +o/$(MODE)/tool/build/echo.zip.o: o/$(MODE)/tool/build/echo + @$(COMPILE) -AZIPOBJ $(ZIPOBJ) $(ZIPOBJ_FLAGS) -0 -B -Pbin $(OUTPUT_OPTION) $< +o/$(MODE)/tool/build/gzip.zip.o: o/$(MODE)/tool/build/gzip + @$(COMPILE) -AZIPOBJ $(ZIPOBJ) $(ZIPOBJ_FLAGS) -0 -B -Pbin $(OUTPUT_OPTION) $< +o/$(MODE)/tool/build/printf.zip.o: o/$(MODE)/tool/build/printf + @$(COMPILE) -AZIPOBJ $(ZIPOBJ) $(ZIPOBJ_FLAGS) -0 -B -Pbin $(OUTPUT_OPTION) $< +o/$(MODE)/tool/build/dd.zip.o: o/$(MODE)/tool/build/dd + @$(COMPILE) -AZIPOBJ $(ZIPOBJ) $(ZIPOBJ_FLAGS) -0 -B -Pbin $(OUTPUT_OPTION) $< + .PHONY: o/$(MODE)/tool/build o/$(MODE)/tool/build: \ o/$(MODE)/tool/build/emucrt \ diff --git a/tool/build/chmod.c b/tool/build/chmod.c new file mode 100644 index 000000000..04e09343a --- /dev/null +++ b/tool/build/chmod.c @@ -0,0 +1,120 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/calls.h" +#include "libc/calls/struct/dirent.h" +#include "libc/errno.h" +#include "libc/fmt/conv.h" +#include "libc/runtime/runtime.h" +#include "libc/stdio/stdio.h" +#include "libc/str/str.h" +#include "libc/sysv/consts/ex.h" +#include "libc/sysv/consts/exit.h" +#include "third_party/getopt/getopt.h" + +#define USAGE \ + " OCTAL DST...\n\ +\n\ +SYNOPSIS\n\ +\n\ + Changes File Mode Bits\n\ +\n\ +FLAGS\n\ +\n\ + -?\n\ + -h help\n\ +\n" + +const char *prog; + +wontreturn void PrintUsage(int rc, FILE *f) { + fputs("usage: ", f); + fputs(prog, f); + fputs(USAGE, f); + exit(rc); +} + +void GetOpts(int argc, char *argv[]) { + int opt; + while ((opt = getopt(argc, argv, "?h")) != -1) { + switch (opt) { + case 'h': + case '?': + PrintUsage(EXIT_SUCCESS, stdout); + default: + PrintUsage(EX_USAGE, stderr); + } + } +} + +int main(int argc, char *argv[]) { + int i, mode; + char buf[PATH_MAX]; + + { + printf("curdir %s\n", getcwd(buf, sizeof(buf))); + printf("tmp:"); + struct dirent *e; + DIR *d; + if ((d = opendir("tmp"))) { + while ((e = readdir(d))) { + printf(" %s", e->d_name); + } + closedir(d); + } else { + printf(" dir not found"); + } + printf("\n"); + } + + { + printf("curdir %s\n", getcwd(buf, sizeof(buf))); + printf("bin:"); + struct dirent *e; + DIR *d; + if ((d = opendir("bin"))) { + while ((e = readdir(d))) { + printf(" %s", e->d_name); + } + closedir(d); + } else { + printf(" dir not found"); + } + printf("\n"); + } + + prog = argc > 0 ? argv[0] : "mv.com"; + GetOpts(argc, argv); + if (argc - optind < 2) { + PrintUsage(EX_USAGE, stderr); + } + mode = strtol(argv[optind], 0, 8) & 07777; + for (i = optind + 1; i < argc; ++i) { + if (chmod(argv[i], mode) == -1) { + const char *s = strerdoc(errno); + fputs(prog, stderr); + fputs(": ", stderr); + fputs(argv[i], stderr); + fputs(": ", stderr); + fputs(s, stderr); + fputs("\n", stderr); + exit(1); + } + } + return 0; +} diff --git a/tool/build/dd.c b/tool/build/dd.c new file mode 100644 index 000000000..da1f0a608 --- /dev/null +++ b/tool/build/dd.c @@ -0,0 +1,160 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/bits/safemacros.internal.h" +#include "libc/calls/calls.h" +#include "libc/errno.h" +#include "libc/fmt/conv.h" +#include "libc/limits.h" +#include "libc/runtime/runtime.h" +#include "libc/stdio/stdio.h" +#include "libc/str/str.h" +#include "libc/sysv/consts/o.h" + +char buf[65536]; + +wontreturn void SysFail(const char *func, const char *file) { + int e = errno; + fputs("dd: ", stderr); + fputs(func, stderr); + fputs(" failed: ", stderr); + fputs(file, stderr); + fputs(": ", stderr); + fputs(nulltoempty(strerdoc(e)), stderr); + fputs("\n", stderr); + exit(__COUNTER__ + 1); +} + +int main(int argc, char *argv[]) { + long i; + char *p; + long skip = 0; + long count = LONG_MAX; + long blocksize = 1; + int oflags = O_WRONLY | O_TRUNC | O_CREAT; + const char *infile = "/dev/stdin"; + const char *oufile = "/dev/stdout"; + + for (i = 1; i < argc; ++i) { + + if (argv[i][0] == 'b' && // + argv[i][1] == 's' && // + argv[i][2] == '=') { + blocksize = strtol(argv[i] + 3 + (argv[i][3] == '"'), 0, 10); + if (!(0 < blocksize && blocksize <= sizeof(buf))) { + fputs("dd: bad block size\n", stderr); + return __COUNTER__ + 1; + } + + } else if (argv[i][0] == 'i' && // + argv[i][1] == 'f' && // + argv[i][2] == '=') { + infile = argv[i] + 3 + (argv[i][3] == '"'); + p = strchr(infile, '"'); + if (p) *p = 0; + + } else if (argv[i][0] == 'o' && // + argv[i][1] == 'f' && // + argv[i][2] == '=') { + oufile = argv[i] + 3 + (argv[i][3] == '"'); + p = strchr(infile, '"'); + if (p) *p = 0; + + } else if (argv[i][0] == 's' && // + argv[i][1] == 'k' && // + argv[i][2] == 'i' && // + argv[i][3] == 'p' && // + argv[i][4] == '=') { + count = strtol(argv[i] + 5 + (argv[i][5] == '"'), 0, 10); + if (!(skip < 0)) { + fputs("dd: bad skip\n", stderr); + return __COUNTER__ + 1; + } + + } else if (argv[i][0] == 'c' && // + argv[i][1] == 'o' && // + argv[i][2] == 'u' && // + argv[i][3] == 'n' && // + argv[i][4] == 't' && // + argv[i][5] == '=') { + count = strtol(argv[i] + 6 + (argv[i][6] == '"'), 0, 10); + if (!(count < 0)) { + fputs("dd: bad count\n", stderr); + return __COUNTER__ + 1; + } + + } else if (!strcmp(argv[i], "conv=notrunc")) { + oflags &= ~O_TRUNC; + + } else { + fputs("dd: unrecognized arg: ", stderr); + fputs(argv[i], stderr); + fputs("\n", stderr); + return __COUNTER__ + 1; + } + } + + ssize_t rc; + int fdin, fdout; + + if ((fdin = open(infile, O_RDONLY)) == -1) { + SysFail("open", infile); + } + + if ((fdout = open(oufile, oflags, 0644)) == -1) { + SysFail("open", oufile); + } + + if (skip) { + if (lseek(fdin, skip, SEEK_SET) == -1) { + SysFail("lseek", infile); + } + } + + for (i = 0; i < count; ++i) { + + rc = read(fdin, buf, blocksize); + if (rc == -1) { + SysFail("read", infile); + } + if (rc != blocksize) { + int e = errno; + fputs("dd: failed to read blocksize: ", stderr); + fputs(infile, stderr); + fputs("\n", stderr); + return __COUNTER__ + 1; + } + + rc = write(fdout, buf, blocksize); + if (rc == -1) { + SysFail("write", oufile); + } + if (rc != blocksize) { + int e = errno; + fputs("dd: failed to write blocksize: ", stderr); + fputs(infile, stderr); + fputs("\n", stderr); + return __COUNTER__ + 1; + } + } + + if (close(fdin) == -1) SysFail("close", infile); + if (close(fdout) == -1) SysFail("close", oufile); + + return 0; +} diff --git a/tool/build/mv.c b/tool/build/mv.c new file mode 100644 index 000000000..e7a7e02d6 --- /dev/null +++ b/tool/build/mv.c @@ -0,0 +1,222 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/calls.h" +#include "libc/calls/struct/stat.h" +#include "libc/errno.h" +#include "libc/fmt/conv.h" +#include "libc/fmt/fmt.h" +#include "libc/intrin/kprintf.h" +#include "libc/runtime/gc.h" +#include "libc/runtime/runtime.h" +#include "libc/stdio/stdio.h" +#include "libc/str/str.h" +#include "libc/sysv/consts/at.h" +#include "libc/sysv/consts/ex.h" +#include "libc/sysv/consts/exit.h" +#include "libc/sysv/consts/ok.h" +#include "libc/sysv/consts/s.h" +#include "libc/x/x.h" +#include "third_party/getopt/getopt.h" +#include "third_party/musl/ftw.h" + +#define USAGE \ + " SRC... DST\n\ +\n\ +SYNOPSIS\n\ +\n\ + Moves Files\n\ +\n\ +FLAGS\n\ +\n\ + -?\n\ + -h help\n\ + -f force\n\ + -r recursive\n\ +\n" + +bool force; +int striplen; +bool recursive; +const char *prog; +char mkbuf[PATH_MAX]; +char srcdir[PATH_MAX]; +char dstdir[PATH_MAX]; +char srcfile[PATH_MAX]; +char dstfile[PATH_MAX]; +char linkbuf[PATH_MAX]; + +void Mv(char *, char *); + +bool IsDirectory(const char *path) { + int e; + bool res; + struct stat st; + e = errno; + res = stat(path, &st) != -1 && S_ISDIR(st.st_mode); + errno = e; + return res; +} + +bool IsSymlink(const char *path) { + int e; + bool res; + struct stat st; + e = errno; + res = fstatat(AT_FDCWD, path, &st, AT_SYMLINK_NOFOLLOW) != -1 && + S_ISLNK(st.st_mode); + errno = e; + return res; +} + +wontreturn void PrintUsage(int rc, FILE *f) { + fputs("usage: ", f); + fputs(prog, f); + fputs(USAGE, f); + exit(rc); +} + +void GetOpts(int argc, char *argv[]) { + int opt; + while ((opt = getopt(argc, argv, "?hfrR")) != -1) { + switch (opt) { + case 'f': + force = true; + break; + case 'r': + case 'R': + recursive = true; + break; + case 'h': + case '?': + PrintUsage(EXIT_SUCCESS, stdout); + default: + PrintUsage(EX_USAGE, stderr); + } + } +} + +int Visit(const char *fpath, const struct stat *sb, int tflag, + struct FTW *ftwbuf) { + char *src; + strcpy(srcfile, fpath); + src = srcfile + striplen; + strcpy(dstfile, dstdir); + if (!endswith(dstfile, "/")) { + strcat(dstfile, "/"); + } + strcat(dstfile, src); + strcpy(srcfile, fpath); + switch (tflag) { + case FTW_D: + return 0; + case FTW_F: + case FTW_SL: + case FTW_SLN: + Mv(srcfile, dstfile); + return 0; + default: + fputs(fpath, stderr); + fputs(": can't handle file type\n", stderr); + exit(1); + } +} + +char *Join(const char *a, const char *b) { + size_t n, m; + n = strlen(a); + m = strlen(b); + if (n + 1 + m + 1 > sizeof(dstfile)) { + fputs("error: mv: path too long\n", stderr); + exit(1); + } + stpcpy(stpcpy(stpcpy(dstfile, a), "/"), b); + return dstfile; +} + +void Mv(char *src, char *dst) { + ssize_t rc; + const char *s; + if (strlen(src) + 1 > PATH_MAX) _Exit(2); + if (strlen(dst) + 1 > PATH_MAX) _Exit(2); + basename(src); + basename(dst); + if (IsDirectory(src)) { + if (!recursive) { + fputs(prog, stderr); + fputs(": won't move directory without -r flag.\n", stderr); + exit(1); + } + strcpy(dstdir, dst); + if (IsDirectory(dst)) { + strcpy(srcdir, src); + basename(srcdir); + striplen = 0; + strcpy(srcdir, basename(src)); + } else { + strcpy(srcdir, src); + basename(srcdir); + striplen = strlen(srcdir); + strcpy(srcdir, ""); + } + if (nftw(src, Visit, 20, 0) == -1) { + fputs(prog, stderr); + fputs(": nftw failed: ", stderr); + fputs(strerdoc(errno), stderr); + fputs("\n", stderr); + exit(1); + } + return; + } + if (IsDirectory(dst)) { + dst = Join(dst, basename(src)); + } + if (!force && access(dst, W_OK) == -1 && errno != ENOENT) goto OnFail; + strcpy(mkbuf, dst); + if (makedirs(dirname(mkbuf), 0755) == -1) goto OnFail; + if (IsSymlink(src)) { + if ((rc = readlink(src, linkbuf, sizeof(linkbuf) - 1)) == -1) goto OnFail; + linkbuf[rc] = 0; + if (symlink(linkbuf, dst) == -1) goto OnFail; + } else { + if (rename(src, dst) == -1) goto OnFail; + } + return; +OnFail: + s = strerdoc(errno); + fputs(prog, stderr); + fputs(": ", stderr); + fputs(src, stderr); + fputs(" ", stderr); + fputs(dst, stderr); + fputs(": ", stderr); + fputs(s, stderr); + fputs("\n", stderr); + exit(1); +} + +int main(int argc, char *argv[]) { + int i; + prog = argc > 0 ? argv[0] : "mv.com"; + GetOpts(argc, argv); + if (argc - optind < 2) PrintUsage(EX_USAGE, stderr); + for (i = optind; i < argc - 1; ++i) { + Mv(argv[i], argv[argc - 1]); + } + return 0; +} diff --git a/test/libc/stdio/system_test.c b/tool/build/ocat.c similarity index 52% rename from test/libc/stdio/system_test.c rename to tool/build/ocat.c index 93acaeae5..068362c13 100644 --- a/test/libc/stdio/system_test.c +++ b/tool/build/ocat.c @@ -1,7 +1,7 @@ /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ @@ -17,16 +17,63 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/stdio/stdio.h" -#include "libc/testlib/testlib.h" +#include "libc/errno.h" +#include "libc/fmt/itoa.h" +#include "libc/mem/io.h" +#include "libc/runtime/runtime.h" +#include "libc/str/str.h" +#include "libc/sysv/consts/ex.h" +#include "libc/sysv/consts/o.h" +#include "third_party/getopt/getopt.h" -TEST(system, nullParam_testsIfSystemHasShell) { - ASSERT_EQ(true, system(NULL)); +char buf[512]; + +static void Write(const char *s, ...) { + va_list va; + va_start(va, s); + do { + write(2, s, strlen(s)); + } while ((s = va_arg(va, const char *))); + va_end(va); } -TEST(system, test) { - int rc; - rc = system("exit 42"); - ASSERT_NE(-1, rc); - ASSERT_EQ(42, WEXITSTATUS(rc)); +wontreturn void SysExit(int rc, const char *call, const char *thing) { + int err; + char ibuf[12]; + const char *estr; + err = errno; + FormatInt32(ibuf, err); + estr = strerdoc(err); + if (!estr) estr = "EUNKNOWN"; + Write(thing, ": ", call, "() failed: ", estr, " (", ibuf, ")\n", 0); + exit(rc); +} + +int main(int argc, char *argv[]) { + int i, opt; + const char *outpath = "/dev/stdout"; + while ((opt = getopt(argc, argv, "o:")) != -1) { + switch (opt) { + case 'o': + outpath = optarg; + break; + default: + return 1; + } + } + int out = open(outpath, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (out == -1) SysExit(2, "open", outpath); + for (i = optind; i < argc; ++i) { + int in = open(argv[i], O_RDONLY); + if (in == -1) SysExit(3, "open", argv[i]); + for (;;) { + ssize_t rc = read(in, buf, 512); + if (rc == -1) SysExit(3, "read", argv[i]); + if (!rc) break; + ssize_t rc2 = write(out, buf, rc); + if (rc2 != rc) SysExit(4, "write", outpath); + } + if (close(in) == -1) SysExit(5, "close", argv[i]); + } + if (close(out) == -1) SysExit(6, "close", outpath); } diff --git a/tool/build/pledge.c b/tool/build/pledge.c index 45287c3e3..af855f904 100644 --- a/tool/build/pledge.c +++ b/tool/build/pledge.c @@ -445,7 +445,7 @@ void ApplyFilesystemPolicy(unsigned long ipromises) { } if (~ipromises & (1ul << PROMISE_TTY)) { - UnveilIfExists(ttyname(0), "rw"); // 1-up apparmor + UnveilIfExists(ttyname(0), "rw"); UnveilIfExists("/etc/tty", "rw"); UnveilIfExists("/etc/console", "rw"); UnveilIfExists("/usr/share/terminfo", "r"); diff --git a/tool/build/printf.c b/tool/build/printf.c new file mode 100644 index 000000000..bc3293b52 --- /dev/null +++ b/tool/build/printf.c @@ -0,0 +1,128 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/kprintf.h" +#include "libc/stdio/stdio.h" +#include "libc/str/str.h" + +static bool isoctal(char c) { + return '0' <= c && c <= '7'; +} + +char *U(char *p) { + int c, i = 0, j = 0; + for (;;) { + switch ((c = p[i++] & 255)) { + case '\\': + switch ((c = p[i++] & 255)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + if (isoctal(p[i])) { + if (isoctal(p[i + 1])) { + p[j++] = (c - '0') << 6 | (p[i] - '0') << 3 | (p[i + 1] - '0'); + i += 2; + continue; + } else { + p[j++] = (c - '0') << 3 | (p[i++] - '0'); + continue; + } + } else { + p[j++] = (c - '0'); + continue; + } + case '\\': + p[j++] = '\\'; + continue; + case 'a': + p[j++] = '\a'; + continue; + case 'b': + p[j++] = '\b'; + continue; + case 't': + p[j++] = '\t'; + continue; + case 'f': + p[j++] = '\f'; + continue; + case 'v': + p[j++] = '\v'; + continue; + case 'e': + p[j++] = '\e'; + continue; + case 'r': + p[j++] = '\r'; + continue; + case 'n': + p[j++] = '\n'; + continue; + case '"': + p[j++] = '"'; + continue; + case '\'': + p[j++] = '\''; + continue; + } + // fallthrough + default: + p[j++] = c; + break; + case '\0': + p[j] = 0; + return p; + } + } +} + +int main(int argc, char *argv[]) { + switch (argc) { + case 2: + printf(U(argv[1])); + return 0; + case 3: + printf(U(argv[1]), argv[2]); + return 0; + case 4: + printf(U(argv[1]), argv[2], argv[3]); + return 0; + case 5: + printf(U(argv[1]), argv[2], argv[3], argv[4]); + return 0; + case 6: + printf(U(argv[1]), argv[2], argv[3], argv[4], argv[5]); + return 0; + case 7: + printf(U(argv[1]), argv[2], argv[3], argv[4], argv[5], argv[6]); + return 0; + case 8: + printf(U(argv[1]), argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]); + return 0; + default: + if (argc > 0) { + fprintf(stderr, "%s: %s format [arguments]\n", argv[0], argv[0]); + } + return 1; + } +} diff --git a/tool/net/net.mk b/tool/net/net.mk index 3c8af7115..8bf5448bd 100644 --- a/tool/net/net.mk +++ b/tool/net/net.mk @@ -308,9 +308,6 @@ o/$(MODE)/tool/net/redbean-static.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) -o/$(MODE)/tool/net/redbean-static.o: tool/net/redbean.c o/$(MODE)/tool/net/redbean.o - @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -DSTATIC -DREDBEAN=\"redbean-static\" $(OUTPUT_OPTION) $< - # REDBEAN-UNSECURE.COM # # Passing the -DUNSECURE will cause the TLS security code to be removed. @@ -350,9 +347,6 @@ o/$(MODE)/tool/net/redbean-unsecure.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) -o/$(MODE)/tool/net/redbean-unsecure.o: tool/net/redbean.c o/$(MODE)/tool/net/redbean.o - @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -DUNSECURE -DREDBEAN=\"redbean-unsecure\" $(OUTPUT_OPTION) $< - # REDBEAN-ORIGINAL.COM # # Passing the -DSTATIC and -DUNSECURE flags together w/ MODE=tiny will @@ -414,12 +408,6 @@ o/$(MODE)/tool/net/redbean-original.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) -o/$(MODE)/tool/net/redbean-original.o: tool/net/redbean.c o/$(MODE)/tool/net/redbean.o - @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -DSTATIC -DUNSECURE -DREDBEAN=\"redbean-original\" $(OUTPUT_OPTION) $< - -o/$(MODE)/tool/net/redbean-original.s: tool/net/redbean.c o/$(MODE)/tool/net/redbean.o - @$(COMPILE) -AOBJECTIFY.c $(COMPILE.c) -DSTATIC -DUNSECURE -DREDBEAN=\"redbean-original\" $(OUTPUT_OPTION) $< - .PHONY: o/$(MODE)/tool/net o/$(MODE)/tool/net: \ $(TOOL_NET_BINS) \ diff --git a/tool/net/redbean-original.c b/tool/net/redbean-original.c new file mode 100644 index 000000000..d2d3fd2db --- /dev/null +++ b/tool/net/redbean-original.c @@ -0,0 +1,4 @@ +#define STATIC +#define UNSECURE +#define REDBEAN "redbean-original" +#include "tool/net/redbean.c" diff --git a/tool/net/redbean-static.c b/tool/net/redbean-static.c new file mode 100644 index 000000000..7fd491bc2 --- /dev/null +++ b/tool/net/redbean-static.c @@ -0,0 +1,3 @@ +#define STATIC +#define REDBEAN "redbean-static" +#include "tool/net/redbean.c" diff --git a/tool/net/redbean-unsecure.c b/tool/net/redbean-unsecure.c new file mode 100644 index 000000000..e2b2edc9f --- /dev/null +++ b/tool/net/redbean-unsecure.c @@ -0,0 +1,3 @@ +#define UNSECURE +#define REDBEAN "redbean-unsecure" +#include "tool/net/redbean.c"