Clean up some code

This commit is contained in:
Justine Tunney 2023-10-11 11:45:31 -07:00
parent ec3275179f
commit 285c565051
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
33 changed files with 122 additions and 382 deletions

View file

@ -1,14 +0,0 @@
#if 0
/*─────────────────────────────────────────────────────────────────╗
To the extent possible under law, Justine Tunney has waived
all copyright and related or neighboring rights to this file,
as it is written in the following disclaimers:
http://unlicense.org/ │
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#endif
#include "libc/runtime/runtime.h"
int main(int argc, char *argv[]) {
abort();
}

View file

@ -1,30 +0,0 @@
#if 0
/*─────────────────────────────────────────────────────────────────╗
To the extent possible under law, Justine Tunney has waived
all copyright and related or neighboring rights to this file,
as it is written in the following disclaimers:
http://unlicense.org/ │
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#endif
#include "libc/intrin/kprintf.h"
#include "libc/log/backtrace.internal.h"
#include "libc/log/log.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/symbols.internal.h"
int main(int argc, char *argv[]) {
ShowCrashReports();
if (IsDebuggerPresent(false)) {
kprintf("debugger found!%n");
} else {
kprintf("try running: gdb %s%n", argv[0]);
kprintf("try running: o//tool/build/strace.com %s%n", argv[0]);
}
__builtin_trap();
printf("recovered from SIGTRAP without handler\r\n");
return 0;
}

View file

@ -1,42 +0,0 @@
#if 0
/*─────────────────────────────────────────────────────────────────╗
To the extent possible under law, Justine Tunney has waived
all copyright and related or neighboring rights to this file,
as it is written in the following disclaimers:
http://unlicense.org/ │
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#endif
#include "libc/macros.internal.h"
#include "libc/stdio/stdio.h"
typedef float xmm_t __attribute__((__vector_size__(16), __aligned__(4)));
float dotvector(float *x, float *y, size_t n) {
size_t i;
float res;
if (n > 64) {
return dotvector(x, y, n / 2) + dotvector(x + n / 2, y + n / 2, n - n / 2);
}
for (res = i = 0; i < n; ++i) {
if (i + 4 <= n) {
xmm_t res4 = (xmm_t){0};
do {
res4 += *(xmm_t *)(x + i) * *(xmm_t *)(y + i);
} while ((i += 4) + 4 <= n);
res += res4[0];
res += res4[1];
res += res4[2];
res += res4[3];
continue;
}
res += x[i] * y[i];
}
return res;
}
int main(int argc, char *argv[]) {
float x[] = {1, 2, 3, 4, 1, 2, 3, 4};
float y[] = {4, 3, 2, 1, 1, 2, 3, 4};
printf("%g\n", dotvector(x, y, ARRAYLEN(x)));
}

View file

@ -1,22 +0,0 @@
#if 0
/*─────────────────────────────────────────────────────────────────╗
To the extent possible under law, Justine Tunney has waived
all copyright and related or neighboring rights to this file,
as it is written in the following disclaimers:
http://unlicense.org/ │
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#endif
#include "libc/calls/calls.h"
#include "libc/stdio/stdio.h"
int main(int argc, char *argv[]) {
if (argc < 3) {
fputs("USAGE: FORKEXEC.COM PROG ARGV₀ [ARGV₁...]\n", stderr);
return 1;
}
if (!fork()) {
execv(argv[1], argv + 2);
return 127;
}
}

View file

@ -1,23 +0,0 @@
#if 0
/*─────────────────────────────────────────────────────────────────╗
To the extent possible under law, Justine Tunney has waived
all copyright and related or neighboring rights to this file,
as it is written in the following disclaimers:
http://unlicense.org/ │
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#endif
#include "libc/calls/calls.h"
#include "libc/stdio/stdio.h"
int main(int argc, char *argv[]) {
if (argc < 3) {
fputs("USAGE: FORKEXECWAIT.COM PROG ARGV₀ [ARGV₁...]\n", stderr);
return 1;
}
if (!fork()) {
execv(argv[1], argv + 2);
return 127;
}
wait(0);
}

View file

@ -1,41 +0,0 @@
#if 0
/*─────────────────────────────────────────────────────────────────╗
To the extent possible under law, Justine Tunney has waived
all copyright and related or neighboring rights to this file,
as it is written in the following disclaimers:
http://unlicense.org/ │
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#endif
#include "libc/calls/calls.h"
#include "libc/log/check.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
dontinline void dostuff(const char *s) {
int i, us;
srand(_rand64()); /* seeds rand() w/ intel rdrnd, auxv, etc. */
for (i = 0; i < 5; ++i) {
us = rand() % 500000;
usleep(us);
printf("hello no. %u from %s %u [us=%d]\n", i, s, getpid(), us);
fflush(stdout);
}
}
int main(int argc, char *argv[]) {
int rc, child, wstatus;
CHECK_NE(-1, (child = fork()));
if (!child) {
/* child process */
dostuff("child");
return 0;
} else {
/* parent process */
dostuff("parent");
/* note: abandoned children become zombies */
CHECK_NE(-1, (rc = wait(&wstatus)));
CHECK_EQ(0, WEXITSTATUS(wstatus));
return 0;
}
}

