mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 11:37:35 +00:00
ea0b5d9d1c
A new rollup tool now exists for flattening out the headers in a way that works better for our purposes than cpp. A lot of the API clutter has been removed. APIs that aren't a sure thing in terms of general recommendation are now marked internal. There's now a smoke test for the amalgamation archive and gigantic header file. So we can now guarantee you can use this project on the easiest difficulty setting without the gigantic repository. A website is being created, which is currently a work in progress: https://justine.storage.googleapis.com/cosmopolitan/index.html
67 lines
2.3 KiB
C
67 lines
2.3 KiB
C
#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/log/color.internal.h"
|
|
#include "libc/log/log.h"
|
|
#include "libc/mem/mem.h"
|
|
#include "libc/runtime/gc.h"
|
|
#include "libc/runtime/runtime.h"
|
|
#include "libc/stdio/stdio.h"
|
|
#include "libc/str/str.h"
|
|
#include "libc/sysv/consts/exit.h"
|
|
#include "libc/sysv/consts/fileno.h"
|
|
#include "libc/sysv/consts/sig.h"
|
|
|
|
#define kTutorialMessage "This echos stdio until Ctrl+C is pressed.\n"
|
|
#define kVictoryMessage "\rGot Ctrl+C and longjmp() ran dtors (>'.')>\n"
|
|
|
|
jmp_buf jb;
|
|
|
|
void GotCtrlC(int sig) {
|
|
gclongjmp(jb, 1);
|
|
unreachable;
|
|
}
|
|
|
|
size_t HowManyBytesOfHeapMemoryAreAllocated(void) {
|
|
return mallinfo().uordblks;
|
|
}
|
|
|
|
void ReadAndPrintLinesLoop(void) {
|
|
ssize_t got;
|
|
unsigned char *buf;
|
|
buf = gc(malloc(BUFSIZ));
|
|
CHECK_NE(0, HowManyBytesOfHeapMemoryAreAllocated());
|
|
for (;;) {
|
|
CHECK_NE(-1, (got = read(STDIN_FILENO, buf, BUFSIZ)));
|
|
CHECK_EQ(got, write(STDOUT_FILENO, buf, got));
|
|
}
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
int rc;
|
|
rc = 0;
|
|
showcrashreports();
|
|
if (cancolor()) {
|
|
CHECK_EQ(0 /* cosmo runtime doesn't link malloc */,
|
|
HowManyBytesOfHeapMemoryAreAllocated());
|
|
puts("This echos stdio until Ctrl+C is pressed.");
|
|
if (!(rc = setjmp(jb))) {
|
|
CHECK_NE(SIG_ERR, signal(SIGINT, GotCtrlC));
|
|
ReadAndPrintLinesLoop();
|
|
unreachable;
|
|
} else {
|
|
--rc;
|
|
}
|
|
CHECK_EQ(0, HowManyBytesOfHeapMemoryAreAllocated());
|
|
puts("\rGot Ctrl+C and longjmp() ran dtors (>'.')>");
|
|
}
|
|
return rc;
|
|
}
|