Move most init back into SetUpOnce

This commit is contained in:
Jōshin 2024-01-06 03:36:59 +00:00
parent 5ea567697d
commit 2869605486
No known key found for this signature in database

View file

@ -35,16 +35,10 @@
#include "libc/testlib/testlib.h" #include "libc/testlib/testlib.h"
static char *self; static char *self;
static bool skiptests, skiparg0; static bool loaded, skiptests, skiparg0;
void SetUpOnce(void) { void SetUpOnce(void) {
testlib_enable_tmp_setup_teardown(); testlib_enable_tmp_setup_teardown();
}
__attribute__((__constructor__)) static void Child(int argc, char *argv[]) {
if (argc < 2 || strcmp(argv[1], "Child")) {
bool loaded = !!__program_executable_name;
self = GetProgramExecutableName();
if (IsMetal()) { if (IsMetal()) {
skiptests = true; skiptests = true;
} else if (IsWindows()) { } else if (IsWindows()) {
@ -72,7 +66,12 @@ __attribute__((__constructor__)) static void Child(int argc, char *argv[]) {
} else if (skiparg0) { } else if (skiparg0) {
fprintf(stderr, "skipping argv[0] tests\n"); fprintf(stderr, "skipping argv[0] tests\n");
} }
} else { }
__attribute__((__constructor__)) static void Child(int argc, char *argv[]) {
loaded = !!__program_executable_name;
self = GetProgramExecutableName();
if (argc >= 2 && !strcmp(argv[1], "Child")) {
int rc; int rc;
if (!IsWindows()) { if (!IsWindows()) {
rc = sys_chdir("/"); rc = sys_chdir("/");
@ -82,7 +81,7 @@ __attribute__((__constructor__)) static void Child(int argc, char *argv[]) {
if (rc) { if (rc) {
exit(122); exit(122);
} }
if (strcmp(argv[2], GetProgramExecutableName())) { if (strcmp(argv[2], self)) {
exit(123); exit(123);
} }
if (argc >= 4) { if (argc >= 4) {