View file

@ -1,29 +0,0 @@
#if 0
/*─────────────────────────────────────────────────────────────────╗
To the extent possible under law, Justine Tunney has waived
all copyright and related or neighboring rights to this file,
as it is written in the following disclaimers:
http://unlicense.org/ │
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#endif
#include "libc/assert.h"
#include "libc/calls/struct/timeval.h"
#include "libc/stdio/stdio.h"
#include "libc/time/struct/tm.h"
#include "libc/time/time.h"
#include "net/http/http.h"
int main(int argc, char *argv[]) {
int rc;
int64_t t;
char p[30];
struct tm tm;
struct timeval tv;
rc = gettimeofday(&tv, 0);
unassert(!rc);
t = tv.tv_sec;
gmtime_r(&t, &tm);
FormatHttpDateTime(p, &tm);
printf("%s\n", p);
}

View file

@ -154,7 +154,7 @@ void *Worker(void *id) {
char inbuf[512], outbuf[512], *p, *q;
// musl libc and cosmopolitan libc support a posix thread extension
// that makes thread cancellation work much better your io routines
// that makes thread cancelation work much better. your io routines
// will just raise ECANCELED so you can check for cancellation with
// normal logic rather than needing to push and pop cleanup handler
// functions onto the stack, or worse dealing with async interrupts

View file

@ -188,7 +188,7 @@ void *ListenWorker(void *arg) {
struct Client client;
// musl libc and cosmopolitan libc support a posix thread extension
// that makes thread cancelation work much better your i/o routines
// that makes thread cancelation work much better. your io routines
// will just raise ECANCELED, so you can check for cancelation with
// normal logic rather than needing to push and pop cleanup handler
// functions onto the stack, or worse dealing with async interrupts

View file

@ -12,8 +12,8 @@
#include "libc/calls/struct/sigset.h"
#include "libc/intrin/kprintf.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/proc/posix_spawn.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/sig.h"

View file

@ -1,17 +0,0 @@
#if 0
/*─────────────────────────────────────────────────────────────────╗
To the extent possible under law, Justine Tunney has waived
all copyright and related or neighboring rights to this file,
as it is written in the following disclaimers:
http://unlicense.org/ │
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#endif
#include "libc/calls/calls.h"
int main(int argc, char *argv[]) {
creat("hello.txt", 0644);
write(3, "hello\n", 6);
close(3);
return 0;
}

View file

@ -10,7 +10,7 @@
#include "libc/runtime/sysconf.h"
#include "libc/stdio/stdio.h"
#define SYSCONF(NAME) printf("%s %,ld\n", #NAME, sysconf(NAME))
#define SYSCONF(NAME) printf("%-24s %,ld\n", #NAME, sysconf(NAME))
int main(int argc, char *argv[]) {
SYSCONF(_SC_CLK_TCK);

View file

@ -8,10 +8,12 @@
*/
#endif
#include "libc/calls/struct/sysinfo.h"
#include "libc/calls/struct/timespec.h"
#include "libc/fmt/conv.h"
#include "libc/fmt/itoa.h"
#include "libc/log/check.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/clock.h"
int main(int argc, char *argv[]) {
int64_t x;

View file

@ -1,19 +0,0 @@
#if 0
/*─────────────────────────────────────────────────────────────────╗
To the extent possible under law, Justine Tunney has waived
all copyright and related or neighboring rights to this file,
as it is written in the following disclaimers:
http://unlicense.org/ │
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#endif
#include "libc/stdio/stdio.h"
#include "libc/thread/tls.h"
void *hog(void) {
return &__get_tls()->tib_errno;
}
int main(int argc, char *argv[]) {
printf("%zu\n", sizeof(struct CosmoTib));
}