diff --git a/build/bootstrap/make.com b/build/bootstrap/make.com index 77a9b16cb..ce4a3b23e 100755 Binary files a/build/bootstrap/make.com and b/build/bootstrap/make.com differ diff --git a/build/definitions.mk b/build/definitions.mk index 2fbd3fabd..7cd79c24d 100644 --- a/build/definitions.mk +++ b/build/definitions.mk @@ -65,7 +65,6 @@ ZIPOBJ = build/bootstrap/zipobj.com FIXUPOBJ = build/bootstrap/fixupobj.com MKDIR = build/bootstrap/mkdir.com -p COMPILE = build/bootstrap/compile.com -V9 -P4096 $(QUOTA) -SYMTAB = $(TMPDIR)/$(subst /,_,$@).symtab COMMA := , PWD := $(shell build/bootstrap/pwd.com) @@ -108,6 +107,12 @@ export MODE export SOURCE_DATE_EPOCH export TMPDIR +ifeq ($(LANDLOCKMAKE_VERSION),) +TMPSAFE = $(TMPDIR)/$(subst /,_,$@) +else +TMPSAFE = $(TMPDIR)/ +endif + FTRACE = \ -pg diff --git a/build/rules.mk b/build/rules.mk index fb8d8a5cc..62718a2fe 100644 --- a/build/rules.mk +++ b/build/rules.mk @@ -75,12 +75,12 @@ o/%.a: @$(COMPILE) -AARCHIVE -wT$@ $(AR) $(ARFLAGS) $@ @$(TMPDIR)/$(subst /,_,$@) o/%.pkg: - $(file >$(TMPDIR)/$(subst /,_,$@).args,$(filter %.o,$^)) - @$(COMPILE) -APACKAGE -wT$@ $(PKG) $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) @$(TMPDIR)/$(subst /,_,$@) + $(file >$(TMPSAFE).args,$(filter %.o,$^)) + @$(COMPILE) -APACKAGE -wT$@ $(PKG) $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) @$(TMPSAFE).args o/$(MODE)/%.pkg: - $(file >$(TMPDIR)/$(subst /,_,$@),$(filter %.o,$^)) - @$(COMPILE) -APACKAGE -wT$@ $(PKG) $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) @$(TMPDIR)/$(subst /,_,$@) + $(file >$(TMPSAFE).args,$(filter %.o,$^)) + @$(COMPILE) -APACKAGE -wT$@ $(PKG) $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) @$(TMPSAFE).args o/$(MODE)/%.o: %.py o/$(MODE)/third_party/python/pyobj.com @$(COMPILE) -wAPYOBJ o/$(MODE)/third_party/python/pyobj.com $(PYFLAGS) -o $@ $< @@ -148,3 +148,24 @@ o/%.okk: % o/$(MODE)/%.okk: .UNSANDBOXED = 1 o/$(MODE)/%.okk: % @$(COMPILE) -ACHECK.h $(COMPILE.cxx) -xc++ -g0 -o $@ $< + +################################################################################ +# executable helpers + +MAKE_OBJCOPY = \ + $(COMPILE) -AOBJCOPY -T$@ \ + $(OBJCOPY) -S -O binary $< $@ + +MAKE_SYMTAB_CREATE = \ + $(COMPILE) -wASYMTAB \ + o/$(MODE)/tool/build/symtab.com \ + -o $(TMPSAFE)/.symtab \ + $< + +MAKE_SYMTAB_ZIP = \ + $(COMPILE) -AZIP -T$@ \ + o/$(MODE)/third_party/zip/zip.com \ + -b$(TMPDIR) \ + -9qj \ + $@ \ + $(TMPSAFE)/.symtab diff --git a/libc/calls/lseek.c b/libc/calls/lseek.c index e0c31cd8e..0fb3f92b9 100644 --- a/libc/calls/lseek.c +++ b/libc/calls/lseek.c @@ -22,6 +22,7 @@ #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" +#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/weaken.h" #include "libc/log/backtrace.internal.h" #include "libc/zipos/zipos.internal.h" @@ -47,6 +48,7 @@ int64_t lseek(int fd, int64_t offset, unsigned whence) { } else { rc = sys_lseek_nt(fd, offset, whence); } - STRACE("lseek(%d, %'ld, %d) → %'ld% m", fd, offset, whence, rc); + STRACE("lseek(%d, %'ld, %s) → %'ld% m", fd, offset, DescribeWhence(whence), + rc); return rc; } diff --git a/libc/intrin/describeflags.internal.h b/libc/intrin/describeflags.internal.h index aca06fb44..2cd1b6312 100644 --- a/libc/intrin/describeflags.internal.h +++ b/libc/intrin/describeflags.internal.h @@ -51,14 +51,15 @@ const char *DescribeSockOptname(char[32], int, int); const char *DescribeSocketFamily(char[12], int); const char *DescribeSocketProtocol(char[12], int); const char *DescribeSocketType(char[64], int); +const char *DescribeWhence(char[12], int); #define DescribeCapability(x) DescribeCapability(alloca(20), x) #define DescribeClockName(x) DescribeClockName(alloca(32), x) -#define DescribeDirfd(dirfd) DescribeDirfd(alloca(12), dirfd) +#define DescribeDirfd(x) DescribeDirfd(alloca(12), x) #define DescribeFrame(x) DescribeFrame(alloca(32), x) #define DescribeFutexResult(x) DescribeFutexResult(alloca(12), x) #define DescribeHow(x) DescribeHow(alloca(12), x) -#define DescribeMapFlags(dirfd) DescribeMapFlags(alloca(64), dirfd) +#define DescribeMapFlags(x) DescribeMapFlags(alloca(64), x) #define DescribeMapping(x, y) DescribeMapping(alloca(8), x, y) #define DescribeNtConsoleInFlags(x) DescribeNtConsoleInFlags(alloca(256), x) #define DescribeNtConsoleOutFlags(x) DescribeNtConsoleOutFlags(alloca(128), x) @@ -77,10 +78,10 @@ const char *DescribeSocketType(char[64], int); #define DescribeOpenFlags(x) DescribeOpenFlags(alloca(128), x) #define DescribePersonalityFlags(p) DescribePersonalityFlags(alloca(128), p) #define DescribePollFlags(p) DescribePollFlags(alloca(64), p) -#define DescribeProtFlags(dirfd) DescribeProtFlags(alloca(48), dirfd) +#define DescribeProtFlags(x) DescribeProtFlags(alloca(48), x) #define DescribePtrace(i) DescribePtrace(alloca(12), i) #define DescribePtraceEvent(x) DescribePtraceEvent(alloca(32), x) -#define DescribeRemapFlags(dirfd) DescribeRemapFlags(alloca(48), dirfd) +#define DescribeRemapFlags(x) DescribeRemapFlags(alloca(48), x) #define DescribeRlimitName(rl) DescribeRlimitName(alloca(20), rl) #define DescribeSchedPolicy(x) DescribeSchedPolicy(alloca(48), x) #define DescribeSockLevel(x) DescribeSockLevel(alloca(12), x) @@ -88,6 +89,7 @@ const char *DescribeSocketType(char[64], int); #define DescribeSocketFamily(x) DescribeSocketFamily(alloca(12), x) #define DescribeSocketProtocol(x) DescribeSocketProtocol(alloca(12), x) #define DescribeSocketType(x) DescribeSocketType(alloca(64), x) +#define DescribeWhence(x) DescribeWhence(alloca(12), x) COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/intrin/describewhence.c b/libc/intrin/describewhence.c new file mode 100644 index 000000000..2b105a622 --- /dev/null +++ b/libc/intrin/describewhence.c @@ -0,0 +1,29 @@ +/*-*- 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/fmt/itoa.h" +#include "libc/intrin/describeflags.internal.h" + +const char *(DescribeWhence)(char buf[12], int whence) { + if (whence == SEEK_SET) return "SEEK_SET"; + if (whence == SEEK_CUR) return "SEEK_CUR"; + if (whence == SEEK_END) return "SEEK_END"; + FormatInt32(buf, whence); + return buf; +} diff --git a/libc/stdio/fopen.c b/libc/stdio/fopen.c index 84dcde81e..2319d8adb 100644 --- a/libc/stdio/fopen.c +++ b/libc/stdio/fopen.c @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/strace.internal.h" #include "libc/mem/mem.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" @@ -68,6 +67,5 @@ FILE *fopen(const char *pathname, const char *mode) { close(fd); } } - STRACE("fopen(%#s, %#s) → %p% m", pathname, mode, f); return f; } diff --git a/test/libc/stdio/fseeko_test.c b/test/libc/stdio/fseeko_test.c new file mode 100644 index 000000000..af2dad344 --- /dev/null +++ b/test/libc/stdio/fseeko_test.c @@ -0,0 +1,37 @@ +/*-*- 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/stdio/stdio.h" +#include "libc/testlib/testlib.h" +#include "libc/x/x.h" + +char testlib_enable_tmp_setup_teardown; + +TEST(fseeko, test) { + FILE *f; + EXPECT_SYS(0, 0, xbarf("foo", "hello!", 6)); + EXPECT_NE(NULL, (f = fopen("foo", "r"))); + EXPECT_EQ(0, fseeko(f, -3, SEEK_END)); + EXPECT_EQ('l', fgetc(f)); + EXPECT_EQ('o', fgetc(f)); + EXPECT_EQ(0, fseeko(f, 3, SEEK_SET)); + EXPECT_EQ('l', fgetc(f)); + EXPECT_EQ('o', fgetc(f)); + EXPECT_EQ(0, fclose(f)); +} diff --git a/third_party/chibicc/chibicc.mk b/third_party/chibicc/chibicc.mk index f0eee938e..e38ab6a7c 100644 --- a/third_party/chibicc/chibicc.mk +++ b/third_party/chibicc/chibicc.mk @@ -83,6 +83,14 @@ o/$(MODE)/third_party/chibicc/chibicc.com.dbg: \ $(THIRD_PARTY_CHIBICC_A).pkg @$(APELINK) +o/$(MODE)/third_party/chibicc/chibicc.com: \ + o/$(MODE)/third_party/chibicc/chibicc.com.dbg \ + o/$(MODE)/third_party/zip/zip.com \ + o/$(MODE)/tool/build/symtab.com + @$(MAKE_OBJCOPY) + @$(MAKE_SYMTAB_CREATE) + @$(MAKE_SYMTAB_ZIP) + o/$(MODE)/third_party/chibicc/as.com.dbg: \ $(THIRD_PARTY_CHIBICC_A_DEPS) \ $(THIRD_PARTY_CHIBICC_A) \ diff --git a/third_party/lua/lua.mk b/third_party/lua/lua.mk index c66574ca7..be049d27b 100644 --- a/third_party/lua/lua.mk +++ b/third_party/lua/lua.mk @@ -248,6 +248,14 @@ o/$(MODE)/third_party/lua/lua.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) +o/$(MODE)/third_party/lua/lua.com: \ + o/$(MODE)/third_party/lua/lua.com.dbg \ + o/$(MODE)/third_party/zip/zip.com \ + o/$(MODE)/tool/build/symtab.com + @$(MAKE_OBJCOPY) + @$(MAKE_SYMTAB_CREATE) + @$(MAKE_SYMTAB_ZIP) + ################################################################################ # luac.com diff --git a/third_party/make/config.h b/third_party/make/config.h index 6aa94f409..31e0fc8fe 100644 --- a/third_party/make/config.h +++ b/third_party/make/config.h @@ -2,6 +2,8 @@ /* src/config.h.in. Generated from configure.ac by autoheader. */ #include "libc/calls/calls.h" +#define LANDLOCKMAKE_VERSION "1.4" + /* Define to the number of bits in type 'ptrdiff_t'. */ #define BITSIZEOF_PTRDIFF_T 64 diff --git a/third_party/make/main.c b/third_party/make/main.c index 114d95ca8..d4076199c 100644 --- a/third_party/make/main.c +++ b/third_party/make/main.c @@ -2975,7 +2975,8 @@ print_version (void) /* Do it only once. */ return; - printf ("%sLandlock Make 1.3 (GNU Make %s)\n", precede, version_string); + printf ("%sLandlock Make " LANDLOCKMAKE_VERSION " (GNU Make %s)\n", + precede, version_string); if (!remote_description || *remote_description == '\0') printf (_("%sBuilt for %s\n"), precede, make_host); diff --git a/third_party/make/make.mk b/third_party/make/make.mk index 7a9d1240a..b55643892 100644 --- a/third_party/make/make.mk +++ b/third_party/make/make.mk @@ -150,6 +150,14 @@ o/$(MODE)/third_party/make/make.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) +o/$(MODE)/third_party/make/make.com: \ + o/$(MODE)/third_party/make/make.com.dbg \ + o/$(MODE)/third_party/zip/zip.com \ + o/$(MODE)/tool/build/symtab.com + @$(MAKE_OBJCOPY) + @$(MAKE_SYMTAB_CREATE) + @$(MAKE_SYMTAB_ZIP) + o/$(MODE)/third_party/make/strcache.o \ o/$(MODE)/third_party/make/expand.o \ o/$(MODE)/third_party/make/read.o: private \ diff --git a/third_party/make/variable.c b/third_party/make/variable.c index 8daba9bd6..7f7582bad 100644 --- a/third_party/make/variable.c +++ b/third_party/make/variable.c @@ -750,6 +750,8 @@ define_automatic_variables (void) ? "" : "-", (remote_description == 0 || remote_description[0] == '\0') ? "" : remote_description); + define_variable_cname ("LANDLOCKMAKE_VERSION", + LANDLOCKMAKE_VERSION, o_default, 0); define_variable_cname ("MAKE_VERSION", buf, o_default, 0); define_variable_cname ("MAKE_HOST", make_host, o_default, 0); @@ -757,11 +759,6 @@ define_automatic_variables (void) isn't one there. */ v = define_variable_cname ("SHELL", default_shell, o_default, 0); - /* On MSDOS we do use SHELL from environment, since it isn't a standard - environment variable on MSDOS, so whoever sets it, does that on purpose. - On OS/2 we do not use SHELL from environment but we have already handled - that problem above. */ -#if !defined(__MSDOS__) && !defined(__EMX__) /* Don't let SHELL come from the environment. */ if (*v->value == '\0' || v->origin == o_env || v->origin == o_env_override) { @@ -769,7 +766,6 @@ define_automatic_variables (void) v->origin = o_file; v->value = xstrdup (default_shell); } -#endif /* Make sure MAKEFILES gets exported if it is set. */ v = define_variable_cname ("MAKEFILES", "", o_default, 0); @@ -777,24 +773,6 @@ define_automatic_variables (void) /* Define the magic D and F variables in terms of the automatic variables they are variations of. */ - -#if defined(__MSDOS__) || defined(WINDOWS32) - /* For consistency, remove the trailing backslash as well as slash. */ - define_variable_cname ("@D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $@)))", - o_automatic, 1); - define_variable_cname ("%D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $%)))", - o_automatic, 1); - define_variable_cname ("*D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $*)))", - o_automatic, 1); - define_variable_cname ("origin != o_env && v->origin != o_env_override) { char *value = recursively_expand_for_file (v, file); -#ifdef WINDOWS32 - if (strcmp (v->name, "Path") == 0 || - strcmp (v->name, "PATH") == 0) - convert_Path_to_windows32 (value, ';'); -#endif *result++ = xstrdup (concat (3, v->name, "=", value)); free (value); } else { -#ifdef WINDOWS32 - if (strcmp (v->name, "Path") == 0 || - strcmp (v->name, "PATH") == 0) - convert_Path_to_windows32 (v->value, ';'); -#endif *result++ = xstrdup (concat (3, v->name, "=", v->value)); } } diff --git a/third_party/mbedtls/test/test.mk b/third_party/mbedtls/test/test.mk index 464f5a55c..13173da5a 100644 --- a/third_party/mbedtls/test/test.mk +++ b/third_party/mbedtls/test/test.mk @@ -131,9 +131,6 @@ o/$(MODE)/third_party/mbedtls/test/%.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) -o/$(MODE)/third_party/mbedtls/test/%.com: o/$(MODE)/third_party/mbedtls/test/%.com.dbg - @$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@ - o/$(MODE)/third_party/mbedtls/test/%.com.runs: o/$(MODE)/third_party/mbedtls/test/%.com @$(COMPILE) -ACHECK -wtT$@ $< $(TESTARGS) diff --git a/third_party/python/python.mk b/third_party/python/python.mk index 910fdfca6..ab6285855 100644 --- a/third_party/python/python.mk +++ b/third_party/python/python.mk @@ -4332,6 +4332,14 @@ o/$(MODE)/third_party/python/python.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) +o/$(MODE)/third_party/python/python.com: \ + o/$(MODE)/third_party/python/python.com.dbg \ + o/$(MODE)/third_party/zip/zip.com \ + o/$(MODE)/tool/build/symtab.com + @$(MAKE_OBJCOPY) + @$(MAKE_SYMTAB_CREATE) + @$(MAKE_SYMTAB_ZIP) + ################################################################################ # FREEZE.COM diff --git a/third_party/quickjs/quickjs.mk b/third_party/quickjs/quickjs.mk index 265f46e04..1391fb8f6 100644 --- a/third_party/quickjs/quickjs.mk +++ b/third_party/quickjs/quickjs.mk @@ -154,6 +154,14 @@ o/$(MODE)/third_party/quickjs/qjs.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) +o/$(MODE)/third_party/quickjs/qjs.com: \ + o/$(MODE)/third_party/quickjs/qjs.com.dbg \ + o/$(MODE)/third_party/zip/zip.com \ + o/$(MODE)/tool/build/symtab.com + @$(MAKE_OBJCOPY) + @$(MAKE_SYMTAB_CREATE) + @$(MAKE_SYMTAB_ZIP) + o/$(MODE)/third_party/quickjs/qjsc.com.dbg: \ $(THIRD_PARTY_QUICKJS) \ o/$(MODE)/third_party/quickjs/qjsc.o \ diff --git a/third_party/sqlite3/sqlite3.mk b/third_party/sqlite3/sqlite3.mk index 8f4fd901b..9b25f8751 100644 --- a/third_party/sqlite3/sqlite3.mk +++ b/third_party/sqlite3/sqlite3.mk @@ -74,6 +74,14 @@ o/$(MODE)/third_party/sqlite3/sqlite3.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) +o/$(MODE)/third_party/sqlite3/sqlite3.com: \ + o/$(MODE)/third_party/sqlite3/sqlite3.com.dbg \ + o/$(MODE)/third_party/zip/zip.com \ + o/$(MODE)/tool/build/symtab.com + @$(MAKE_OBJCOPY) + @$(MAKE_SYMTAB_CREATE) + @$(MAKE_SYMTAB_ZIP) + $(THIRD_PARTY_SQLITE3_A): \ third_party/sqlite3/ \ $(THIRD_PARTY_SQLITE3_A).pkg \ diff --git a/third_party/tidy/tidy.mk b/third_party/tidy/tidy.mk index 97ff350fd..129254562 100644 --- a/third_party/tidy/tidy.mk +++ b/third_party/tidy/tidy.mk @@ -53,6 +53,14 @@ o/$(MODE)/third_party/tidy/tidy.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) +o/$(MODE)/third_party/tidy/tidy.com: \ + o/$(MODE)/third_party/tidy/tidy.com.dbg \ + o/$(MODE)/third_party/zip/zip.com \ + o/$(MODE)/tool/build/symtab.com + @$(MAKE_OBJCOPY) + @$(MAKE_SYMTAB_CREATE) + @$(MAKE_SYMTAB_ZIP) + o/$(MODE)/third_party/tidy/.tidyrc.zip.o: private ZIPOBJ_FLAGS += -B THIRD_PARTY_TIDY_COMS = \ diff --git a/third_party/zip/fileio.c b/third_party/zip/fileio.c index a9e5a0c2b..efd1893c8 100644 --- a/third_party/zip/fileio.c +++ b/third_party/zip/fileio.c @@ -22,10 +22,7 @@ #include "libc/stdio/temp.h" #include "libc/time/time.h" #include "libc/time/struct/tm.h" -#include "libc/fmt/fmt.h" -#include "libc/x/x.h" -#include "libc/x/x.h" -#include "libc/runtime/gc.internal.h" +#include "libc/sysv/consts/s.h" #include "libc/limits.h" #ifdef NO_MKTIME @@ -1178,7 +1175,6 @@ ulg dostime; /* DOS time to convert */ #endif /* ZP_NEED_GEN_D2U_TIME */ -#ifndef MACOS int destroy(f) char *f; /* file to delete */ /* Delete the file *f, returning non-zero on failure. */ @@ -1195,69 +1191,32 @@ char *d, *s; /* destination and source file names */ */ { z_stat t; /* results of stat() */ -#if defined(CMS_MVS) - /* cmsmvs.h defines FOPW_TEMP as memory(hiperspace). Since memory is - * lost at end of run, always do copy instead of rename. - */ - int copy = 1; -#else int copy = 0; -#endif int d_exists; -#if defined(VMS) || defined(CMS_MVS) - /* stat() is broken on VMS remote files (accessed through Decnet). - * This patch allows creation of remote zip files, but is not sufficient - * to update them or compress remote files */ - unlink(d); -#else /* !(VMS || CMS_MVS) */ d_exists = (LSTAT(d, &t) == 0); if (d_exists) { /* * respect existing soft and hard links! */ - if (t.st_nlink > 1 -# ifdef S_IFLNK - || (t.st_mode & S_IFMT) == S_IFLNK -# endif - ) + if (t.st_nlink > 1 || (t.st_mode & S_IFMT) == S_IFLNK) copy = 1; else if (unlink(d)) return ZE_CREAT; /* Can't erase zip file--give up */ } -#endif /* ?(VMS || CMS_MVS) */ -#ifndef CMS_MVS if (!copy) { if (rename(s, d)) { /* Just move s on top of d */ copy = 1; /* failed ? */ -#if !defined(VMS) && !defined(ATARI) && !defined(AZTEC_C) -#if !defined(CMS_MVS) && !defined(RISCOS) && !defined(QDOS) - /* For VMS, ATARI, AMIGA Aztec, VM_CMS, MVS, RISCOS, - always assume that failure is EXDEV */ - if (errno != EXDEV -# ifdef THEOS - && errno != EEXIST -# else -# ifdef ENOTSAM - && errno != ENOTSAM /* Used at least on Turbo C */ -# endif -# endif - ) return ZE_CREAT; -#endif /* !CMS_MVS && !RISCOS */ -#endif /* !VMS && !ATARI && !AZTEC_C */ + if (errno != EXDEV) + return ZE_CREAT; } } -#endif /* !CMS_MVS */ if (copy) { FILE *f, *g; /* source and destination files */ int r; /* temporary variable */ -#ifdef RISCOS - if (SWI_OS_FSControl_26(s,d,0xA1)!=NULL) { -#endif - /* Use zfopen for almost all opens where fopen is used. For most OS that support large files we use the 64-bit file environment and zfopen maps to fopen, but this allows @@ -1280,13 +1239,9 @@ char *d, *s; /* destination and source file names */ return r ? (r == ZE_TEMP ? ZE_WRITE : r) : ZE_WRITE; } unlink(s); -#ifdef RISCOS - } -#endif } return ZE_OK; } -#endif /* !MACOS */ int getfileattr(f) @@ -1326,11 +1281,6 @@ int a; /* attributes returned by getfileattr() */ #ifndef VMS /* VMS-specific function is in VMS.C. */ -static char *EnsureDirs(char *path) { - makedirs(gc(xdirname(path)), 0755); - return path; -} - char *tempname(zip) char *zip; /* path name of zip file to generate temp name for */ @@ -1338,13 +1288,6 @@ char *tempname(zip) { char *t = zip; /* malloc'ed space for name (use zip to avoid warning) */ -#ifdef __COSMOPOLITAN__ - t = malloc(PATH_MAX); - snprintf(t, PATH_MAX, "%szip.XXXXXX", kTmpPath); - mkstemp(EnsureDirs(t)); - return t; -#endif - # ifdef CMS_MVS if ((t = malloc(strlen(tempath) + L_tmpnam + 2)) == NULL) return NULL; diff --git a/third_party/zip/zip.c b/third_party/zip/zip.c index d284e5b36..290b1db86 100644 --- a/third_party/zip/zip.c +++ b/third_party/zip/zip.c @@ -35,17 +35,10 @@ #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "libc/runtime/runtime.h" -#include "libc/runtime/gc.internal.h" -#include "libc/x/x.h" #include "third_party/bzip2/bzlib.h" #define MAXCOM 256 /* Maximum one-line comment size */ -static char *EnsureDirs(char *path) { - makedirs(gc(xdirname(path)), 0755); - return path; -} - /* Local option flags */ #ifndef DELETE #define DELETE 0 @@ -2204,15 +2197,6 @@ char **argv; /* command line tokens */ } #endif -#ifdef RISCOS - set_prefix(); -#endif - -#ifdef __human68k__ - fflush(stderr); - setbuf(stderr, NULL); -#endif - /* Re-initialize global variables to make the zip dll re-entrant. It is * possible that we could get away with not re-initializing all of these * but better safe than sorry. @@ -2591,25 +2575,6 @@ char **argv; /* command line tokens */ { switch (option) { -#ifdef EBCDIC - case 'a': - aflag = ASCII; - printf("Translating to ASCII...\n"); - break; -#endif /* EBCDIC */ -#ifdef CMS_MVS - case 'B': - bflag = 1; - printf("Using binary mode...\n"); - break; -#endif /* CMS_MVS */ -#ifdef TANDEM - case 'B': - nskformatopt(value); - free(value); - break; -#endif - case '0': method = STORE; level = 0; break; case '1': case '2': case '3': case '4': @@ -2645,11 +2610,6 @@ char **argv; /* command line tokens */ } action = DELETE; break; -#ifdef MACOS - case o_df: - MacZip.DataForkOnly = true; - break; -#endif /* MACOS */ case o_db: if (negated) display_bytes = 0; @@ -3835,7 +3795,7 @@ char **argv; /* command line tokens */ } strcat(tempzip, "ziXXXXXX"); - if ((yd = mkstemp(EnsureDirs(gc(xjoinpaths(kTmpPath, tempzip))))) == EOF) { + if ((yd = mkstemp(tempzip)) == EOF) { ZIPERR(ZE_TEMP, tempzip); } if ((y = fdopen(yd, FOPW_TMP)) == NULL) { @@ -4838,7 +4798,7 @@ char **argv; /* command line tokens */ } strcat(tempzip, "ziXXXXXX"); - if ((yd = mkstemp(EnsureDirs(gc(xjoinpaths(kTmpPath, tempzip))))) == EOF) { + if ((yd = mkstemp(tempzip)) == EOF) { ZIPERR(ZE_TEMP, tempzip); } if ((y = fdopen(yd, FOPW_TMP)) == NULL) { diff --git a/third_party/zip/zipfile.c b/third_party/zip/zipfile.c index 97f247a07..9a85e5b1d 100644 --- a/third_party/zip/zipfile.c +++ b/third_party/zip/zipfile.c @@ -17,6 +17,7 @@ #include "third_party/zip/zip.h" #include "third_party/zip/revision.h" #ifdef UNICODE_SUPPORT +#include "libc/stdio/lock.h" #include "third_party/zip/crc32.h" #endif @@ -2957,7 +2958,8 @@ local int find_next_signature(f) /* look for P K ? ? signature */ - m = getc(f); + flockfile(f); + m = getc_unlocked(f); /* here = zftello(f); @@ -2969,20 +2971,20 @@ local int find_next_signature(f) /* found a P */ sigbuf[0] = (char) m; - if ((m = getc(f)) == EOF) + if ((m = getc_unlocked(f)) == EOF) break; if (m != 0x4b /*'K' except EBCDIC*/) { /* not a signature */ - ungetc(m, f); + ungetc_unlocked(m, f); } else { /* found P K */ sigbuf[1] = (char) m; - if ((m = getc(f)) == EOF) + if ((m = getc_unlocked(f)) == EOF) break; if (m == 0x50 /*'P' except EBCDIC*/) { /* not a signature but maybe start of new one */ - ungetc(m, f); + ungetc_unlocked(m, f); continue; } else if (m >= 16) { /* last 2 chars expect < 16 for signature */ @@ -2990,11 +2992,11 @@ local int find_next_signature(f) } sigbuf[2] = (char) m; - if ((m = getc(f)) == EOF) + if ((m = getc_unlocked(f)) == EOF) break; if (m == 0x50 /*'P' except EBCDIC*/) { /* not a signature but maybe start of new one */ - ungetc(m, f); + ungetc_unlocked(m, f); continue; } else if (m >= 16) { /* last 2 chars expect < 16 */ @@ -3003,16 +3005,15 @@ local int find_next_signature(f) sigbuf[3] = (char) m; /* found possible signature */ + funlockfile(f); return 1; } } - m = getc(f); - } - if (ferror(f)) { - return 0; + m = getc_unlocked(f); } /* found nothing */ + funlockfile(f); return 0; } @@ -4069,6 +4070,7 @@ local int scanzipf_regnew() bytes (=65557 bytes) from the end of the file. We back up 128k, to allow some junk being appended to a Zip file. */ + int e = errno; if ((zfseeko(in_file, -0x20000L, SEEK_END) != 0) || /* Some fseek() implementations (e.g. MSC 8.0 16-bit) fail to signal an error when seeking before the beginning of the file. @@ -4076,6 +4078,7 @@ local int scanzipf_regnew() for the error value -1. */ (zftello(in_file) == (zoff_t)-1L)) { + errno = e; /* file is less than 128 KB so back up to beginning */ if (zfseeko(in_file, 0L, SEEK_SET) != 0) { fclose(in_file); @@ -5119,28 +5122,12 @@ int readzipfile() zipfile_exists = 0; /* If zip file exists, read headers and check structure */ -#ifdef VMS - if (zipfile == NULL || !(*zipfile) || !strcmp(zipfile, "-")) - return ZE_OK; - { - int rtype; - - if ((VMSmunch(zipfile, GET_RTYPE, (char *)&rtype) == RMS$_NORMAL) && - (rtype == FAT$C_VARIABLE)) { - fprintf(mesg, - "\n Error: zipfile is in variable-length record format. Please\n\ - run \"bilf b %s\" to convert the zipfile to fixed-length\n\ - record format.\n\n", zipfile); - return ZE_FORM; - } - } - readable = ((f = zfopen(zipfile, FOPR)) != NULL); -#else /* !VMS */ readable = (zipfile != NULL && *zipfile && strcmp(zipfile, "-")); if (readable) { + int e = errno; readable = ((f = zfopen(zipfile, FOPR)) != NULL); + errno = e; } -#endif /* ?VMS */ /* skip check if streaming */ if (!readable) { @@ -5155,63 +5142,9 @@ int readzipfile() zipfile_exists = 1; } -#ifdef MVS - /* Very nasty special case for MVS. Just because the zipfile has been - * opened for reading does not mean that we can actually read the data. - * Typical JCL to create a zipfile is - * - * //ZIPFILE DD DISP=(NEW,CATLG),DSN=prefix.ZIP, - * // SPACE=(CYL,(10,10)) - * - * That creates a VTOC entry with an end of file marker (DS1LSTAR) of zero. - * Alas the VTOC end of file marker is only used when the file is opened in - * append mode. When a file is opened in read mode, the "other" end of file - * marker is used, a zero length data block signals end of file when reading. - * With a brand new file which has not been written to yet, it is undefined - * what you read off the disk. In fact you read whatever data was in the same - * disk tracks before the zipfile was allocated. You would be amazed at the - * number of application programmers who still do not understand this. Makes - * for interesting and semi-random errors, GIGO. - * - * Newer versions of SMS will automatically write a zero length block when a - * file is allocated. However not all sites run SMS or they run older levels - * so we cannot rely on that. The only safe thing to do is close the file, - * open in append mode (we already know that the file exists), close it again, - * reopen in read mode and try to read a data block. Opening and closing in - * append mode will write a zero length block where DS1LSTAR points, making - * sure that the VTOC and internal end of file markers are in sync. Then it - * is safe to read data. If we cannot read one byte of data after all that, - * it is a brand new zipfile and must not be read. - */ - if (readable) - { - char c; - fclose(f); - /* append mode */ - if ((f = zfopen(zipfile, "ab")) == NULL) { - ZIPERR(ZE_OPEN, zipfile); - } - fclose(f); - /* read mode again */ - if ((f = zfopen(zipfile, FOPR)) == NULL) { - ZIPERR(ZE_OPEN, zipfile); - } - if (fread(&c, 1, 1, f) != 1) { - /* no actual data */ - readable = 0; - fclose(f); - } - else{ - fseek(f, 0, SEEK_SET); /* at least one byte in zipfile, back to the start */ - } - } -#endif /* MVS */ - /* ------------------------ */ /* new file read */ - - #ifndef UTIL if (fix == 2) { scanzipf_fixnew(); diff --git a/third_party/zip/zipup.c b/third_party/zip/zipup.c index 095e80c4f..aa87e1381 100644 --- a/third_party/zip/zipup.c +++ b/third_party/zip/zipup.c @@ -537,14 +537,14 @@ struct zlist far *z; /* zip entry to compress */ if (window != NULL) free(window); /* window can't be a mapped file here */ window_size = (ulg)q + MIN_LOOKAHEAD; - remain = window_size & (PAGESIZE-1); + remain = window_size & (FRAMESIZE-1); /* If we can't touch the page beyond the end of file, we must * allocate an extra page. */ if (remain > MIN_LOOKAHEAD) { window = (uch*)mmap(0, window_size, PROT_READ, MAP_PRIVATE, ifile, 0); } else { - window = (uch*)valloc(window_size - remain + PAGESIZE); + window = (uch*)valloc(window_size - remain + FRAMESIZE); if (window != NULL) { window = (uch*)mmap((char*)window, window_size - remain, PROT_READ, MAP_PRIVATE | MAP_FIXED, ifile, 0); diff --git a/tool/build/build.mk b/tool/build/build.mk index 0329076ce..79698ac51 100644 --- a/tool/build/build.mk +++ b/tool/build/build.mk @@ -93,6 +93,14 @@ o/$(MODE)/tool/build/%.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) +o/$(MODE)/tool/build/blinkenlights.com: \ + o/$(MODE)/tool/build/blinkenlights.com.dbg \ + o/$(MODE)/third_party/zip/zip.com \ + o/$(MODE)/tool/build/symtab.com + @$(MAKE_OBJCOPY) + @$(MAKE_SYMTAB_CREATE) + @$(MAKE_SYMTAB_ZIP) + o/$(MODE)/tool/build/emulator.o: private \ OVERRIDE_COPTS += \ -fno-sanitize=pointer-overflow diff --git a/tool/net/net.mk b/tool/net/net.mk index 464ceabfe..2615368b6 100644 --- a/tool/net/net.mk +++ b/tool/net/net.mk @@ -110,10 +110,11 @@ o/$(MODE)/tool/net/redbean.com.dbg: \ o/$(MODE)/tool/net/redbean.com: \ o/$(MODE)/tool/net/redbean.com.dbg \ + o/$(MODE)/third_party/zip/zip.com \ o/$(MODE)/tool/build/symtab.com - @$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@ - @$(COMPILE) -wASYMTAB o/$(MODE)/tool/build/symtab.com -o $(SYMTAB) $< - @$(COMPILE) -wAZIP -T$@ $@ -A $(SYMTAB) + @$(MAKE_OBJCOPY) + @$(MAKE_SYMTAB_CREATE) + @$(MAKE_SYMTAB_ZIP) # REDBEAN-DEMO.COM # @@ -223,10 +224,11 @@ o/$(MODE)/tool/net/redbean-demo.com.dbg: \ o/$(MODE)/tool/net/redbean-demo.com: \ o/$(MODE)/tool/net/redbean-demo.com.dbg \ + o/$(MODE)/third_party/zip/zip.com \ o/$(MODE)/tool/build/symtab.com - @$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@ - @$(COMPILE) -wASYMTAB o/$(MODE)/tool/build/symtab.com -o $(SYMTAB) $< - @$(COMPILE) -wAZIP -T$@ $@ -A $(SYMTAB) + @$(MAKE_OBJCOPY) + @$(MAKE_SYMTAB_CREATE) + @$(MAKE_SYMTAB_ZIP) # REDBEAN-STATIC.COM # @@ -244,6 +246,14 @@ o/$(MODE)/tool/net/redbean-static.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) +o/$(MODE)/tool/net/redbean-static.com: \ + o/$(MODE)/tool/net/redbean-static.com.dbg \ + o/$(MODE)/third_party/zip/zip.com \ + o/$(MODE)/tool/build/symtab.com + @$(MAKE_OBJCOPY) + @$(MAKE_SYMTAB_CREATE) + @$(MAKE_SYMTAB_ZIP) + # REDBEAN-UNSECURE.COM # # Passing the -DUNSECURE will cause the TLS security code to be removed. @@ -269,6 +279,14 @@ o/$(MODE)/tool/net/redbean-unsecure.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) +o/$(MODE)/tool/net/redbean-unsecure.com: \ + o/$(MODE)/tool/net/redbean-unsecure.com.dbg \ + o/$(MODE)/third_party/zip/zip.com \ + o/$(MODE)/tool/build/symtab.com + @$(MAKE_OBJCOPY) + @$(MAKE_SYMTAB_CREATE) + @$(MAKE_SYMTAB_ZIP) + # REDBEAN-ORIGINAL.COM # # Passing the -DSTATIC and -DUNSECURE flags together w/ MODE=tiny will @@ -286,6 +304,14 @@ o/$(MODE)/tool/net/redbean-original.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) +o/$(MODE)/tool/net/redbean-original.com: \ + o/$(MODE)/tool/net/redbean-original.com.dbg \ + o/$(MODE)/third_party/zip/zip.com \ + o/$(MODE)/tool/build/symtab.com + @$(MAKE_OBJCOPY) + @$(MAKE_SYMTAB_CREATE) + @$(MAKE_SYMTAB_ZIP) + o/$(MODE)/tool/net/demo/.lua/.zip.o: \ tool/net/demo/.lua o/$(MODE)/tool/net/demo/.zip.o: \ diff --git a/tool/plinko/plinko.mk b/tool/plinko/plinko.mk index 337a13fed..a3b3c645f 100644 --- a/tool/plinko/plinko.mk +++ b/tool/plinko/plinko.mk @@ -45,6 +45,14 @@ o/$(MODE)/tool/plinko/%.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) +o/$(MODE)/tool/plinko/plinko.com: \ + o/$(MODE)/tool/plinko/plinko.com.dbg \ + o/$(MODE)/third_party/zip/zip.com \ + o/$(MODE)/tool/build/symtab.com + @$(MAKE_OBJCOPY) + @$(MAKE_SYMTAB_CREATE) + @$(MAKE_SYMTAB_ZIP) + o/$(MODE)/tool/plinko/plinko.com.zip.o: \ o/$(MODE)/tool/plinko/plinko.com diff --git a/tool/viz/viz.mk b/tool/viz/viz.mk index dd02a7a94..c1ba2fa0d 100644 --- a/tool/viz/viz.mk +++ b/tool/viz/viz.mk @@ -38,7 +38,6 @@ TOOL_VIZ_DIRECTDEPS = \ LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ - LIBC_TESTLIB \ LIBC_TIME \ LIBC_TINYMATH \ LIBC_X \ @@ -79,6 +78,22 @@ o/$(MODE)/tool/viz/printimage.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) +o/$(MODE)/tool/viz/printimage.com: \ + o/$(MODE)/tool/viz/printimage.com.dbg \ + o/$(MODE)/third_party/zip/zip.com \ + o/$(MODE)/tool/build/symtab.com + @$(MAKE_OBJCOPY) + @$(MAKE_SYMTAB_CREATE) + @$(MAKE_SYMTAB_ZIP) + +o/$(MODE)/tool/viz/printvideo.com: \ + o/$(MODE)/tool/viz/printvideo.com.dbg \ + o/$(MODE)/third_party/zip/zip.com \ + o/$(MODE)/tool/build/symtab.com + @$(MAKE_OBJCOPY) + @$(MAKE_SYMTAB_CREATE) + @$(MAKE_SYMTAB_ZIP) + o/$(MODE)/tool/viz/derasterize.o: private \ OVERRIDE_CFLAGS += \ -DSTACK_FRAME_UNLIMITED \