mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Pay off more technical debt
This makes breaking changes to add underscores to many non-standard function names provided by the c library. MODE=tiny is now tinier and we now use smaller locks that are better for tiny apps in this mode. Some headers have been renamed to be in the same folder as the build package, so it'll be easier to know which build dependency is needed. Certain old misguided interfaces have been removed. Intel intrinsics headers are now listed in libc/isystem (but not in the amalgamation) to help further improve open source compatibility. Header complexity has also been reduced. Lastly, more shell scripts are now available.
This commit is contained in:
parent
b69f3d2488
commit
6f7d0cb1c3
960 changed files with 4072 additions and 4873 deletions
|
@ -16,23 +16,24 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/gc.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/crc32.h"
|
||||
#include "libc/nt/struct/filetime.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "libc/x/xasprintf.h"
|
||||
#include "libc/x/xiso8601.h"
|
||||
#include "libc/zip.h"
|
||||
#include "tool/decode/lib/asmcodegen.h"
|
||||
#include "tool/decode/lib/disassemblehex.h"
|
||||
|
@ -79,9 +80,9 @@ void ShowGeneralFlag(uint16_t generalflag) {
|
|||
|
||||
void ShowTimestamp(uint16_t time, uint16_t date) {
|
||||
show(".short", format(b1, "%#04hx", time),
|
||||
gc(xasprintf("%s (%s)", "lastmodifiedtime", gc(FormatDosTime(time)))));
|
||||
_gc(xasprintf("%s (%s)", "lastmodifiedtime", _gc(FormatDosTime(time)))));
|
||||
show(".short", format(b1, "%#04hx", date),
|
||||
gc(xasprintf("%s (%s)", "lastmodifieddate", gc(FormatDosDate(date)))));
|
||||
_gc(xasprintf("%s (%s)", "lastmodifieddate", _gc(FormatDosDate(date)))));
|
||||
}
|
||||
|
||||
void ShowCompressionMethod(uint16_t compressmethod) {
|
||||
|
@ -96,18 +97,19 @@ void ShowNtfs(uint8_t *ntfs, size_t n) {
|
|||
mtime = WindowsTimeToTimeSpec(READ64LE(ntfs + 8));
|
||||
atime = WindowsTimeToTimeSpec(READ64LE(ntfs + 16));
|
||||
ctime = WindowsTimeToTimeSpec(READ64LE(ntfs + 24));
|
||||
show(".long", gc(xasprintf("%d", READ32LE(ntfs))), "ntfs reserved");
|
||||
show(".short", gc(xasprintf("0x%04x", READ16LE(ntfs + 4))),
|
||||
show(".long", _gc(xasprintf("%d", READ32LE(ntfs))), "ntfs reserved");
|
||||
show(".short", _gc(xasprintf("0x%04x", READ16LE(ntfs + 4))),
|
||||
"ntfs attribute tag value #1");
|
||||
show(".short", gc(xasprintf("%hu", READ16LE(ntfs + 6))),
|
||||
show(".short", _gc(xasprintf("%hu", READ16LE(ntfs + 6))),
|
||||
"ntfs attribute tag size");
|
||||
show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 8))),
|
||||
gc(xasprintf("%s (%s)", "ntfs last modified time",
|
||||
gc(xiso8601(&mtime)))));
|
||||
show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 16))),
|
||||
gc(xasprintf("%s (%s)", "ntfs last access time", gc(xiso8601(&atime)))));
|
||||
show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 24))),
|
||||
gc(xasprintf("%s (%s)", "ntfs creation time", gc(xiso8601(&ctime)))));
|
||||
show(".quad", _gc(xasprintf("%lu", READ64LE(ntfs + 8))),
|
||||
_gc(xasprintf("%s (%s)", "ntfs last modified time",
|
||||
_gc(xiso8601(&mtime)))));
|
||||
show(".quad", _gc(xasprintf("%lu", READ64LE(ntfs + 16))),
|
||||
_gc(xasprintf("%s (%s)", "ntfs last access time",
|
||||
_gc(xiso8601(&atime)))));
|
||||
show(".quad", _gc(xasprintf("%lu", READ64LE(ntfs + 24))),
|
||||
_gc(xasprintf("%s (%s)", "ntfs creation time", _gc(xiso8601(&ctime)))));
|
||||
}
|
||||
|
||||
void ShowExtendedTimestamp(uint8_t *p, size_t n, bool islocal) {
|
||||
|
@ -115,28 +117,28 @@ void ShowExtendedTimestamp(uint8_t *p, size_t n, bool islocal) {
|
|||
if (n) {
|
||||
--n;
|
||||
flag = *p++;
|
||||
show(".byte", gc(xasprintf("0b%03hhb", flag)), "fields present in local");
|
||||
show(".byte", _gc(xasprintf("0b%03hhb", flag)), "fields present in local");
|
||||
if ((flag & 1) && n >= 4) {
|
||||
show(".long", gc(xasprintf("%u", READ32LE(p))),
|
||||
gc(xasprintf("%s (%s)", "last modified",
|
||||
gc(xiso8601(&(struct timespec){READ32LE(p)})))));
|
||||
show(".long", _gc(xasprintf("%u", READ32LE(p))),
|
||||
_gc(xasprintf("%s (%s)", "last modified",
|
||||
_gc(xiso8601(&(struct timespec){READ32LE(p)})))));
|
||||
p += 4;
|
||||
n -= 4;
|
||||
}
|
||||
flag >>= 1;
|
||||
if (islocal) {
|
||||
if ((flag & 1) && n >= 4) {
|
||||
show(".long", gc(xasprintf("%u", READ32LE(p))),
|
||||
gc(xasprintf("%s (%s)", "access time",
|
||||
gc(xiso8601(&(struct timespec){READ32LE(p)})))));
|
||||
show(".long", _gc(xasprintf("%u", READ32LE(p))),
|
||||
_gc(xasprintf("%s (%s)", "access time",
|
||||
_gc(xiso8601(&(struct timespec){READ32LE(p)})))));
|
||||
p += 4;
|
||||
n -= 4;
|
||||
}
|
||||
flag >>= 1;
|
||||
if ((flag & 1) && n >= 4) {
|
||||
show(".long", gc(xasprintf("%u", READ32LE(p))),
|
||||
gc(xasprintf("%s (%s)", "creation time",
|
||||
gc(xiso8601(&(struct timespec){READ32LE(p)})))));
|
||||
show(".long", _gc(xasprintf("%u", READ32LE(p))),
|
||||
_gc(xasprintf("%s (%s)", "creation time",
|
||||
_gc(xiso8601(&(struct timespec){READ32LE(p)})))));
|
||||
p += 4;
|
||||
n -= 4;
|
||||
}
|
||||
|
@ -146,19 +148,19 @@ void ShowExtendedTimestamp(uint8_t *p, size_t n, bool islocal) {
|
|||
|
||||
void ShowZip64(uint8_t *p, size_t n, bool islocal) {
|
||||
if (n >= 8) {
|
||||
show(".quad", gc(xasprintf("%lu", READ64LE(p))),
|
||||
gc(xasprintf("uncompressed size (%,ld)", READ64LE(p))));
|
||||
show(".quad", _gc(xasprintf("%lu", READ64LE(p))),
|
||||
_gc(xasprintf("uncompressed size (%,ld)", READ64LE(p))));
|
||||
}
|
||||
if (n >= 16) {
|
||||
show(".quad", gc(xasprintf("%lu", READ64LE(p + 8))),
|
||||
gc(xasprintf("compressed size (%,ld)", READ64LE(p + 8))));
|
||||
show(".quad", _gc(xasprintf("%lu", READ64LE(p + 8))),
|
||||
_gc(xasprintf("compressed size (%,ld)", READ64LE(p + 8))));
|
||||
}
|
||||
if (n >= 24) {
|
||||
show(".quad", gc(xasprintf("%lu", READ64LE(p + 16))),
|
||||
gc(xasprintf("lfile hdr offset (%,ld)", READ64LE(p + 16))));
|
||||
show(".quad", _gc(xasprintf("%lu", READ64LE(p + 16))),
|
||||
_gc(xasprintf("lfile hdr offset (%,ld)", READ64LE(p + 16))));
|
||||
}
|
||||
if (n >= 28) {
|
||||
show(".long", gc(xasprintf("%u", READ32LE(p + 24))), "disk number");
|
||||
show(".long", _gc(xasprintf("%u", READ32LE(p + 24))), "disk number");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,9 +168,9 @@ void ShowInfoZipNewUnixExtra(uint8_t *p, size_t n, bool islocal) {
|
|||
if (p[0] == 1 && p[1] == 4 && p[6] == 4) {
|
||||
show(".byte", "1", "version");
|
||||
show(".byte", "4", "uid length");
|
||||
show(".long", gc(xasprintf("%u", READ32LE(p + 2))), "uid");
|
||||
show(".long", _gc(xasprintf("%u", READ32LE(p + 2))), "uid");
|
||||
show(".byte", "4", "gid length");
|
||||
show(".long", gc(xasprintf("%u", READ32LE(p + 7))), "gid");
|
||||
show(".long", _gc(xasprintf("%u", READ32LE(p + 7))), "gid");
|
||||
} else {
|
||||
disassemblehex(p, n, stdout);
|
||||
}
|
||||
|
@ -220,11 +222,11 @@ void ShowExtras(uint8_t *extras, uint16_t extrassize, bool islocal) {
|
|||
p += ZIP_EXTRA_SIZE(p), ++i) {
|
||||
show(".short",
|
||||
firstnonnull(findnamebyid(kZipExtraNames, ZIP_EXTRA_HEADERID(p)),
|
||||
gc(xasprintf("0x%04hx", ZIP_EXTRA_HEADERID(p)))),
|
||||
gc(xasprintf("%s[%d].%s", "extras", i, "headerid")));
|
||||
show(".short", gc(xasprintf("%df-%df", (i + 2) * 10, (i + 1) * 10)),
|
||||
gc(xasprintf("%s[%d].%s (%hd %s)", "extras", i, "contentsize",
|
||||
ZIP_EXTRA_CONTENTSIZE(p), "bytes")));
|
||||
_gc(xasprintf("0x%04hx", ZIP_EXTRA_HEADERID(p)))),
|
||||
_gc(xasprintf("%s[%d].%s", "extras", i, "headerid")));
|
||||
show(".short", _gc(xasprintf("%df-%df", (i + 2) * 10, (i + 1) * 10)),
|
||||
_gc(xasprintf("%s[%d].%s (%hd %s)", "extras", i, "contentsize",
|
||||
ZIP_EXTRA_CONTENTSIZE(p), "bytes")));
|
||||
if (first) {
|
||||
first = false;
|
||||
printf("%d:", (i + 1) * 10);
|
||||
|
@ -242,18 +244,18 @@ void ShowLocalFileHeader(uint8_t *lf, uint16_t idx) {
|
|||
show(".ascii", format(b1, "%`'.*s", 4, lf), "magic");
|
||||
show(".byte",
|
||||
firstnonnull(findnamebyid(kZipEraNames, ZIP_LFILE_VERSIONNEED(lf)),
|
||||
gc(xasprintf("%d", ZIP_LFILE_VERSIONNEED(lf)))),
|
||||
_gc(xasprintf("%d", ZIP_LFILE_VERSIONNEED(lf)))),
|
||||
"pkzip version need");
|
||||
show(".byte",
|
||||
firstnonnull(findnamebyid(kZipOsNames, ZIP_LFILE_OSNEED(lf)),
|
||||
gc(xasprintf("%d", ZIP_LFILE_OSNEED(lf)))),
|
||||
_gc(xasprintf("%d", ZIP_LFILE_OSNEED(lf)))),
|
||||
"os need");
|
||||
ShowGeneralFlag(ZIP_LFILE_GENERALFLAG(lf));
|
||||
ShowCompressionMethod(ZIP_LFILE_COMPRESSIONMETHOD(lf));
|
||||
ShowTimestamp(ZIP_LFILE_LASTMODIFIEDTIME(lf), ZIP_LFILE_LASTMODIFIEDDATE(lf));
|
||||
show(
|
||||
".long",
|
||||
format(b1, "%#x", ZIP_LFILE_CRC32(lf)), gc(xasprintf("%s (%#x)", "crc32z", GetZipLfileCompressedSize(lf) /* crc32_z(0, ZIP_LFILE_CONTENT(lf), GetZipLfileCompressedSize(lf)) */)));
|
||||
format(b1, "%#x", ZIP_LFILE_CRC32(lf)), _gc(xasprintf("%s (%#x)", "crc32z", GetZipLfileCompressedSize(lf) /* crc32_z(0, ZIP_LFILE_CONTENT(lf), GetZipLfileCompressedSize(lf)) */)));
|
||||
if (ZIP_LFILE_COMPRESSEDSIZE(lf) == 0xFFFFFFFF) {
|
||||
show(".long", "0xFFFFFFFF", "compressedsize (zip64)");
|
||||
} else {
|
||||
|
@ -274,7 +276,7 @@ void ShowLocalFileHeader(uint8_t *lf, uint16_t idx) {
|
|||
printf("0:");
|
||||
show(".ascii",
|
||||
format(b1, "%`'s",
|
||||
gc(strndup(ZIP_LFILE_NAME(lf), ZIP_LFILE_NAMESIZE(lf)))),
|
||||
_gc(strndup(ZIP_LFILE_NAME(lf), ZIP_LFILE_NAMESIZE(lf)))),
|
||||
"name");
|
||||
printf("1:");
|
||||
ShowExtras(ZIP_LFILE_EXTRA(lf), ZIP_LFILE_EXTRASIZE(lf), true);
|
||||
|
@ -288,19 +290,19 @@ void ShowCentralFileHeader(uint8_t *cf) {
|
|||
printf("\n/\t%s (%zu %s)\n", "central directory file header",
|
||||
ZIP_CFILE_HDRSIZE(cf), "bytes");
|
||||
show(".ascii", format(b1, "%`'.*s", 4, cf), "magic");
|
||||
show(".byte", gc(xasprintf("%d", ZIP_CFILE_VERSIONMADE(cf))),
|
||||
show(".byte", _gc(xasprintf("%d", ZIP_CFILE_VERSIONMADE(cf))),
|
||||
"zip version made");
|
||||
show(".byte",
|
||||
firstnonnull(findnamebyid(kZipOsNames, ZIP_CFILE_FILEATTRCOMPAT(cf)),
|
||||
gc(xasprintf("%d", ZIP_CFILE_FILEATTRCOMPAT(cf)))),
|
||||
_gc(xasprintf("%d", ZIP_CFILE_FILEATTRCOMPAT(cf)))),
|
||||
"file attr compat");
|
||||
show(".byte",
|
||||
firstnonnull(findnamebyid(kZipEraNames, ZIP_CFILE_VERSIONNEED(cf)),
|
||||
gc(xasprintf("%d", ZIP_CFILE_VERSIONNEED(cf)))),
|
||||
_gc(xasprintf("%d", ZIP_CFILE_VERSIONNEED(cf)))),
|
||||
"pkzip version need");
|
||||
show(".byte",
|
||||
firstnonnull(findnamebyid(kZipOsNames, ZIP_CFILE_OSNEED(cf)),
|
||||
gc(xasprintf("%d", ZIP_CFILE_OSNEED(cf)))),
|
||||
_gc(xasprintf("%d", ZIP_CFILE_OSNEED(cf)))),
|
||||
"os need");
|
||||
ShowGeneralFlag(ZIP_CFILE_GENERALFLAG(cf));
|
||||
ShowCompressionMethod(ZIP_CFILE_COMPRESSIONMETHOD(cf));
|
||||
|
@ -339,7 +341,7 @@ void ShowCentralFileHeader(uint8_t *cf) {
|
|||
printf("0:");
|
||||
show(".ascii",
|
||||
format(b1, "%`'s",
|
||||
gc(strndup(ZIP_CFILE_NAME(cf), ZIP_CFILE_NAMESIZE(cf)))),
|
||||
_gc(strndup(ZIP_CFILE_NAME(cf), ZIP_CFILE_NAMESIZE(cf)))),
|
||||
"name");
|
||||
printf("1:");
|
||||
ShowExtras(ZIP_CFILE_EXTRA(cf), ZIP_CFILE_EXTRASIZE(cf), false);
|
||||
|
@ -427,7 +429,7 @@ void DisassembleZip(const char *path, uint8_t *p, size_t n) {
|
|||
uint16_t i;
|
||||
static int records;
|
||||
uint8_t *eocd32, *eocd64, *cdir, *cf, *lf, *q;
|
||||
if (endswith(path, ".com.dbg") && (q = memmem(p, n, "MZqFpD", 6))) {
|
||||
if (_endswith(path, ".com.dbg") && (q = memmem(p, n, "MZqFpD", 6))) {
|
||||
n -= q - p;
|
||||
p += q - p;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue