Make terminal ui binaries work well everywhere
Here's some screenshots of an emulator tui program that was compiled on Linux, then scp'd it to Windows, Mac, and FreeBSD. https://justine.storage.googleapis.com/blinkenlights-cmdexe.png https://justine.storage.googleapis.com/blinkenlights-imac.png https://justine.storage.googleapis.com/blinkenlights-freebsd.png https://justine.storage.googleapis.com/blinkenlights-lisp.png How is this even possible that we have a nontrivial ui binary that just works on Mac, Windows, Linux, and BSD? Surely a first ever achievement. Fixed many bugs. Bootstrapped John McCarthy's metacircular evaluator on bare metal in half the size of Altair BASIC (about 2.5kb) and ran it in emulator for fun and profit.
This commit is contained in:
@ -28,25 +28,25 @@ struct FindComBinary {
|
||||
char buf[PATH_MAX];
|
||||
};
|
||||
|
||||
static struct FindComBinary findcombinary_;
|
||||
static struct FindComBinary g_findcombinary;
|
||||
|
||||
/**
|
||||
* Returns path of binary without debug information, or null.
|
||||
*
|
||||
* @return path to non-debug binary, or -1 w/ errno
|
||||
*/
|
||||
const char *findcombinary(void) {
|
||||
const char *FindComBinary(void) {
|
||||
size_t len;
|
||||
const char *p;
|
||||
if (!findcombinary_.once) {
|
||||
findcombinary_.once = true;
|
||||
if (!g_findcombinary.once) {
|
||||
g_findcombinary.once = true;
|
||||
if ((p = (const char *)getauxval(AT_EXECFN)) &&
|
||||
(len = strlen(p)) < ARRAYLEN(findcombinary_.buf)) {
|
||||
findcombinary_.res = memcpy(findcombinary_.buf, p, len + 1);
|
||||
if (len > 4 && memcmp(&findcombinary_.buf[len - 4], ".dbg", 4) == 0) {
|
||||
findcombinary_.buf[len - 4] = '\0';
|
||||
(len = strlen(p)) < ARRAYLEN(g_findcombinary.buf)) {
|
||||
g_findcombinary.res = memcpy(g_findcombinary.buf, p, len + 1);
|
||||
if (len > 4 && memcmp(&g_findcombinary.buf[len - 4], ".dbg", 4) == 0) {
|
||||
g_findcombinary.buf[len - 4] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
return findcombinary_.res;
|
||||
return g_findcombinary.res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user