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:
Justine Tunney 2022-09-12 23:10:38 -07:00
parent b69f3d2488
commit 6f7d0cb1c3
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
960 changed files with 4072 additions and 4873 deletions

View file

@ -20,7 +20,7 @@
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/o.h"

View file

@ -18,6 +18,7 @@
*/
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/copyfd.internal.h"
#include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/stat.h"
#include "libc/elf/elf.h"
@ -30,7 +31,6 @@
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/arraylist2.internal.h"
#include "libc/mem/io.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/sock.h"
@ -232,8 +232,8 @@ int main(int argc, char *argv[]) {
for (i = 0;; ++i) {
TryAgain:
if (!(arg = getargs_next(&ga))) break;
if (endswith(arg, "/")) goto TryAgain;
if (endswith(arg, ".pkg")) goto TryAgain;
if (_endswith(arg, "/")) goto TryAgain;
if (_endswith(arg, ".pkg")) goto TryAgain;
CHECK_NE(-1, stat(arg, st), "%s", arg);
if (!st->st_size || S_ISDIR(st->st_mode)) goto TryAgain;
CHECK_NE(-1, (fd = open(arg, O_RDONLY)), "%s", arg);

View file

@ -21,7 +21,7 @@
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -41,6 +41,7 @@
#include "libc/intrin/pcmpeqb.h"
#include "libc/intrin/pmovmskb.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/intrin/tpenc.h"
#include "libc/limits.h"
#include "libc/log/check.h"
#include "libc/log/color.internal.h"
@ -49,18 +50,17 @@
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/arraylist2.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/sock.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/str/strwidth.h"
#include "libc/str/thompike.h"
#include "libc/str/tpdecode.internal.h"
#include "libc/str/tpenc.h"
#include "libc/str/tpencode.internal.h"
#include "libc/sysv/consts/auxv.h"
#include "libc/sysv/consts/ex.h"
@ -77,6 +77,8 @@
#include "libc/sysv/errfuns.h"
#include "libc/time/time.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "libc/x/xsigaction.h"
#include "third_party/gdtoa/gdtoa.h"
#include "third_party/getopt/getopt.h"
#include "tool/build/lib/address.h"
@ -589,14 +591,14 @@ static void ToggleMouseTracking(void) {
}
static void LeaveScreen(void) {
TtyWriteString(gc(xasprintf("\e[%d;%dH\e[S\r\n", tyn, txn)));
TtyWriteString(_gc(xasprintf("\e[%d;%dH\e[S\r\n", tyn, txn)));
}
static void GetTtySize(int fd) {
struct winsize wsize;
wsize.ws_row = tyn;
wsize.ws_col = txn;
getttysize(fd, &wsize);
_getttysize(fd, &wsize);
tyn = wsize.ws_row;
txn = wsize.ws_col;
}
@ -760,7 +762,7 @@ void TuiSetup(void) {
static bool once;
report = false;
if (!once) {
INFOF("loaded program %s\n%s", codepath, gc(FormatPml4t(m)));
INFOF("loaded program %s\n%s", codepath, _gc(FormatPml4t(m)));
CommonSetup();
ioctl(ttyout, TCGETS, &oldterm);
xsigaction(SIGINT, OnSigInt, 0, 0, oldsig + 3);
@ -776,7 +778,7 @@ void TuiSetup(void) {
DrainInput(ttyin);
y = 0;
if (GetCursorPosition(&y, NULL) != -1) {
TtyWriteString(gc(xasprintf("\e[%dS", y)));
TtyWriteString(_gc(xasprintf("\e[%dS", y)));
}
}
}
@ -1686,7 +1688,7 @@ static void DrawStatus(struct Panel *p) {
rw += AppendStat(s, "freed", a->freed, a->freed != b->freed);
rw += AppendStat(s, "tables", a->pagetables, a->pagetables != b->pagetables);
rw += AppendStat(s, "fds", m->fds.i, false);
AppendFmt(&p->lines[0], "\e[7m%-*s%s\e[0m", xn - rw, gc(GetStatus(xn - rw)),
AppendFmt(&p->lines[0], "\e[7m%-*s%s\e[0m", xn - rw, _gc(GetStatus(xn - rw)),
s->p);
free(s->p);
free(s);
@ -2258,7 +2260,7 @@ static void OnVidyaServiceWriteCharacter(void) {
p = buf;
p += FormatCga(m->bx[0], p);
p = stpcpy(p, "\e7");
w = tpenc(GetVidyaByte(m->ax[0]));
w = _tpenc(GetVidyaByte(m->ax[0]));
do {
*p++ = w;
} while ((w >>= 8));
@ -2286,7 +2288,7 @@ static void OnVidyaServiceTeletypeOutput(void) {
uint64_t w;
char buf[12];
n = 0 /* FormatCga(m->bx[0], buf) */;
w = tpenc(VidyaServiceXlatTeletype(m->ax[0]));
w = _tpenc(VidyaServiceXlatTeletype(m->ax[0]));
do buf[n++] = w;
while ((w >>= 8));
PtyWrite(pty, buf, n);

View file

@ -8,32 +8,32 @@
*/
#endif
#include "dsp/tty/tty.h"
#include "libc/mem/arraylist2.internal.h"
#include "libc/assert.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/morton.h"
#include "libc/intrin/popcnt.h"
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/fmt/fmt.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/morton.h"
#include "libc/intrin/popcnt.h"
#include "libc/limits.h"
#include "libc/log/color.internal.h"
#include "libc/log/internal.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/arraylist2.internal.h"
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"
#include "libc/sysv/consts/sig.h"
#include "libc/tinymath/emodl.h"
#include "libc/x/x.h"
#include "libc/x/xsigaction.h"
#include "third_party/gdtoa/gdtoa.h"
#include "third_party/getopt/getopt.h"
@ -339,7 +339,7 @@ void OpMeminfo(void) {
OpCr();
OpCr();
fflush(stdout);
meminfo(fileno(stdout));
_meminfo(fileno(stdout));
}
void Glue2f(FLOAT fn(FLOAT, FLOAT)) {
@ -470,7 +470,7 @@ void ConsumeToken(void) {
token.i = 0;
if (history.i) history.p[history.i - 1].i = 0;
if (comment) return;
if (startswith(token.p, "#!")) return;
if (_startswith(token.p, "#!")) return;
switch (setjmp(thrower)) {
default:
if (CallFunction(token.p)) return;

View file

@ -22,7 +22,6 @@
#include "libc/fmt/conv.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"
@ -107,7 +106,7 @@ int main(int argc, char *argv[]) {
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);
const char *s = _strerdoc(errno);
fputs(prog, stderr);
fputs(": ", stderr);
fputs(argv[i], stderr);

View file

@ -23,7 +23,6 @@
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/o.h"
@ -72,7 +71,7 @@ wontreturn void SysExit(int rc, const char *call, const char *thing) {
const char *estr;
err = errno;
FormatInt32(ibuf, err);
estr = strerdoc(err);
estr = _strerdoc(err);
if (!estr) estr = "EUNKNOWN";
Write(thing, ": ", call, "() failed: ", estr, " (", ibuf, ")\n", 0);
exit(rc);

View file

@ -17,14 +17,17 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/copyfd.internal.h"
#include "libc/calls/copyfile.h"
#include "libc/calls/ioctl.h"
#include "libc/calls/struct/itimerval.h"
#include "libc/calls/struct/rlimit.h"
#include "libc/calls/struct/rusage.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/sigset.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/struct/timeval.h"
#include "libc/calls/struct/winsize.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h"
@ -33,21 +36,20 @@
#include "libc/intrin/kprintf.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/limits.h"
#include "libc/log/appendresourcereport.internal.h"
#include "libc/log/color.internal.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/alg.h"
#include "libc/mem/io.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/kcpuids.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/sysconf.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/auxv.h"
#include "libc/sysv/consts/clock.h"
@ -394,16 +396,16 @@ bool IsGccOnlyFlag(const char *s) {
return true;
}
}
if (startswith(s, "-ffixed-")) return true;
if (startswith(s, "-fcall-saved")) return true;
if (startswith(s, "-fcall-used")) return true;
if (startswith(s, "-fgcse-")) return true;
if (startswith(s, "-fvect-cost-model=")) return true;
if (startswith(s, "-fsimd-cost-model=")) return true;
if (startswith(s, "-fopt-info")) return true;
if (startswith(s, "-mstringop-strategy=")) return true;
if (startswith(s, "-mpreferred-stack-boundary=")) return true;
if (startswith(s, "-Wframe-larger-than=")) return true;
if (_startswith(s, "-ffixed-")) return true;
if (_startswith(s, "-fcall-saved")) return true;
if (_startswith(s, "-fcall-used")) return true;
if (_startswith(s, "-fgcse-")) return true;
if (_startswith(s, "-fvect-cost-model=")) return true;
if (_startswith(s, "-fsimd-cost-model=")) return true;
if (_startswith(s, "-fopt-info")) return true;
if (_startswith(s, "-mstringop-strategy=")) return true;
if (_startswith(s, "-mpreferred-stack-boundary=")) return true;
if (_startswith(s, "-Wframe-larger-than=")) return true;
return false;
}
@ -436,7 +438,7 @@ void AddEnv(char *s) {
}
char *StripPrefix(char *s, char *p) {
if (startswith(s, p)) {
if (_startswith(s, p)) {
return s + strlen(p);
} else {
return s;
@ -454,18 +456,18 @@ void AddArg(char *s) {
appendw(&shortened, ' ');
if ((isar || isbfd || ispkg) &&
(strcmp(args.p[args.n - 1], "-o") &&
(endswith(s, ".o") || endswith(s, ".pkg") ||
(endswith(s, ".a") && !isar)))) {
(_endswith(s, ".o") || _endswith(s, ".pkg") ||
(_endswith(s, ".a") && !isar)))) {
appends(&shortened, basename(s));
} else {
appends(&shortened, s);
}
} else if (/*
* a in ('-', '--') or
* a.startswith('-o') or
* a._startswith('-o') or
* c == 'ld' and a == '-T' or
* c == 'cc' and a.startswith('-O') or
* c == 'cc' and a.startswith('-x') or
* c == 'cc' and a._startswith('-O') or
* c == 'cc' and a._startswith('-x') or
* c == 'cc' and a in ('-c', '-E', '-S')
*/
s[0] == '-' && (!s[1] || s[1] == 'o' || (s[1] == '-' && !s[2]) ||
@ -592,7 +594,7 @@ int Launch(void) {
gotchld = 0;
if (pipe2(pipefds, O_CLOEXEC) == -1) {
kprintf("pipe2 failed: %s\n", strerrno(errno));
kprintf("pipe2 failed: %s\n", _strerrno(errno));
exit(1);
}
@ -605,7 +607,7 @@ int Launch(void) {
pid = vfork();
if (pid == -1) {
kprintf("vfork failed: %s\n", strerrno(errno));
kprintf("vfork failed: %s\n", _strerrno(errno));
exit(1);
}
@ -629,7 +631,7 @@ int Launch(void) {
dup2(pipefds[1], 2);
sigprocmask(SIG_SETMASK, &savemask, 0);
execve(cmd, args.p, env.p);
kprintf("execve(%#s) failed: %s\n", cmd, strerrno(errno));
kprintf("execve(%#s) failed: %s\n", cmd, _strerrno(errno));
_Exit(127);
}
close(pipefds[1]);
@ -956,7 +958,7 @@ int main(int argc, char *argv[]) {
/*
* capture flags
*/
if (startswith(argv[i], "-o")) {
if (_startswith(argv[i], "-o")) {
if (!strcmp(argv[i], "-o")) {
outpath = argv[++i];
} else {
@ -1040,25 +1042,25 @@ int main(int argc, char *argv[]) {
if (isgcc && ccversion >= 6) no_sanitize_alignment = true;
} else if (!strcmp(argv[i], "-fno-sanitize=pointer-overflow")) {
if (isgcc && ccversion >= 6) no_sanitize_pointer_overflow = true;
} else if (startswith(argv[i], "-fsanitize=implicit") &&
} else if (_startswith(argv[i], "-fsanitize=implicit") &&
strstr(argv[i], "integer")) {
if (isgcc) AddArg(argv[i]);
} else if (startswith(argv[i], "-fvect-cost") ||
startswith(argv[i], "-mstringop") ||
startswith(argv[i], "-gz") ||
} else if (_startswith(argv[i], "-fvect-cost") ||
_startswith(argv[i], "-mstringop") ||
_startswith(argv[i], "-gz") ||
strstr(argv[i], "stack-protector") ||
strstr(argv[i], "sanitize") ||
startswith(argv[i], "-fvect-cost") ||
startswith(argv[i], "-fvect-cost")) {
_startswith(argv[i], "-fvect-cost") ||
_startswith(argv[i], "-fvect-cost")) {
if (isgcc && ccversion >= 6) {
AddArg(argv[i]);
}
} else if (startswith(argv[i], "-fdiagnostic-color=")) {
} else if (_startswith(argv[i], "-fdiagnostic-color=")) {
colorflag = argv[i];
} else if (startswith(argv[i], "-R") ||
} else if (_startswith(argv[i], "-R") ||
!strcmp(argv[i], "-fsave-optimization-record")) {
if (isclang) AddArg(argv[i]);
} else if (isclang && startswith(argv[i], "--debug-prefix-map")) {
} else if (isclang && _startswith(argv[i], "--debug-prefix-map")) {
/* llvm doesn't provide a gas interface so simulate w/ clang */
AddArg(xstrcat("-f", argv[i] + 2));
} else if (isgcc && (!strcmp(argv[i], "-Os") || !strcmp(argv[i], "-O2") ||
@ -1143,7 +1145,7 @@ int main(int argc, char *argv[]) {
* scrub environment for determinism and great justice
*/
for (envp = environ; *envp; ++envp) {
if (startswith(*envp, "MODE=")) {
if (_startswith(*envp, "MODE=")) {
mode = *envp + 5;
}
if (IsSafeEnv(*envp)) {

View file

@ -17,16 +17,15 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/copyfd.internal.h"
#include "libc/calls/copyfile.h"
#include "libc/calls/struct/stat.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/fmt/fmt.h"
#include "libc/mem/io.h"
#include "libc/runtime/gc.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/ex.h"
@ -132,7 +131,7 @@ int Visit(const char *fpath, const struct stat *sb, int tflag,
strcpy(srcfile, fpath);
src = srcfile + striplen;
strcpy(dstfile, dstdir);
if (!endswith(dstfile, "/")) {
if (!_endswith(dstfile, "/")) {
strcat(dstfile, "/");
}
strcat(dstfile, src);
@ -210,7 +209,7 @@ void Cp(char *src, char *dst) {
if (nftw(src, Visit, 20, 0) == -1) {
fputs(prog, stderr);
fputs(": nftw failed: ", stderr);
fputs(strerdoc(errno), stderr);
fputs(_strerdoc(errno), stderr);
fputs("\n", stderr);
exit(1);
}
@ -231,7 +230,7 @@ void Cp(char *src, char *dst) {
}
return;
OnFail:
s = strerdoc(errno);
s = _strerdoc(errno);
fputs(prog, stderr);
fputs(": ", stderr);
fputs(src, stderr);

View file

@ -23,7 +23,6 @@
#include "libc/limits.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/o.h"
@ -36,7 +35,7 @@ wontreturn void SysFail(const char *func, const char *file) {
fputs(" failed: ", stderr);
fputs(file, stderr);
fputs(": ", stderr);
fputs(nulltoempty(strerdoc(e)), stderr);
fputs(nulltoempty(_strerdoc(e)), stderr);
fputs("\n", stderr);
exit(__COUNTER__ + 1);
}

View file

@ -28,7 +28,7 @@
#include "libc/sysv/consts/sa.h"
#include "libc/sysv/consts/sig.h"
#include "libc/time/time.h"
#include "libc/x/x.h"
#include "libc/x/xgetline.h"
static int pid;

View file

@ -30,7 +30,6 @@
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/runtime/runtime.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/msync.h"
@ -66,7 +65,7 @@ wontreturn void SysExit(int rc, const char *call, const char *thing) {
const char *estr;
err = errno;
FormatInt32(ibuf, err);
estr = strerdoc(err);
estr = _strerdoc(err);
if (!estr) estr = "EUNKNOWN";
Write(thing, ": ", call, "() failed: ", estr, " (", ibuf, ")\n", 0);
exit(rc);

View file

@ -21,7 +21,6 @@
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"
@ -171,7 +170,7 @@ void Compress(const char *inpath) {
if (!output) {
fputs(outpath, stderr);
fputs(": gzopen() failed\n", stderr);
fputs(strerdoc(errno), stderr);
fputs(_strerdoc(errno), stderr);
fputs("\n", stderr);
exit(1);
}
@ -181,7 +180,7 @@ void Compress(const char *inpath) {
errnum = 0;
fputs(inpath, stderr);
fputs(": read failed: ", stderr);
fputs(strerdoc(ferror(input)), stderr);
fputs(_strerdoc(ferror(input)), stderr);
fputs("\n", stderr);
_Exit(1);
}
@ -226,14 +225,14 @@ void Decompress(const char *inpath) {
if (!input) {
fputs(inpath, stderr);
fputs(": gzopen() failed\n", stderr);
fputs(strerdoc(errno), stderr);
fputs(_strerdoc(errno), stderr);
fputs("\n", stderr);
exit(1);
}
if (opt_usestdout) {
output = stdout;
outpath = "/dev/stdout";
} else if (endswith(inpath, ".gz")) {
} else if (_endswith(inpath, ".gz")) {
n = strlen(inpath);
if (n - 3 + 1 > PATH_MAX) _Exit(2);
memcpy(pathbuf, inpath, n - 3);
@ -242,7 +241,7 @@ void Decompress(const char *inpath) {
if (!(output = fopen(outpath, opt_append ? "wa" : "wb"))) {
fputs(outpath, stderr);
fputs(": open failed: ", stderr);
fputs(strerdoc(errno), stderr);
fputs(_strerdoc(errno), stderr);
fputs("\n", stderr);
_Exit(1);
}
@ -264,7 +263,7 @@ void Decompress(const char *inpath) {
if (fwrite(databuf, rc, 1, output) != 1) {
fputs(outpath, stderr);
fputs(": write failed: ", stderr);
fputs(strerdoc(ferror(output)), stderr);
fputs(_strerdoc(ferror(output)), stderr);
fputs("\n", stderr);
_Exit(1);
}

View file

@ -16,8 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/safemacros.internal.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/macros.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
@ -331,7 +331,7 @@ void HandleOperand(const char *op) {
while (*op) {
found = false;
for (i = 0; i < ARRAYLEN(kDescriptors); ++i) {
if (startswith(op, kDescriptors[i].prefix)) {
if (_startswith(op, kDescriptors[i].prefix)) {
found = true;
op += strlen(kDescriptors[i].prefix);
if (succinct_) {

View file

@ -18,7 +18,7 @@
*/
#include "libc/log/check.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/str.h"
#include "tool/build/lib/endian.h"
#include "tool/build/lib/machine.h"

View file

@ -16,15 +16,15 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/arraylist2.internal.h"
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/fmt/fmt.h"
#include "libc/intrin/tpenc.h"
#include "libc/macros.internal.h"
#include "libc/mem/arraylist2.internal.h"
#include "libc/mem/fmt.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "libc/str/tpenc.h"
#include "tool/build/lib/buffer.h"
/* TODO(jart): replace with new append*() library */
@ -55,7 +55,7 @@ void AppendWide(struct Buffer *b, wint_t wc) {
uint64_t wb;
char buf[8];
i = 0;
wb = tpenc(wc);
wb = _tpenc(wc);
do {
buf[i++] = wb & 0xFF;
wb >>= 8;

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/nexgen32e/bsr.h"
#include "libc/intrin/bsr.h"
#include "libc/nexgen32e/x86feature.h"
#include "tool/build/lib/clmul.h"
#include "tool/build/lib/endian.h"
@ -33,7 +33,7 @@ struct clmul {
static struct clmul clmul(uint64_t a, uint64_t b) {
uint64_t t, x = 0, y = 0;
if (a && b) {
if (bsrl(a) < bsrl(b)) t = a, a = b, b = t;
if (_bsrl(a) < _bsrl(b)) t = a, a = b, b = t;
for (t = 0; b; a <<= 1, b >>= 1) {
if (b & 1) x ^= a, y ^= t;
t = t << 1 | a >> 63;

View file

@ -115,7 +115,7 @@ char *Demangle(char *p, const char *symbol, size_t n) {
char *r;
size_t sn;
sn = strlen(symbol);
if (startswith(symbol, "_Z")) {
if (_startswith(symbol, "_Z")) {
if ((r = DemangleCxxFilt(p, n, symbol, sn))) return r;
}
return CopySymbol(p, n, symbol, sn);

View file

@ -18,11 +18,11 @@
*/
#include "libc/fmt/bing.internal.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/tpenc.h"
#include "libc/log/check.h"
#include "libc/mem/arraylist2.internal.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "libc/str/tpenc.h"
#include "third_party/xed/x86.h"
#include "tool/build/lib/demangle.h"
#include "tool/build/lib/dis.h"
@ -151,7 +151,7 @@ static char *DisLineData(struct Dis *d, char *p, const uint8_t *b, size_t n) {
*p++ = '#';
*p++ = ' ';
for (i = 0; i < n; ++i) {
w = tpenc(bing(b[i], 0));
w = _tpenc(bing(b[i], 0));
do {
*p++ = w;
} while ((w >>= 8));

View file

@ -16,12 +16,12 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/alg.h"
#include "libc/elf/elf.h"
#include "libc/elf/struct/sym.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/alg.h"
#include "libc/mem/mem.h"
#include "libc/runtime/memtrack.internal.h"
#include "libc/str/str.h"
@ -85,7 +85,7 @@ static void DisLoadElfSyms(struct Dis *d, struct Elf *elf) {
for (i = 0; i < n; ++i) {
if (ELF64_ST_TYPE(st[i].st_info) == STT_SECTION ||
ELF64_ST_TYPE(st[i].st_info) == STT_FILE || !st[i].st_name ||
startswith(d->syms.stab + st[i].st_name, "v_") ||
_startswith(d->syms.stab + st[i].st_name, "v_") ||
!(0 <= st[i].st_name && st[i].st_name < stablen) || !st[i].st_value ||
!IsLegalPointer(st[i].st_value)) {
continue;

View file

@ -158,8 +158,8 @@ static char *DisName(struct Dis *d, char *bp, const char *name,
} else {
*p++ = 's';
}
} else if (wantsuffix || (ambiguous && !startswith(name, "f") &&
!startswith(name, "set"))) {
} else if (wantsuffix || (ambiguous && !_startswith(name, "f") &&
!_startswith(name, "set"))) {
if (Osz(rde)) {
if (ambiguous || Mode(rde) != XED_MODE_REAL) {
*p++ = 'w';

View file

@ -21,7 +21,7 @@
#include "libc/elf/def.h"
#include "libc/log/check.h"
#include "libc/mem/arraylist2.internal.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/runtime/memtrack.internal.h"
#include "libc/stdalign.internal.h"
#include "libc/str/str.h"
@ -29,7 +29,7 @@
#include "libc/sysv/consts/msync.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "tool/build/lib/elfwriter.h"
static const Elf64_Ehdr kObjHeader = {
@ -86,8 +86,8 @@ static void MakeRelaSection(struct ElfWriter *elf, size_t section) {
elfwriter_align(elf, alignof(Elf64_Rela), sizeof(Elf64_Rela));
shdr = elfwriter_startsection(
elf,
gc(xasprintf("%s%s", ".rela",
&elf->shstrtab->p[elf->shdrs->p[section].sh_name])),
_gc(xasprintf("%s%s", ".rela",
&elf->shstrtab->p[elf->shdrs->p[section].sh_name])),
SHT_RELA, SHF_INFO_LINK);
elf->shdrs->p[shdr].sh_info = section;
elfwriter_reserve(elf, size);

View file

@ -22,12 +22,13 @@
#include "libc/log/check.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/stdio/rand.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/s.h"
#include "libc/time/struct/tm.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "libc/zip.h"
#include "third_party/zlib/zlib.h"
#include "tool/build/lib/elfwriter.h"
@ -166,7 +167,7 @@ void elfwriter_zip(struct ElfWriter *elf, const char *symbol, const char *name,
/* emit embedded file content w/ pkzip local file header */
elfwriter_align(elf, 1, 0);
elfwriter_startsection(elf,
gc(xasprintf("%s%s", ZIP_LOCALFILE_SECTION, name)),
_gc(xasprintf("%s%s", ZIP_LOCALFILE_SECTION, name)),
SHT_PROGBITS, SHF_ALLOC);
if (method == kZipCompressionDeflate) {
CHECK_EQ(Z_OK, deflateInit2(memset(&zs, 0, sizeof(zs)),
@ -195,9 +196,9 @@ void elfwriter_zip(struct ElfWriter *elf, const char *symbol, const char *name,
EmitZipLfileHdr(lfile, name, namesize, crc, era, gflags, method, mtime, mdate,
compsize, uncompsize);
elfwriter_commit(elf, lfilehdrsize + compsize);
lfilesym = elfwriter_appendsym(elf, gc(xasprintf("%s%s", "zip+lfile:", name)),
ELF64_ST_INFO(STB_LOCAL, STT_OBJECT),
STV_DEFAULT, 0, lfilehdrsize);
lfilesym = elfwriter_appendsym(
elf, _gc(xasprintf("%s%s", "zip+lfile:", name)),
ELF64_ST_INFO(STB_LOCAL, STT_OBJECT), STV_DEFAULT, 0, lfilehdrsize);
elfwriter_appendsym(elf, symbol, ELF64_ST_INFO(STB_GLOBAL, STT_OBJECT),
STV_DEFAULT, lfilehdrsize, compsize);
elfwriter_finishsection(elf);
@ -205,13 +206,13 @@ void elfwriter_zip(struct ElfWriter *elf, const char *symbol, const char *name,
/* emit central directory record */
elfwriter_align(elf, 1, 0);
elfwriter_startsection(elf,
gc(xasprintf("%s%s", ZIP_DIRECTORY_SECTION, name)),
_gc(xasprintf("%s%s", ZIP_DIRECTORY_SECTION, name)),
SHT_PROGBITS, SHF_ALLOC);
EmitZipCdirHdr(
(cfile = elfwriter_reserve(elf, kZipCdirHdrLinkableSizeBootstrap)), name,
namesize, crc, era, gflags, method, mtime, mdate, iattrs, dosmode, mode,
compsize, uncompsize, commentsize, mtim, atim, ctim);
elfwriter_appendsym(elf, gc(xasprintf("%s%s", "zip+cdir:", name)),
elfwriter_appendsym(elf, _gc(xasprintf("%s%s", "zip+cdir:", name)),
ELF64_ST_INFO(STB_LOCAL, STT_OBJECT), STV_DEFAULT, 0,
kZipCdirHdrLinkableSizeBootstrap);
elfwriter_appendrela(elf, kZipCfileOffsetOffset, lfilesym, R_X86_64_32,

View file

@ -18,10 +18,12 @@
*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/iovec.h"
#include "libc/errno.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/sysv/consts/sig.h"
#include "libc/x/x.h"
#include "libc/x/xsigaction.h"
#include "net/https/https.h"
#include "third_party/mbedtls/net_sockets.h"
#include "third_party/mbedtls/ssl.h"

View file

@ -16,8 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bsf.h"
#include "libc/macros.internal.h"
#include "libc/nexgen32e/bsf.h"
#include "libc/str/str.h"
#include "third_party/xed/x86.h"
#include "tool/build/lib/address.h"
@ -33,7 +33,7 @@ static bool IsOpcodeEqual(struct XedDecodedInst *xedd, uint8_t *a) {
if (xedd->length) {
if (xedd->length <= 7) {
w = Read64(a) ^ Read64(xedd->bytes);
return !w || bsfl(w) >= (xedd->length << 3);
return !w || _bsfl(w) >= (xedd->length << 3);
} else {
return memcmp(a, xedd->bytes, xedd->length) == 0;
}

View file

@ -122,7 +122,7 @@ static void SplitLines(struct Lines *lines, char *p) {
static bool ConsumeFileOverview(struct Lines *lines) {
int i;
if (lines->n && lines->p[0].n >= strlen(FILEOVERVIEW) &&
startswith(lines->p[0].p, FILEOVERVIEW)) {
_startswith(lines->p[0].p, FILEOVERVIEW)) {
lines->p[0].p += strlen(FILEOVERVIEW);
lines->p[0].n -= strlen(FILEOVERVIEW);
while (lines->p[0].n &&

View file

@ -18,10 +18,10 @@
*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/iovec.h"
#include "libc/intrin/bsr.h"
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/sock/sock.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/o.h"
@ -76,9 +76,9 @@ void PersistObject(const char *path, size_t align,
CHECK(IsWithin(sizeof(*obj->abi), obj->abi, obj->size, obj->p));
for (n = i = 0; obj->arrays[i].size; ++i) ++n;
iovlen = (n + 1) * 2;
pad = gc(xcalloc(align, 1));
hdr = gc(xmalloc(obj->size));
iov = gc(xcalloc(iovlen, sizeof(*iov)));
pad = _gc(xcalloc(align, 1));
hdr = _gc(xmalloc(obj->size));
iov = _gc(xcalloc(iovlen, sizeof(*iov)));
bytes = obj->size;
iov[0].iov_base = memcpy(hdr, obj->p, obj->size);
iov[0].iov_len = bytes;
@ -94,7 +94,7 @@ void PersistObject(const char *path, size_t align,
p2 = obj->arrays[i].pp;
arrayptroffset = p2 - p1;
arraydataoffset = filesize;
CHECK((!len || bsrl(len) + bsrl(size) < 31),
CHECK((!len || _bsrl(len) + _bsrl(size) < 31),
"path=%s i=%d len=%,lu size=%,lu", path, i, len, size);
CHECK(IsWithin(sizeof(void *), pp, obj->size, obj->p));
CHECK(!IsOverlapping(pp, pp + sizeof(void *), obj->magic,

View file

@ -20,10 +20,12 @@
#include "libc/calls/struct/stat.h"
#include "libc/log/check.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/o.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "tool/build/lib/psk.h"
/**
@ -33,7 +35,7 @@ void *GetRunitPsk(void) {
int fd;
char *r, *p;
struct stat st;
p = gc(xasprintf("%s/.runit.psk", gc(xhomedir())));
p = _gc(xasprintf("%s/.runit.psk", _gc(xhomedir())));
if (stat(p, &st) == -1 || st.st_size != 32) {
fprintf(stderr, "need o//examples/getrandom.com -bn32 >~/.runit.psk\n");
exit(1);

View file

@ -19,12 +19,12 @@
#include "libc/fmt/itoa.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/intrin/tpenc.h"
#include "libc/log/check.h"
#include "libc/mem/arraylist2.internal.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "libc/str/thompike.h"
#include "libc/str/tpenc.h"
#include "libc/str/unicode.h"
#include "libc/sysv/errfuns.h"
#include "libc/x/x.h"
@ -1356,7 +1356,7 @@ int PtyAppendLine(struct Pty *pty, struct Buffer *buf, unsigned y) {
u = wc;
w = 1;
} else {
u = tpenc(wc);
u = _tpenc(wc);
w = max(1, wcwidth(wc));
}
} else {
@ -1367,7 +1367,7 @@ int PtyAppendLine(struct Pty *pty, struct Buffer *buf, unsigned y) {
if (u != ' ') {
np ^= kPtyFlip;
} else {
u = tpenc(u'');
u = _tpenc(u'');
if (pty->conf & kPtyBlinkcursor) {
np |= kPtyBlink;
}

View file

@ -42,7 +42,7 @@
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/vendor.internal.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/pc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/select.h"

View file

@ -19,7 +19,7 @@
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/nexgen32e/vendor.internal.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "tool/build/lib/address.h"

View file

@ -26,7 +26,7 @@
#include "libc/nexgen32e/kompressor.h"
#include "libc/nexgen32e/lz4.h"
#include "libc/runtime/ezmap.internal.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -33,14 +33,14 @@
#include "libc/mem/arraylist.internal.h"
#include "libc/mem/arraylist2.internal.h"
#include "libc/mem/bisectcarleft.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/runtime/ezmap.internal.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/stack.h"
#include "libc/runtime/sysconf.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/clone.h"
@ -166,8 +166,8 @@ void Crunch(void) {
free(sources.p);
sources.p = 0;
sources.i = j;
longsort((const long *)sauces, sources.i);
longsort((const long *)edges.p, edges.i);
_longsort((const long *)sauces, sources.i);
_longsort((const long *)edges.p, edges.i);
}
void Rehash(void) {
@ -221,7 +221,7 @@ unsigned GetSourceId(const char *name, size_t len) {
bool ShouldSkipSource(const char *src) {
unsigned j;
for (j = 0; j < ARRAYLEN(kIgnorePrefixes); ++j) {
if (startswith(src, kIgnorePrefixes[j])) {
if (_startswith(src, kIgnorePrefixes[j])) {
return true;
}
}
@ -345,7 +345,7 @@ const char *StripExt(char pathbuf[PATH_MAX], const char *s) {
bool IsObjectSource(const char *name) {
int i;
for (i = 0; i < ARRAYLEN(kSourceExts); ++i) {
if (endswith(name, kSourceExts[i])) return true;
if (_endswith(name, kSourceExts[i])) return true;
}
return false;
}
@ -390,7 +390,7 @@ int Diver(void *arg, int tid) {
path = strings.p + sauces[i].name;
if (!IsObjectSource(path)) continue;
appendw(&bout, '\n');
if (!startswith(path, "o/")) {
if (!_startswith(path, "o/")) {
appends(&bout, buildroot);
}
appends(&bout, StripExt(pathbuf, path));

View file

@ -12,7 +12,6 @@
#include "libc/fmt/conv.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/x/x.h"
@ -73,7 +72,7 @@ int main(int argc, char *argv[]) {
fputs(": cannot create directory '", stderr);
fputs(argv[i], stderr);
fputs("' ", stderr);
fputs(strerdoc(errno), stderr);
fputs(_strerdoc(errno), stderr);
fputc('\n', stderr);
exit(1);
}

View file

@ -21,10 +21,9 @@
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/fmt/fmt.h"
#include "libc/runtime/gc.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/ex.h"
@ -117,7 +116,7 @@ int Visit(const char *fpath, const struct stat *sb, int tflag,
strcpy(srcfile, fpath);
src = srcfile + striplen;
strcpy(dstfile, dstdir);
if (!endswith(dstfile, "/")) {
if (!_endswith(dstfile, "/")) {
strcat(dstfile, "/");
}
strcat(dstfile, src);
@ -177,7 +176,7 @@ void Mv(char *src, char *dst) {
if (nftw(src, Visit, 20, 0) == -1) {
fputs(prog, stderr);
fputs(": nftw failed: ", stderr);
fputs(strerdoc(errno), stderr);
fputs(_strerdoc(errno), stderr);
fputs("\n", stderr);
exit(1);
}
@ -198,7 +197,7 @@ void Mv(char *src, char *dst) {
}
return;
OnFail:
s = strerdoc(errno);
s = _strerdoc(errno);
fputs(prog, stderr);
fputs(": ", stderr);
fputs(src, stderr);

View file

@ -17,11 +17,10 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/copyfd.internal.h"
#include "libc/errno.h"
#include "libc/fmt/itoa.h"
#include "libc/mem/io.h"
#include "libc/runtime/runtime.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/o.h"
@ -44,7 +43,7 @@ wontreturn void SysExit(int rc, const char *call, const char *thing) {
const char *estr;
err = errno;
FormatInt32(ibuf, err);
estr = strerdoc(err);
estr = _strerdoc(err);
if (!estr) estr = "EUNKNOWN";
Write(thing, ": ", call, "() failed: ", estr, " (", ibuf, ")\n", 0);
exit(rc);

View file

@ -228,21 +228,21 @@ void IndexSections(struct Object *obj) {
CHECK_NOTNULL((shdr = GetElfSectionHeaderAddress(obj->elf, obj->size, i)));
if (shdr->sh_type != SHT_NULL) {
CHECK_NOTNULL((name = GetElfSectionName(obj->elf, obj->size, shdr)));
if (startswith(name, ".sort.")) name += 5;
if (_startswith(name, ".sort.")) name += 5;
if ((strcmp(name, ".piro.relo") == 0 ||
startswith(name, ".piro.relo.")) ||
_startswith(name, ".piro.relo.")) ||
(strcmp(name, ".data.rel.ro") == 0 ||
startswith(name, ".data.rel.ro."))) {
_startswith(name, ".data.rel.ro."))) {
sect.kind = kPiroRelo;
} else if (strcmp(name, ".piro.data") == 0 ||
startswith(name, ".piro.data.")) {
_startswith(name, ".piro.data.")) {
sect.kind = kPiroData;
} else if (strcmp(name, ".piro.bss") == 0 ||
startswith(name, ".piro.bss.")) {
_startswith(name, ".piro.bss.")) {
sect.kind = kPiroBss;
} else if (strcmp(name, ".data") == 0 || startswith(name, ".data.")) {
} else if (strcmp(name, ".data") == 0 || _startswith(name, ".data.")) {
sect.kind = kData;
} else if (strcmp(name, ".bss") == 0 || startswith(name, ".bss.")) {
} else if (strcmp(name, ".bss") == 0 || _startswith(name, ".bss.")) {
sect.kind = kBss;
} else {
sect.kind = kText;

View file

@ -39,10 +39,10 @@
#include "libc/intrin/safemacros.internal.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/io.h"
#include "libc/calls/copyfd.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/kcpuids.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/sysconf.h"
#include "libc/sock/sock.h"

View file

@ -24,8 +24,8 @@
#include "libc/intrin/bits.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
@ -35,7 +35,8 @@
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/sa.h"
#include "libc/sysv/consts/sig.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "libc/x/xgetline.h"
#include "third_party/dlmalloc/dlmalloc.h"
#include "third_party/getopt/getopt.h"
@ -635,7 +636,7 @@ static void Parse(struct Trace *t, const char *line, long lineno) {
CHECK_EQ('.', *p++, DEBUG);
us = strtol(p, &p, 10);
CHECK_EQ(' ', *p++, DEBUG);
if (startswith(p, "<... ")) {
if (_startswith(p, "<... ")) {
CHECK_NOTNULL((p = strchr(p, '>')));
++p;
for (event = t->events.n; event--;) {
@ -655,18 +656,18 @@ static void Parse(struct Trace *t, const char *line, long lineno) {
t->events.p[event].sec = sec;
t->events.p[event].us = us;
t->events.p[event].lineno = lineno;
if (startswith(p, "+++ exited with ")) {
if (_startswith(p, "+++ exited with ")) {
p += strlen("+++ exited with ");
t->events.p[event].kind = EK_EXIT;
t->events.p[event].ret = atoi(p);
return;
} else if (startswith(p, "+++ killed by ")) {
} else if (_startswith(p, "+++ killed by ")) {
p += strlen("+++ killed by ");
CHECK((q = strchr(p, ' ')), DEBUG);
t->events.p[event].kind = EK_KILLED;
t->events.p[event].ret = GetSignal(p, q - p);
return;
} else if (startswith(p, "--- ")) {
} else if (_startswith(p, "--- ")) {
p += 4;
CHECK(isalpha(*p), DEBUG);
CHECK((q = strchr(p, ' ')), DEBUG);
@ -683,7 +684,7 @@ static void Parse(struct Trace *t, const char *line, long lineno) {
if (*p == ',') ++p;
while (*p == ' ') ++p;
CHECK(*p, DEBUG);
if (startswith(p, "<unfinished ...>")) {
if (_startswith(p, "<unfinished ...>")) {
t->events.p[event].is_interrupted = true;
break;
} else if (*p == ')') {
@ -703,7 +704,7 @@ static void Parse(struct Trace *t, const char *line, long lineno) {
break;
}
CHECK_LT((arg = t->events.p[event].arity++), 6);
if (isalpha(*p) && !startswith(p, "NULL")) {
if (isalpha(*p) && !_startswith(p, "NULL")) {
bzero(&b, sizeof(b));
for (; isalpha(*p) || *p == '_'; ++p) {
AppendSlice(&b, *p);
@ -713,7 +714,7 @@ static void Parse(struct Trace *t, const char *line, long lineno) {
} else {
t->events.p[event].arg[arg].name = -1;
}
if (startswith(p, "NULL")) {
if (_startswith(p, "NULL")) {
p += 4;
t->events.p[event].arg[arg].kind = AK_LONG;
t->events.p[event].arg[arg].x = 0;

View file

@ -16,15 +16,15 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/alg.h"
#include "libc/assert.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/dirent.h"
#include "libc/calls/struct/stat.h"
#include "libc/fmt/fmt.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/log/check.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/alg.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/dt.h"
@ -115,7 +115,7 @@ void RefactorDir(const char *dpath) {
char *path = gc(xmalloc(4096));
CHECK_NOTNULL(dir = opendir(firstnonnull(dpath, ".")));
while ((ent = readdir(dir))) {
if (startswith(ent->d_name, ".")) continue;
if (_startswith(ent->d_name, ".")) continue;
if (strcmp(ent->d_name, "o") == 0) continue;
snprintf(path, 4096, "%s%s%s", dpath ? dpath : "", dpath ? "/" : "",
ent->d_name);

View file

@ -20,7 +20,6 @@
#include "libc/errno.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"
@ -74,7 +73,7 @@ void Remove(const char *path) {
return;
OnFail:
if (force && errno == ENOENT) return;
s = strerdoc(errno);
s = _strerdoc(errno);
fputs(prog, stderr);
fputs(": cannot remove '", stderr);
fputs(path, stderr);

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "ape/relocations.h"
#include "libc/mem/arraylist2.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/errno.h"
@ -25,9 +24,10 @@
#include "libc/intrin/kprintf.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/mem/arraylist2.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/map.h"
@ -97,13 +97,13 @@ void Visit(const char *path) {
char *map;
size_t size;
bool isheader;
if (!endswith(path, ".h") && !endswith(path, ".inc")) return;
if (endswith(path, ".internal.h")) return;
if (endswith(path, "/internal.h")) return;
if (endswith(path, ".internal.inc")) return;
if (endswith(path, "/internal.inc")) return;
if (startswith(path, "libc/isystem/")) return;
isheader = endswith(path, ".h");
if (!_endswith(path, ".h") && !_endswith(path, ".inc")) return;
if (_endswith(path, ".internal.h")) return;
if (_endswith(path, "/internal.h")) return;
if (_endswith(path, ".internal.inc")) return;
if (_endswith(path, "/internal.inc")) return;
if (_startswith(path, "libc/isystem/")) return;
isheader = _endswith(path, ".h");
if (isheader && isinterned(visited, path)) return;
appends(&output, "\n\f\n/*!BEGIN ");
appends(&output, path);

View file

@ -19,17 +19,19 @@
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/itimerval.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/stat.h"
#include "libc/dns/dns.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/limits.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/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/ipclassify.internal.h"
#include "libc/stdio/stdio.h"
@ -42,9 +44,11 @@
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/sysv/consts/sig.h"
#include "libc/sysv/consts/sock.h"
#include "libc/time/time.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "net/https/https.h"
#include "third_party/mbedtls/ssl.h"
#include "third_party/zlib/zlib.h"
@ -142,7 +146,7 @@ void Connect(void) {
int rc, err, expo;
long double t1, t2;
struct addrinfo *ai;
if ((rc = getaddrinfo(g_hostname, gc(xasprintf("%hu", g_runitdport)),
if ((rc = getaddrinfo(g_hostname, _gc(xasprintf("%hu", g_runitdport)),
&kResolvHints, &ai)) != 0) {
FATALF("%s:%hu: EAI_%s %m", g_hostname, g_runitdport, gai_strerror(rc));
unreachable;
@ -199,7 +203,7 @@ bool Send(int tmpfd, const void *output, size_t outputsize) {
static bool once;
static z_stream zs;
zsize = 32768;
zbuf = gc(malloc(zsize));
zbuf = _gc(malloc(zsize));
if (!once) {
CHECK_EQ(Z_OK, deflateInit2(&zs, 4, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
Z_DEFAULT_STRATEGY));
@ -241,7 +245,7 @@ bool SendRequest(int tmpfd) {
CHECK_NE(MAP_FAILED, (p = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0)));
CHECK_LE((namesize = strlen((name = basename(g_prog)))), PATH_MAX);
CHECK_LE((progsize = st.st_size), INT_MAX);
CHECK_NOTNULL((hdr = gc(calloc(1, (hdrsize = 17 + namesize)))));
CHECK_NOTNULL((hdr = _gc(calloc(1, (hdrsize = 17 + namesize)))));
crc = crc32_z(0, p, st.st_size);
q = hdr;
q = WRITE32BE(q, RUNITD_MAGIC);
@ -261,7 +265,7 @@ bool SendRequest(int tmpfd) {
void RelayRequest(void) {
int i, rc, have, transferred;
char *buf = gc(malloc(PIPE_BUF));
char *buf = _gc(malloc(PIPE_BUF));
for (transferred = 0;;) {
rc = read(13, buf, PIPE_BUF);
CHECK_NE(-1, rc);
@ -381,7 +385,7 @@ int SpawnSubprocesses(int argc, char *argv[]) {
// create compressed network request ahead of time
CHECK_NE(-1, (tmpfd = open(
(tpath = gc(xasprintf(
(tpath = _gc(xasprintf(
"%s/runit.%d", firstnonnull(getenv("TMPDIR"), "/tmp"),
getpid()))),
O_WRONLY | O_CREAT | O_TRUNC, 0755)));

View file

@ -16,18 +16,19 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bits.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/struct/timeval.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/bits.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/sock.h"
#include "libc/sock/struct/pollfd.h"
@ -52,6 +53,7 @@
#include "libc/sysv/consts/w.h"
#include "libc/time/time.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "net/https/https.h"
#include "third_party/getopt/getopt.h"
#include "third_party/mbedtls/ssl.h"
@ -220,7 +222,7 @@ void StartTcpServer(void) {
CHECK_NE(-1, listen(g_servfd, 10));
asize = sizeof(g_servaddr);
CHECK_NE(-1, getsockname(g_servfd, &g_servaddr, &asize));
INFOF("%s:%s", "listening on tcp", gc(DescribeAddress(&g_servaddr)));
INFOF("%s:%s", "listening on tcp", _gc(DescribeAddress(&g_servaddr)));
if (g_sendready) {
printf("ready %hu\n", ntohs(g_servaddr.sin_port));
fflush(stdout);
@ -382,8 +384,8 @@ void HandleClient(void) {
EzFd(g_clifd);
INFOF("EzHandshake");
EzHandshake();
addrstr = gc(DescribeAddress(&addr));
DEBUGF("%s %s %s", gc(DescribeAddress(&g_servaddr)), "accepted", addrstr);
addrstr = _gc(DescribeAddress(&addr));
DEBUGF("%s %s %s", _gc(DescribeAddress(&g_servaddr)), "accepted", addrstr);
Recv(msg, sizeof(msg));
CHECK_EQ(RUNITD_MAGIC, READ32BE(msg));
@ -391,9 +393,9 @@ void HandleClient(void) {
namesize = READ32BE(msg + 5);
filesize = READ32BE(msg + 9);
crc = READ32BE(msg + 13);
exename = gc(calloc(1, namesize + 1));
exename = _gc(calloc(1, namesize + 1));
Recv(exename, namesize);
g_exepath = gc(xasprintf("o/%d.%s", getpid(), basename(exename)));
g_exepath = _gc(xasprintf("o/%d.%s", getpid(), basename(exename)));
INFOF("%s asked we run %`'s (%,u bytes @ %`'s)", addrstr, exename, filesize,
g_exepath);
@ -567,7 +569,6 @@ int main(int argc, char *argv[]) {
} else {
CHECK_EQ(3, (g_bogusfd = open("/dev/zero", O_RDONLY | O_CLOEXEC)));
}
defer(close_s, &g_bogusfd);
if (!isdirectory("o")) CHECK_NE(-1, mkdir("o", 0700));
if (g_daemonize) Daemonize();
return Serve();

View file

@ -35,8 +35,7 @@
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/append.internal.h"
#include "libc/str/errfun.h"
#include "libc/stdio/append.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/nr.h"
#include "libc/sysv/consts/ptrace.h"
@ -660,7 +659,7 @@ static void Flush(void) {
static const char *GetErrnoName(int x) {
const char *s;
static char buf[16];
if ((s = strerrno(x))) return s;
if ((s = _strerrno(x))) return s;
FormatInt64(buf, x);
return buf;
}

View file

@ -20,7 +20,6 @@
#include "libc/errno.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
/**
@ -33,7 +32,7 @@ int main(int argc, char *argv[]) {
prog = argc > 0 ? argv[0] : "touch.com";
for (i = 1; i < argc; ++i) {
if (touch(argv[i], 0666) == -1) {
s = strerdoc(errno);
s = _strerdoc(errno);
fputs(prog, stderr);
fputs(": cannot touch '", stderr);
fputs(argv[i], stderr);

View file

@ -22,9 +22,11 @@
#include "libc/calls/struct/winsize.h"
#include "libc/calls/termios.h"
#include "libc/calls/ttydefaults.h"
#include "libc/errno.h"
#include "libc/intrin/kprintf.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/sig.h"
#include "libc/sysv/consts/termios.h"

View file

@ -23,7 +23,6 @@
#include "libc/fmt/itoa.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/errfun.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/s.h"
#include "libc/x/x.h"
@ -59,12 +58,12 @@ void Execute(char *argv[]) {
int Visit(const char *fpath, const struct stat *sb, int tflag,
struct FTW *ftwbuf) {
if (tflag == FTW_F && endswith(fpath, ".gz")) {
if (tflag == FTW_F && _endswith(fpath, ".gz")) {
Execute((char *[]){"build/bootstrap/gzip.com", "-d", fpath, 0});
strcpy(binpath, fpath);
binpath[strlen(binpath) - 3] = 0;
chmod(binpath, 0755);
} else if (tflag == FTW_F && endswith(fpath, ".sym")) {
} else if (tflag == FTW_F && _endswith(fpath, ".sym")) {
strcpy(binpath, fpath);
binpath[strlen(binpath) - 4] = 0;
symlink(xslurp(fpath, 0), binpath);
@ -83,7 +82,7 @@ int main(int argc, char *argv[]) {
if (nftw(tmpdir, Visit, 20, 0) == -1) {
fputs(prog, stderr);
fputs(": nftw failed: ", stderr);
fputs(strerdoc(errno), stderr);
fputs(_strerdoc(errno), stderr);
fputs("\n", stderr);
exit(1);
}

View file

@ -22,11 +22,11 @@
#include "libc/log/check.h"
#include "libc/math.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
/**
* @fileoverview Tool for generating rldecode'd character sets, e.g.
@ -216,7 +216,7 @@ int main(int argc, char *argv[]) {
for (i = 0; i < argc; ++i) {
if (i) printf(" ");
printf("%s", !ArgNeedsShellQuotes(argv[i]) ? argv[i]
: gc(AddShellQuotes(argv[i])));
: _gc(AddShellQuotes(argv[i])));
}
printf("\n");
@ -276,7 +276,7 @@ int main(int argc, char *argv[]) {
} else {
if (runcount) {
printf("\t.byte\t%-24s# %02x-%02x %hc-%hc\n",
gc(xasprintf("%3d,%d", runcount, runchar)), runstart,
_gc(xasprintf("%3d,%d", runcount, runchar)), runstart,
runstart + runcount - 1, Bing(runstart),
Bing(runstart + runcount - 1));
thetally += 2;

View file

@ -24,7 +24,7 @@
#include "libc/limits.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/clock.h"
@ -138,7 +138,7 @@ void ProcessFile(struct ElfWriter *elf, const char *path) {
}
if (S_ISDIR(st.st_mode)) {
st.st_size = 0;
if (!endswith(name, "/")) {
if (!_endswith(name, "/")) {
name = gc(xstrcat(name, '/'));
}
}
@ -160,7 +160,7 @@ void PullEndOfCentralDirectoryIntoLinkage(struct ElfWriter *elf) {
void CheckFilenameKosher(const char *path) {
CHECK_LE(kZipCfileHdrMinSize + strlen(path),
kZipCdirHdrLinkableSizeBootstrap);
CHECK(!startswith(path, "/"));
CHECK(!_startswith(path, "/"));
CHECK(!strstr(path, ".."));
}

View file

@ -16,8 +16,6 @@
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/elf/def.h"
@ -26,6 +24,8 @@
#include "libc/elf/struct/shdr.h"
#include "libc/errno.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/macros.internal.h"
@ -36,7 +36,7 @@
#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 "tool/decode/lib/asmcodegen.h"
#include "tool/decode/lib/elfidnames.h"
#include "tool/decode/lib/flagger.h"

View file

@ -19,7 +19,7 @@
#include "libc/fmt/fmt.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "tool/decode/lib/asmcodegen.h"

View file

@ -24,12 +24,12 @@
#include "libc/nt/struct/imagedosheader.internal.h"
#include "libc/nt/struct/imagentheaders.internal.h"
#include "libc/nt/struct/imageoptionalheader.internal.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/stdio/stdio.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 "third_party/xed/x86.h"
#include "tool/decode/lib/asmcodegen.h"
#include "tool/decode/lib/flagger.h"
@ -181,7 +181,7 @@ static void showpeoptionalheader(struct NtImageOptionalHeader *opt) {
show(".long", \
format(b1, "%#X,%u", opt->DataDirectory[x].VirtualAddress, \
opt->DataDirectory[x].Size), \
gc(xasprintf("opt->DataDirectory[%s]", #x))); \
_gc(xasprintf("opt->DataDirectory[%s]", #x))); \
} \
} while (0)
@ -212,7 +212,7 @@ static void ShowIlt(int64_t *ilt) {
do {
printf("\n");
show(".quad", format(b1, "%#lx", *ilt),
gc(xasprintf("@%#lx", (intptr_t)ilt - (intptr_t)mz)));
_gc(xasprintf("@%#lx", (intptr_t)ilt - (intptr_t)mz)));
if (*ilt) {
char *hint = (char *)((intptr_t)mz + *ilt);
printf("/\t.short\t%d\t\t\t# @%#lx\n", READ16LE(hint),
@ -231,13 +231,13 @@ static void ShowIat(char *iat, size_t size) {
for (p = iat, e = iat + size; p + 20 <= e; p += 20) {
printf("\n");
show(".long", format(b1, "%#x", READ32LE(p)),
gc(xasprintf("ImportLookupTable RVA @%#lx",
(intptr_t)p - (intptr_t)mz)));
_gc(xasprintf("ImportLookupTable RVA @%#lx",
(intptr_t)p - (intptr_t)mz)));
show(".long", format(b1, "%#x", READ32LE(p + 4)), "TimeDateStamp");
show(".long", format(b1, "%#x", READ32LE(p + 8)), "ForwarderChain");
show(".long", format(b1, "%#x", READ32LE(p + 12)),
READ32LE(p + 12)
? gc(xasprintf("DllName RVA (%s)", (char *)mz + READ32LE(p + 12)))
? _gc(xasprintf("DllName RVA (%s)", (char *)mz + READ32LE(p + 12)))
: "DllName RVA");
show(".long", format(b1, "%#x", READ32LE(p + 16)),
"ImportAddressTable RVA");

View file

@ -73,11 +73,13 @@
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/str/strwidth.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "libc/x/xgetline.h"
#define IsSpace(C) ((C) == ' ')
#define IsPipe(C) ((C) == '|' || (C) == u'│')
@ -162,14 +164,14 @@ int main(int argc, char *argv[]) {
}
xn += 1000;
L = xmalloc((yn + 2) * sizeof(*L));
L[0] = utf8to16(gc(xasprintf(" %*s ", xn, " ")), -1, 0);
L[0] = utf8to16(_gc(xasprintf(" %*s ", xn, " ")), -1, 0);
for (y = 0; y < yn; ++y) {
s = xasprintf(" %s%*s ", T[y], xn - n, " ");
L[y + 1] = utf8to16(s, -1, 0);
free(T[y]);
free(s);
}
L[yn + 2 - 1] = utf8to16(gc(xasprintf(" %*s ", xn, " ")), -1, 0);
L[yn + 2 - 1] = utf8to16(_gc(xasprintf(" %*s ", xn, " ")), -1, 0);
free(T);
V = xcalloc((yn + 1) * (xn + 1), 1);
for (y = 1; y <= yn; ++y) {

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/math.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/x/x.h"

View file

@ -5,7 +5,7 @@
http://unlicense.org/ │
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/x/x.h"

View file

@ -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;
}

View file

@ -16,19 +16,20 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#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/safemacros.internal.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.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"
@ -65,9 +66,9 @@ void ShowCompressionMethod(uint16_t compressmethod) {
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 ShowNtfs(uint8_t *ntfs, size_t n) {
@ -75,18 +76,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) {
@ -94,28 +96,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;
}
@ -125,19 +127,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");
}
}
@ -145,9 +147,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);
}
@ -187,11 +189,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);
@ -209,18 +211,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 {
@ -241,7 +243,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);

View file

@ -64,7 +64,7 @@ static int LuaFetch(lua_State *L) {
return LuaNilError(L, "invalid header name: %s", key);
val = lua_tolstring(L, -1, &vallen);
if (!(hdr = gc(EncodeHttpHeaderValue(val, vallen, 0))))
if (!(hdr = _gc(EncodeHttpHeaderValue(val, vallen, 0))))
return LuaNilError(L, "invalid header %s value encoding", key);
// Content-Length and Connection will be overwritten;
@ -101,14 +101,14 @@ static int LuaFetch(lua_State *L) {
if (bodylen > 0 || !(methodidx == kHttpGet || methodidx == kHttpHead ||
methodidx == kHttpTrace || methodidx == kHttpDelete ||
methodidx == kHttpConnect)) {
conlenhdr = gc(xasprintf("Content-Length: %zu\r\n", bodylen));
conlenhdr = _gc(xasprintf("Content-Length: %zu\r\n", bodylen));
}
/*
* Parse URL.
*/
gc(ParseUrl(urlarg, urlarglen, &url));
gc(url.params.p);
_gc(ParseUrl(urlarg, urlarglen, &url));
_gc(url.params.p);
usingssl = false;
if (url.scheme.n) {
#ifndef UNSECURE
@ -127,9 +127,9 @@ static int LuaFetch(lua_State *L) {
#endif
if (url.host.n) {
host = gc(strndup(url.host.p, url.host.n));
host = _gc(strndup(url.host.p, url.host.n));
if (url.port.n) {
port = gc(strndup(url.port.p, url.port.n));
port = _gc(strndup(url.port.p, url.port.n));
#ifndef UNSECURE
} else if (usingssl) {
port = "443";
@ -146,7 +146,7 @@ static int LuaFetch(lua_State *L) {
if (!IsAcceptableHost(host, -1)) {
return LuaNilError(L, "invalid host");
}
if (!hosthdr) hosthdr = gc(xasprintf("%s:%s", host, port));
if (!hosthdr) hosthdr = _gc(xasprintf("%s:%s", host, port));
url.fragment.p = 0, url.fragment.n = 0;
url.scheme.p = 0, url.scheme.n = 0;
@ -155,7 +155,7 @@ static int LuaFetch(lua_State *L) {
url.host.p = 0, url.host.n = 0;
url.port.p = 0, url.port.n = 0;
if (!url.path.n || url.path.p[0] != '/') {
p = gc(xmalloc(1 + url.path.n));
p = _gc(xmalloc(1 + url.path.n));
mempcpy(mempcpy(p, "/", 1), url.path.p, url.path.n);
url.path.p = p;
++url.path.n;
@ -164,14 +164,14 @@ static int LuaFetch(lua_State *L) {
/*
* Create HTTP message.
*/
request = gc(xasprintf("%s %s HTTP/1.1\r\n"
"Host: %s\r\n"
"Connection: close\r\n"
"User-Agent: %s\r\n"
"%s%s"
"\r\n%s",
method, gc(EncodeUrl(&url, 0)), hosthdr, agenthdr,
conlenhdr, headers ? headers : "", body));
request = _gc(xasprintf("%s %s HTTP/1.1\r\n"
"Host: %s\r\n"
"Connection: close\r\n"
"User-Agent: %s\r\n"
"%s%s"
"\r\n%s",
method, _gc(EncodeUrl(&url, 0)), hosthdr, agenthdr,
conlenhdr, headers ? headers : "", body));
requestlen = strlen(request);
/*
@ -211,7 +211,7 @@ static int LuaFetch(lua_State *L) {
if (!evadedragnetsurveillance) {
mbedtls_ssl_set_hostname(&sslcli, host);
}
bio = gc(malloc(sizeof(struct TlsBio)));
bio = _gc(malloc(sizeof(struct TlsBio)));
bio->fd = sock;
bio->a = 0;
bio->b = 0;
@ -443,7 +443,7 @@ VerifyFailed:
LockInc(&shared->c.sslverifyfailed);
close(sock);
return LuaNilTlsError(
L, gc(DescribeSslVerifyFailure(sslcli.session_negotiate->verify_result)),
L, _gc(DescribeSslVerifyFailure(sslcli.session_negotiate->verify_result)),
ret);
#endif
#undef ssl

View file

@ -25,19 +25,19 @@
#include "libc/fmt/itoa.h"
#include "libc/fmt/leb128.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/bsf.h"
#include "libc/intrin/bsr.h"
#include "libc/intrin/popcnt.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/bench.h"
#include "libc/nexgen32e/bsf.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/nexgen32e/rdtsc.h"
#include "libc/nexgen32e/rdtscp.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/sysconf.h"
#include "libc/sock/sock.h"
@ -316,7 +316,7 @@ int LuaPopcnt(lua_State *L) {
int LuaBsr(lua_State *L) {
long x;
if ((x = luaL_checkinteger(L, 1))) {
lua_pushinteger(L, bsrl(x));
lua_pushinteger(L, _bsrl(x));
return 1;
} else {
luaL_argerror(L, 1, "zero");
@ -327,7 +327,7 @@ int LuaBsr(lua_State *L) {
int LuaBsf(lua_State *L) {
long x;
if ((x = luaL_checkinteger(L, 1))) {
lua_pushinteger(L, bsfl(x));
lua_pushinteger(L, _bsfl(x));
return 1;
} else {
luaL_argerror(L, 1, "zero");

View file

@ -22,7 +22,6 @@
#include "libc/log/log.h"
#include "libc/runtime/stack.h"
#include "libc/str/str.h"
#include "libc/str/tpenc.h"
#include "libc/str/utf16.h"
#include "third_party/double-conversion/wrapper.h"
#include "third_party/lua/cosmo.h"

View file

@ -35,16 +35,18 @@
#include "libc/fmt/conv.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/bsr.h"
#include "libc/intrin/likely.h"
#include "libc/intrin/nomultics.internal.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/log/appendresourcereport.internal.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/alloca.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/nexgen32e/nt2sysv.h"
#include "libc/nexgen32e/rdtsc.h"
@ -52,8 +54,6 @@
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/nt/thread.h"
#include "libc/runtime/clktck.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/memtrack.internal.h"
#include "libc/runtime/runtime.h"
@ -61,7 +61,7 @@
#include "libc/sock/goodsocket.internal.h"
#include "libc/sock/sock.h"
#include "libc/sock/struct/pollfd.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/stdio/hex.internal.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
@ -93,6 +93,7 @@
#include "libc/thread/thread.h"
#include "libc/thread/tls.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "libc/zip.h"
#include "net/http/escape.h"
#include "net/http/http.h"
@ -642,7 +643,7 @@ static void UseCertificate(mbedtls_ssl_config *c, struct Cert *kp,
const char *role) {
VERBOSEF("(ssl) using %s certificate %`'s for HTTPS %s",
mbedtls_pk_get_name(&kp->cert->pk),
gc(FormatX509Name(&kp->cert->subject)), role);
_gc(FormatX509Name(&kp->cert->subject)), role);
CHECK_EQ(0, mbedtls_ssl_conf_own_cert(c, kp->cert, kp->key));
}
@ -659,21 +660,21 @@ static void InternCertificate(mbedtls_x509_crt *cert, mbedtls_x509_crt *prev) {
if (prev) {
if (mbedtls_x509_crt_check_parent(prev, cert, 1)) {
DEBUGF("(ssl) unbundling %`'s from %`'s",
gc(FormatX509Name(&prev->subject)),
gc(FormatX509Name(&cert->subject)));
_gc(FormatX509Name(&prev->subject)),
_gc(FormatX509Name(&cert->subject)));
prev->next = 0;
} else if ((r = mbedtls_x509_crt_check_signature(prev, cert, 0))) {
WARNF("(ssl) invalid signature for %`'s -> %`'s (-0x%04x)",
gc(FormatX509Name(&prev->subject)),
gc(FormatX509Name(&cert->subject)), -r);
_gc(FormatX509Name(&prev->subject)),
_gc(FormatX509Name(&cert->subject)), -r);
}
}
if (mbedtls_x509_time_is_past(&cert->valid_to)) {
WARNF("(ssl) certificate %`'s is expired",
gc(FormatX509Name(&cert->subject)));
_gc(FormatX509Name(&cert->subject)));
} else if (mbedtls_x509_time_is_future(&cert->valid_from)) {
WARNF("(ssl) certificate %`'s is from the future",
gc(FormatX509Name(&cert->subject)));
_gc(FormatX509Name(&cert->subject)));
}
for (i = 0; i < certs.n; ++i) {
if (!certs.p[i].cert) continue;
@ -682,7 +683,7 @@ static void InternCertificate(mbedtls_x509_crt *cert, mbedtls_x509_crt *prev) {
!mbedtls_x509_name_cmp(&cert->subject, &certs.p[i].cert->subject)) {
VERBOSEF("(ssl) %s %`'s is already loaded",
mbedtls_pk_get_name(&cert->pk),
gc(FormatX509Name(&cert->subject)));
_gc(FormatX509Name(&cert->subject)));
return;
}
}
@ -951,8 +952,8 @@ static void ProgramCache(long x) {
}
static void SetDefaults(void) {
ProgramBrand(gc(xasprintf("%s/%hhd.%hhd.%hhd", REDBEAN, VERSION >> 020,
VERSION >> 010, VERSION >> 000)));
ProgramBrand(_gc(xasprintf("%s/%hhd.%hhd.%hhd", REDBEAN, VERSION >> 020,
VERSION >> 010, VERSION >> 000)));
__log_level = kLogInfo;
maxpayloadsize = 64 * 1024;
ProgramCache(-1);
@ -1078,7 +1079,7 @@ static bool LuaEvalCode(const char *code) {
}
static bool LuaEvalFile(const char *path) {
char *f = gc(xslurp(path, 0));
char *f = _gc(xslurp(path, 0));
if (!f) FATALF("(cfg) error: failed to read file %`'s", path);
return LuaEvalCode(f);
}
@ -1603,7 +1604,7 @@ static bool TlsRouteFind(mbedtls_pk_type_t type, mbedtls_ssl_context *ssl,
0, mbedtls_ssl_set_hs_own_cert(ssl, certs.p[i].cert, certs.p[i].key));
DEBUGF("(ssl) TlsRoute(%s, %`'.*s) %s %`'s", mbedtls_pk_type_name(type),
size, host, mbedtls_pk_get_name(&certs.p[i].cert->pk),
gc(FormatX509Name(&certs.p[i].cert->subject)));
_gc(FormatX509Name(&certs.p[i].cert->subject)));
return true;
}
}
@ -1618,7 +1619,7 @@ static bool TlsRouteFirst(mbedtls_pk_type_t type, mbedtls_ssl_context *ssl) {
0, mbedtls_ssl_set_hs_own_cert(ssl, certs.p[i].cert, certs.p[i].key));
DEBUGF("(ssl) TlsRoute(%s) %s %`'s", mbedtls_pk_type_name(type),
mbedtls_pk_get_name(&certs.p[i].cert->pk),
gc(FormatX509Name(&certs.p[i].cert->subject)));
_gc(FormatX509Name(&certs.p[i].cert->subject)));
return true;
}
}
@ -1683,7 +1684,7 @@ static bool TlsSetup(void) {
ssl.session->compression ? " COMPRESSED" : "",
ssl.curve ? ssl.curve->name : "uncurved");
DEBUGF("(ssl) client ciphersuite preference was %s",
gc(FormatSslClientCiphers(&ssl)));
_gc(FormatSslClientCiphers(&ssl)));
return true;
} else if (r == MBEDTLS_ERR_SSL_WANT_READ) {
LockInc(&shared->c.handshakeinterrupts);
@ -1707,12 +1708,12 @@ static bool TlsSetup(void) {
case MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN:
LockInc(&shared->c.sslnociphers);
WARNF("(ssl) %s %s %s", DescribeClient(), "sslnociphers",
gc(FormatSslClientCiphers(&ssl)));
_gc(FormatSslClientCiphers(&ssl)));
return false;
case MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE:
LockInc(&shared->c.sslcantciphers);
WARNF("(ssl) %s %s %s", DescribeClient(), "sslcantciphers",
gc(FormatSslClientCiphers(&ssl)));
_gc(FormatSslClientCiphers(&ssl)));
return false;
case MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION:
LockInc(&shared->c.sslnoversion);
@ -1731,7 +1732,7 @@ static bool TlsSetup(void) {
case MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:
LockInc(&shared->c.sslverifyfailed);
WARNF("(ssl) %s SSL %s", DescribeClient(),
gc(DescribeSslVerifyFailure(
_gc(DescribeSslVerifyFailure(
ssl.session_negotiate->verify_result)));
return false;
case MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE:
@ -1791,7 +1792,7 @@ static void ConfigureCertificate(mbedtls_x509write_cert *cw, struct Cert *ca,
san[nsan - 2].tag = MBEDTLS_X509_SAN_DNS_NAME;
san[nsan - 2].val = s;
san[nsan - 1].tag = MBEDTLS_X509_SAN_DNS_NAME;
san[nsan - 1].val = gc(xasprintf("*.%s", s));
san[nsan - 1].val = _gc(xasprintf("*.%s", s));
}
}
}
@ -1904,7 +1905,7 @@ static void LoadCertificates(void) {
if (!havecert && (!psks.n || ksk.key)) {
if ((ksk = GetKeySigningKey()).key) {
DEBUGF("(ssl) generating ssl certificates using %`'s",
gc(FormatX509Name(&ksk.cert->subject)));
_gc(FormatX509Name(&ksk.cert->subject)));
} else {
VERBOSEF("(ssl) could not find non-CA SSL certificate key pair with"
" -addext keyUsage=digitalSignature"
@ -2013,7 +2014,7 @@ static void IndexAssets(void) {
CHECK(READ32LE(zcdir) == kZipCdir64HdrMagic ||
READ32LE(zcdir) == kZipCdirHdrMagic);
n = GetZipCdirRecords(zcdir);
m = roundup2pow(MAX(1, n) * HASH_LOAD_FACTOR);
m = _roundup2pow(MAX(1, n) * HASH_LOAD_FACTOR);
p = xcalloc(m, sizeof(struct Asset));
for (cf = GetZipCdirOffset(zcdir); n--; cf += ZIP_CFILE_HDRSIZE(zbase + cf)) {
CHECK_EQ(kZipCfileHdrMagic, ZIP_CFILE_MAGIC(zbase + cf));
@ -2151,11 +2152,11 @@ static char *AppendHeader(char *p, const char *k, const char *v) {
static char *AppendContentType(char *p, const char *ct) {
p = stpcpy(p, "Content-Type: ");
p = stpcpy(p, ct);
if ((cpm.istext = startswith(ct, "text/"))) {
if ((cpm.istext = _startswith(ct, "text/"))) {
if (!strchr(ct + 5, ';')) {
p = stpcpy(p, "; charset=utf-8");
}
if (!cpm.referrerpolicy && startswith(ct + 5, "html")) {
if (!cpm.referrerpolicy && _startswith(ct + 5, "html")) {
cpm.referrerpolicy = "no-referrer-when-downgrade";
}
}
@ -2766,10 +2767,10 @@ static void LaunchBrowser(const char *path) {
}
// assign a loopback address if no server or unknown server address
if (!servers.n || !addr.s_addr) addr.s_addr = htonl(INADDR_LOOPBACK);
if (*path != '/') path = gc(xasprintf("/%s", path));
if ((prog = commandv(GetSystemUrlLauncherCommand(), gc(malloc(PATH_MAX)),
if (*path != '/') path = _gc(xasprintf("/%s", path));
if ((prog = commandv(GetSystemUrlLauncherCommand(), _gc(malloc(PATH_MAX)),
PATH_MAX))) {
u = gc(xasprintf("http://%s:%d%s", inet_ntoa(addr), port, path));
u = _gc(xasprintf("http://%s:%d%s", inet_ntoa(addr), port, path));
DEBUGF("(srvr) opening browser with command %`'s %s", prog, u);
ignore.sa_flags = 0;
ignore.sa_handler = SIG_IGN;
@ -2815,7 +2816,7 @@ static int GetDecimalWidth(long x) {
}
static int GetOctalWidth(int x) {
return !x ? 1 : x < 8 ? 2 : 1 + bsr(x) / 3;
return !x ? 1 : x < 8 ? 2 : 1 + _bsr(x) / 3;
}
static const char *DescribeCompressionRatio(char rb[8], uint8_t *zcf) {
@ -3405,7 +3406,7 @@ static int LuaGetSslIdentity(lua_State *L) {
psks.p[sslpskindex - 1].identity_len);
} else {
cert = mbedtls_ssl_get_peer_cert(&ssl);
lua_pushstring(L, cert ? gc(FormatX509Name(&cert->subject)) : "");
lua_pushstring(L, cert ? _gc(FormatX509Name(&cert->subject)) : "");
}
}
return 1;
@ -3654,7 +3655,7 @@ static void StoreFile(char *path) {
size_t plen, tlen;
struct stat st;
char *target = path;
if (startswith(target, "./")) target += 2;
if (_startswith(target, "./")) target += 2;
tlen = strlen(target);
if (!IsReasonablePath(target, tlen))
FATALF("(cfg) error: can't store %`'s: contains '.' or '..' segments",
@ -3670,13 +3671,13 @@ static void StorePath(const char *dirpath) {
DIR *d;
char *path;
struct dirent *e;
if (!isdirectory(dirpath) && !endswith(dirpath, "/"))
if (!isdirectory(dirpath) && !_endswith(dirpath, "/"))
return StoreFile(dirpath);
if (!(d = opendir(dirpath))) FATALF("(cfg) error: can't open %`'s", dirpath);
while ((e = readdir(d))) {
if (strcmp(e->d_name, ".") == 0) continue;
if (strcmp(e->d_name, "..") == 0) continue;
path = gc(xjoinpaths(dirpath, e->d_name));
path = _gc(xjoinpaths(dirpath, e->d_name));
if (e->d_type == DT_DIR) {
StorePath(path);
} else {
@ -3748,7 +3749,7 @@ static int LuaNilError(lua_State *L, const char *fmt, ...) {
static int LuaNilTlsError(lua_State *L, const char *s, int r) {
return LuaNilError(L, "tls %s failed (%s %s)", s,
IsTiny() ? "grep" : GetTlsError(r),
gc(xasprintf("-0x%04x", -r)));
_gc(xasprintf("-0x%04x", -r)));
}
#include "tool/net/fetch.inc"
@ -3815,7 +3816,7 @@ static int LuaLog(lua_State *L) {
module = ar.short_src;
line = ar.currentline;
} else {
module = gc(strndup(effectivepath.p, effectivepath.n));
module = _gc(strndup(effectivepath.p, effectivepath.n));
line = -1;
}
flogf(level, module, line, NULL, "%s", msg);
@ -4117,7 +4118,7 @@ static int LuaSetHeader(lua_State *L) {
static int LuaGetCookie(lua_State *L) {
char *cookie = 0, *cookietmpl, *cookieval;
OnlyCallDuringRequest(L, "GetCookie");
cookietmpl = gc(xasprintf(" %s=", luaL_checkstring(L, 1)));
cookietmpl = _gc(xasprintf(" %s=", luaL_checkstring(L, 1)));
if (HasHeader(kHttpCookie)) {
appends(&cookie, " "); // prepend space to simplify cookie search
appendd(&cookie, HeaderData(kHttpCookie), HeaderLength(kHttpCookie));
@ -4162,7 +4163,7 @@ static int LuaSetCookie(lua_State *L) {
if ((ishostpref || issecurepref) && !usingssl) {
luaL_argerror(
L, 1,
gc(xasprintf("%s and %s prefixes require SSL", hostpref, securepref)));
_gc(xasprintf("%s and %s prefixes require SSL", hostpref, securepref)));
unreachable;
}
@ -4474,7 +4475,7 @@ static int LuaProgramCertificate(lua_State *L) {
static int LuaProgramHeader(lua_State *L) {
ProgramHeader(
gc(xasprintf("%s: %s", luaL_checkstring(L, 1), luaL_checkstring(L, 2))));
_gc(xasprintf("%s: %s", luaL_checkstring(L, 1), luaL_checkstring(L, 2))));
return 0;
}
@ -4554,7 +4555,7 @@ static int LuaGetZipPaths(lua_State *L) {
zcf += ZIP_CFILE_HDRSIZE(zcf)) {
CHECK_EQ(kZipCfileHdrMagic, ZIP_CFILE_MAGIC(zcf));
path = GetAssetPath(zcf, &pathlen);
if (prefixlen == 0 || startswith(path, prefix)) {
if (prefixlen == 0 || _startswith(path, prefix)) {
lua_pushlstring(L, path, pathlen);
lua_seti(L, -2, ++i);
}
@ -5844,7 +5845,7 @@ static char *ServeAsset(struct Asset *a, const char *path, size_t pathlen) {
}
} else if (!IsTiny() && cpm.msg.method != kHttpHead && !IsSslCompressed() &&
ClientAcceptsGzip() &&
((cpm.contentlength >= 100 && startswithi(ct, "text/")) ||
((cpm.contentlength >= 100 && _startswithi(ct, "text/")) ||
(cpm.contentlength >= 1000 &&
MeasureEntropy(cpm.content, 1000) < 7))) {
p = ServeAssetCompressed(a);
@ -6324,7 +6325,7 @@ static int MemoryMonitor(void *arg, int tid) {
ws.ws_col = 80;
ws.ws_row = 40;
getttysize(tty, &ws);
_getttysize(tty, &ws);
appendr(&b, 0);
appends(&b, "\e[H\e[1m");
@ -6542,7 +6543,7 @@ static void MakeExecutableModifiable(void) {
if (IsWindows()) return; // TODO
if (IsOpenbsd()) return; // TODO
if (IsNetbsd()) return; // TODO
if (endswith(zpath, ".com.dbg")) return;
if (_endswith(zpath, ".com.dbg")) return;
close(zfd);
ft = __ftrace;
if ((zfd = OpenExecutable()) == -1) {

View file

@ -25,12 +25,12 @@
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/gc.internal.h"
#include "libc/sock/goodsocket.internal.h"
#include "libc/sock/sock.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/slice.h"
#include "libc/str/str.h"
@ -45,6 +45,7 @@
#include "libc/sysv/consts/tcp.h"
#include "libc/time/time.h"
#include "libc/x/x.h"
#include "libc/x/xsigaction.h"
#include "net/http/http.h"
#include "net/http/url.h"
#include "net/https/https.h"
@ -400,8 +401,8 @@ int main(int argc, char *argv[]) {
/*
* Parse URL.
*/
gc(ParseUrl(urlarg, -1, &url));
gc(url.params.p);
_gc(ParseUrl(urlarg, -1, &url));
_gc(url.params.p);
usessl = false;
if (url.scheme.n) {
if (url.scheme.n == 5 && !memcasecmp(url.scheme.p, "https", 5)) {
@ -411,9 +412,9 @@ int main(int argc, char *argv[]) {
}
}
if (url.host.n) {
host = gc(strndup(url.host.p, url.host.n));
host = _gc(strndup(url.host.p, url.host.n));
if (url.port.n) {
port = gc(strndup(url.port.p, url.port.n));
port = _gc(strndup(url.port.p, url.port.n));
} else {
port = usessl ? "443" : "80";
}
@ -429,7 +430,7 @@ int main(int argc, char *argv[]) {
url.host.p = 0, url.host.n = 0;
url.port.p = 0, url.port.n = 0;
if (!url.path.n || url.path.p[0] != '/') {
char *p = gc(xmalloc(1 + url.path.n));
char *p = _gc(xmalloc(1 + url.path.n));
mempcpy(mempcpy(p, "/", 1), url.path.p, url.path.n);
url.path.p = p;
++url.path.n;

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/intrin/bsf.h"
#include "libc/intrin/popcnt.h"
#include "libc/limits.h"
#include "libc/log/check.h"
@ -24,7 +25,6 @@
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/bsf.h"
#include "libc/str/str.h"
#include "tool/plinko/lib/cons.h"
#include "tool/plinko/lib/gc.h"
@ -93,7 +93,7 @@ int Census(struct Gc *G) {
if (!~G->M[j]) {
l += DWBITS;
} else {
l += bsfl(~G->M[j]);
l += _bsfl(~G->M[j]);
break;
}
}
@ -124,7 +124,7 @@ void Sweep(struct Gc *G) {
for (; i < G->n; ++i) {
m = G->M[i];
if (~m) {
j = bsfl(~m);
j = _bsfl(~m);
m >>= j;
m <<= j;
d -= j;
@ -136,7 +136,7 @@ void Sweep(struct Gc *G) {
}
for (; i < G->n; b -= DWBITS, m = G->M[++i]) {
for (; m; m &= ~((dword)1 << j)) {
a = b + ~(j = bsfl(m));
a = b + ~(j = _bsfl(m));
Set(--d, MAKE(Relocate(G, LO(Get(a))), Relocate(G, HI(Get(a)))));
SetShadow(d, MAKE(LO(GetShadow(a)), Relocate(G, HI(GetShadow(a)))));
}

View file

@ -1,14 +1,14 @@
#ifndef COSMOPOLITAN_TOOL_PLINKO_LIB_HISTO_H_
#define COSMOPOLITAN_TOOL_PLINKO_LIB_HISTO_H_
#include "libc/intrin/bsr.h"
#include "libc/macros.internal.h"
#include "libc/nexgen32e/bsr.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define HISTO(H, X) \
do { \
uint64_t x_ = X; \
x_ = x_ ? bsrl(x_) + 1 : x_; \
x_ = x_ ? _bsrl(x_) + 1 : x_; \
++H[MIN(x_, ARRAYLEN(H) - 1)]; \
} while (0)

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/strace.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/errno.h"
#include "libc/intrin/likely.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/nexgen32e/bsr.h"
#include "libc/intrin/bsr.h"
#include "tool/plinko/lib/char.h"
#include "tool/plinko/lib/ktpenc.h"
#include "tool/plinko/lib/plinko.h"
@ -31,7 +31,7 @@ int PrintChar(int fd, int s) {
if (c == L'\n') Flush(fd);
} else {
d = c;
e = kTpEnc[bsrl(d) - 7];
e = kTpEnc[_bsrl(d) - 7];
i = n = e & 255;
do g_buffer[fd][bp[fd] + i--] = 0200 | (d & 077);
while (d >>= 6, i);

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/strace.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/nexgen32e/rdtsc.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"

View file

@ -40,7 +40,7 @@ static const char *GetElfSymbol(uintptr_t funcaddr) {
static const char *GetDispatchName(int x) {
const char *s;
s = GetElfSymbol(LO(GetShadow(x)));
if (startswith(s, "Dispatch")) s += 8;
if (_startswith(s, "Dispatch")) s += 8;
return s;
}

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/strace.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/errno.h"
#include "libc/log/check.h"
#include "libc/runtime/runtime.h"

View file

@ -2,11 +2,11 @@
#
# OVERVIEW
#
# Micro-experiment assembler.
# Micro-Experiment Assembler
#
# EXAMPLES
#
# asmexpr 'mov $-4096,%rax' 'not %rax' 'bsr %rax,%rax'
# asmexpr 'mov $8,%rax' 'bsr %rax,%rax'
# asmexpr 'mov $0,%ecx' 'vmovd %ecx,%xmm1' 'vpbroadcastb %xmm1,%ymm1' 'mov $0x20202032489001ff,%rax' 'vmovq %rax,%xmm0' 'vpcmpgtb %ymm1,%ymm0,%ymm2'
c=/tmp/asmexpr.c

2
tool/scripts/awk1 Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec awk "$@" '{print $1}'

2
tool/scripts/awk2 Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec awk "$@" '{print $2}'

2
tool/scripts/awk3 Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec awk "$@" '{print $3}'

2
tool/scripts/awk4 Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec awk "$@" '{print $4}'

2
tool/scripts/awk5 Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec awk "$@" '{print $5}'

2
tool/scripts/awk6 Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec awk "$@" '{print $6}'

2
tool/scripts/awk7 Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec awk "$@" '{print $7}'

2
tool/scripts/awk8 Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec awk "$@" '{print $8}'

4
tool/scripts/bf Executable file
View file

@ -0,0 +1,4 @@
#!/bin/sh
bing.com <"$1" |
fold.com |
exec less

5
tool/scripts/bloat Executable file
View file

@ -0,0 +1,5 @@
#!/bin/sh
nm -C --size "$@" |
sort -r |
grep ' [bBtTRr] ' |
exec less

View file

@ -1,17 +0,0 @@
#!/bin/sh
if ! [ -e ape/ape.S ]; then
echo please cd to cosmopolitan root directory >&2
exit 1
fi
COSMOPOLITAN="$PWD"
EMACSCONFIGS="$HOME/.emacs.d/init.el"
[ -e "$EMACSCONFIGS" ] || EMACSCONFIGS="$HOME/.emacs"
cat >>"$EMACSCONFIGS" <<EOF # idempotent
(let ((path "$COSMOPOLITAN/tool/emacs"))
(when (file-directory-p path)
(add-to-list 'load-path path)
(require 'cosmo)))
EOF

View file

@ -1,43 +0,0 @@
#!/bin/sh
set -ex
rm -f o/ansi/.cosmopolitan.h o/ansi/cosmopolitan.h
make -j12 o/ansi/cosmopolitan.h MODE=ansi
make -j12 o//libc/crt/crt.o o//ape/ape.o o//ape/ape.lds
make -j12 o//cosmopolitan.a
rm -rf o/cosmo
mkdir -p o/cosmo
cp o//ape/ape.o \
o//ape/ape.lds \
o//libc/crt/crt.o \
o//cosmopolitan.a \
o/cosmo
{
echo '#ifndef COSMOPOLITAN_H_'
echo '#define COSMOPOLITAN_H_'
echo '#ifdef __cplusplus'
echo 'extern "C" {'
echo '#endif'
cat o/ansi/cosmopolitan.h
echo '#ifdef __cplusplus'
echo '} /* extern C */'
echo '#endif'
echo '#endif /* COSMOPOLITAN_H_ */'
} >o/cosmo/cosmopolitan.h
cd o/cosmo
cat <<EOF >HELLO.C
int main(int argc, char *argv[]) {
printf("hello world\n");
return 0;
}
EOF
gcc -O -s -static -nostdlib -nostdinc \
-Wl,-T,ape.lds -include cosmopolitan.h \
-o HELLO.COM.DBG HELLO.C crt.o ape.o cosmopolitan.a
objcopy -S -O binary HELLO.COM.DBG HELLO.COM
ls -hal ./HELLO.COM
./HELLO.COM

4
tool/scripts/ezgdb Executable file
View file

@ -0,0 +1,4 @@
#!/bin/sh
PROG="$1"
shift
exec gdb "$PROG" -ex "set args $*" -ex run

View file

@ -1,4 +1,14 @@
#!/usr/bin/env python.com
#
# OVERVIEW
#
# One-Off Makefile Rule Generator
#
# EXAMPLES
#
# tool/scripts/get-deps.py examples/hello.c
# asmexpr 'mov $0,%ecx' 'vmovd %ecx,%xmm1' 'vpbroadcastb %xmm1,%ymm1' 'mov $0x20202032489001ff,%rax' 'vmovq %rax,%xmm0' 'vpcmpgtb %ymm1,%ymm0,%ymm2'
#
import os
import re

View file

@ -1,6 +1,10 @@
#!/bin/sh
exec /usr/bin/grep \
--exclude-dir=o \
--exclude-dir=gcc \
--exclude-dir=.git \
exec grep \
--exclude=TAGS \
--exclude=HTAGS \
--exclude=*.com \
--exclude-dir=o \
--exclude-dir=gcc \
--exclude-dir=.git \
--exclude=archive-contents \
"$@"

View file

@ -1,15 +0,0 @@
#!/bin/sh
# installs emacs version w/ working (replace-buffer-contents)
# it's sooooo worth it due to clang-format-10 working so well
set -ex
sudo apt build-dep emacs
cd "$HOME"
export CFLAGS="-O2"
rm -rf emacs-26.3
wget https://mirrors.kernel.org/gnu/emacs/emacs-26.3.tar.gz
tar xf emacs-26.3.tar.gz
cd emacs-26.3
./configure
make -j8
sudo make install
rm -f ../emacs-26.3.tar.gz

6
tool/scripts/loc Executable file
View file

@ -0,0 +1,6 @@
#!/bin/bash
echo $(( $(find ape dsp libc examples net test third_party tool -name \*.c | xargs cat | wc -l) +
$(find ape dsp libc examples net test third_party tool -name \*.h | xargs cat | wc -l) +
$(find ape dsp libc examples net test third_party tool -name \*.S | xargs cat | wc -l) +
$(find ape dsp libc examples net test third_party tool -name \*.el | xargs cat | wc -l) +
$(find ape dsp libc examples net test third_party tool -name \*.mk | xargs cat | wc -l) ))

3
tool/scripts/obj Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
objdump -Cwd "$@" |
exec less

16
tool/scripts/pb Executable file
View file

@ -0,0 +1,16 @@
#!/bin/sh
exec python.com -c "
# -*- coding: utf-8 -*-
import sys
from math import *
x = $*
s = x < 0
x = abs(x)
b = str(bin(x))[2:].replace('L', '')
n = len(b)
if n <= 8: n = 8
elif n <= 16: n = 16
elif n <= 32: n = 32
elif n <= 64: n = 64
sys.stdout.write(('%%s0b%%0%dd' % n) % ('-' if s else '', int(b)))
"

9
tool/scripts/pe Executable file
View file

@ -0,0 +1,9 @@
#!/bin/sh
echo "# -*- coding: utf-8 -*-
import os
import sys
from math import *
s = str($*)
sys.stdout.write(s)
" >/tmp/pe
exec python.com /tmp/pe

2
tool/scripts/performance Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
echo "performance" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

14
tool/scripts/po Executable file
View file

@ -0,0 +1,14 @@
#!/bin/sh
exec python.com -c "
import sys
from math import *
s = str(oct($*).replace('o',''))
if len(s) > 1: s = s[1:]
b = s.replace('L', '')
n = len(b)
if n <= 3: n = 3
elif n <= 6: n = 6
elif n <= 11: n = 11
elif n <= 22: n = 22
sys.stdout.write(('0%%0%dd' % n) % int(b))
"

2
tool/scripts/powersave Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
echo "powersave" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

17
tool/scripts/px Executable file
View file

@ -0,0 +1,17 @@
#!/bin/sh
exec python.com -c "
# -*- coding: utf-8 -*-
import sys
from math import *
x = $*
s = x < 0
x = abs(x)
b = str(hex(x))[2:].replace('L', '')
n = len(b)
if n <= 2: n = 2
elif n <= 4: n = 4
elif n <= 8: n = 8
elif n <= 12: n = 12
elif n <= 16: n = 16
sys.stdout.write(('%%s0x%%0%dx' % n) % ('-' if s else '', int(b,16)))
"

4
tool/scripts/re Executable file
View file

@ -0,0 +1,4 @@
#!/bin/sh
readelf -Wa "$1" |
c++filt |
exec less

15
tool/scripts/renameheader Executable file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env bash
FROM="${1?from}"
TO="${2?to}"
if [ -f "$TO" ]; then
rm -f "$FROM" || exit
else
mv "$FROM" "$TO" || exit
fi
sed -i -e "s/$(echo "${FROM//\//_}" | sed 's/\./_/' | tr a-z A-Z)_H_/$(echo "${TO//\//_}" | sed 's/\./_/' | tr a-z A-Z)_H_/" "$TO" || exit
tool/scripts/grep -nH -RPie "\"$FROM\"" |
tool/scripts/awk1 -F: |
xargs sed -i -e "s/${FROM//\//\\/}/${TO//\//\\/}/"

98
tool/scripts/wut Executable file
View file

@ -0,0 +1,98 @@
#!/bin/sh
rm -f /tmp/wut-linux
(
grep -R "$1" ~/dox/susv4-2018/ | sed '
/meta.idx/d
' >/tmp/wut-posix
) &
(
grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/linux/include/ | sed '
/\/asm-/ {
/asm-\(x86\|generic\)/!d
}
s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/
s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/
' >>/tmp/wut-linux
) &
(
grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/linux-2.6.18/include/ | sed '
/\/asm-/ {
/asm-\(x86\|generic\)/!d
}
s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/
s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/2.6.18\t\1/
' >>/tmp/wut-linux
) &
(
grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/xnu/ | sed '
s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/
s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/
' >/tmp/wut-xnu
) &
(
{
if ! grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/freebsd/sys/; then
grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/freebsd/lib/libc/
fi
} | sed '
/\/contrib\//d
/\/linux\//d
s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/
s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/
' >/tmp/wut-freebsd
) &
(
{
if ! grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/openbsd/sys/; then
grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/openbsd/lib/libc/
fi
} | sed '
/\/linux\//d
s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/
s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/
' >/tmp/wut-openbsd
) &
(
{
if ! grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/netbsd/sys/; then
grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/netbsd/lib/libc/
fi
} | sed '
/\/linux\//d
s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/
s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/
' >/tmp/wut-netbsd
) &
(
grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/10.0.18362.0/um/ | sed '
s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/
s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/
' >/tmp/wut-windows
) &
wait
f() {
if [ $(ls -lH /tmp/wut-$1 | awk5) -gt 0 ]; then
cat /tmp/wut-$1
else
echo $1 says nothing
fi
}
f linux
f xnu
f freebsd
f openbsd
f netbsd
f windows
f posix

View file

@ -20,11 +20,13 @@
#include "libc/calls/calls.h"
#include "libc/calls/ioctl.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/struct/winsize.h"
#include "libc/fmt/fmt.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/str/locale.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/exit.h"
#include "libc/sysv/consts/fileno.h"
@ -32,7 +34,6 @@
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/sysv/consts/termios.h"
#include "libc/str/locale.h"
#include "third_party/stb/stb_image.h"
#define SQR(X) ((X) * (X))

View file

@ -16,15 +16,15 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bits.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/bsr.h"
#include "libc/intrin/tpenc.h"
#include "libc/macros.internal.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/str/tpenc.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/s.h"
@ -44,7 +44,7 @@ void bf(int fd) {
char ibuf[W], obuf[12 + 1 + W * 6 + 1 + W * (2 + 11) + 11 + 1];
o = 0;
if (fstat(fd, &st) != -1 && S_ISREG(st.st_mode) && st.st_size) {
bits = bsr(roundup2pow(st.st_size));
bits = _bsr(_roundup2pow(st.st_size));
bits = ROUNDUP(bits, 4);
} else {
bits = 48;
@ -58,7 +58,7 @@ void bf(int fd) {
obuf[n++] = ' ';
for (i = 0; i < rc; ++i) {
c = ibuf[i] & 0xff;
w = tpenc(kCp437[c]);
w = _tpenc(kCp437[c]);
do {
obuf[n++] = w;
} while ((w >>= 8));

Some files were not shown because too many files have changed in this diff Show more