diff --git a/src/interface.c b/src/interface.c index b69dc8a8..c3bb4a5d 100644 --- a/src/interface.c +++ b/src/interface.c @@ -407,7 +407,7 @@ void c_interface_select_diskette( int drive ) if (entries <= 0) { DISKERR_SHOWERR("Problem reading directory"); - snprintf(disk_path, PATH_MAX, "%s", getenv("HOME")); + snprintf(disk_path, PATH_MAX, "%s", HOMEDIR); nextdir = true; continue; } @@ -1545,7 +1545,7 @@ static void *interface_thread(void *current_key) char *path = NULL; prefs_copyStringValue(PREF_DOMAIN_INTERFACE, PREF_DISK_PATH, &path); if (!path) { - ASPRINTF(&path, "%s", getenv("HOME")); + ASPRINTF(&path, "%s", HOMEDIR); } strncpy(disk_path, path, PATH_MAX-1); disk_path[PATH_MAX-1] = '\0'; diff --git a/src/meta/debug.c b/src/meta/debug.c index 9fc42d17..b2756d73 100644 --- a/src/meta/debug.c +++ b/src/meta/debug.c @@ -2366,7 +2366,7 @@ YY_RULE_SETUP { #if CPU_TRACING char *buf = NULL; - asprintf(&buf, "%s/%s", getenv("HOME"), "cputrace.txt"); + asprintf(&buf, "%s/%s", HOMEDIR, "cputrace.txt"); cpu65_trace_toggle(buf); FREE(buf); #else @@ -2381,7 +2381,7 @@ YY_RULE_SETUP { #if DISK_TRACING char *buf = NULL; - asprintf(&buf, "%s/%s", getenv("HOME"), "disktrace.txt"); + asprintf(&buf, "%s/%s", HOMEDIR, "disktrace.txt"); c_toggle_disk_trace_6(buf, NULL); FREE(buf); #else diff --git a/src/meta/debug.l b/src/meta/debug.l index 2c572751..43b29eaa 100644 --- a/src/meta/debug.l +++ b/src/meta/debug.l @@ -852,7 +852,7 @@ ADDRS [0-9a-fA-F]+ {BOS}cput?r?a?c?e?{EOS} { #if CPU_TRACING char *buf = NULL; - asprintf(&buf, "%s/%s", getenv("HOME"), "cputrace.txt"); + asprintf(&buf, "%s/%s", HOMEDIR, "cputrace.txt"); cpu65_trace_toggle(buf); FREE(buf); #else @@ -863,7 +863,7 @@ ADDRS [0-9a-fA-F]+ {BOS}diskt?r?a?c?e?{EOS} { #if DISK_TRACING char *buf = NULL; - asprintf(&buf, "%s/%s", getenv("HOME"), "disktrace.txt"); + asprintf(&buf, "%s/%s", HOMEDIR, "disktrace.txt"); c_toggle_disk_trace_6(buf, NULL); FREE(buf); #else diff --git a/src/misc.h b/src/misc.h index a2b9dc37..bf743420 100644 --- a/src/misc.h +++ b/src/misc.h @@ -25,6 +25,12 @@ enum { // top installation directory extern const char *data_dir; +#if MOBILE_DEVICE +# define HOMEDIR data_dir +#else +# define HOMEDIR getenv("HOME") +#endif + // global ref to CLI args extern char **argv; extern int argc; diff --git a/src/prefs.c b/src/prefs.c index 2814026b..e587b8c8 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -47,7 +47,7 @@ void prefs_load(void) { } if (!prefsFile) { - ASPRINTF(&prefsFile, "%s/.apple2.json", getenv("HOME")); + ASPRINTF(&prefsFile, "%s/.apple2.json", HOMEDIR); } assert(prefsFile); diff --git a/src/test/testcommon.c b/src/test/testcommon.c index 7b48d635..e5d40c6e 100644 --- a/src/test/testcommon.c +++ b/src/test/testcommon.c @@ -45,7 +45,7 @@ void test_common_init(void) { emulator_ctors(); char *envvar = NULL; - ASPRINTF(&envvar, "APPLE2IX_JSON=%s/.apple2.test.json", getenv("HOME")); + ASPRINTF(&envvar, "APPLE2IX_JSON=%s/.apple2.test.json", HOMEDIR); assert(envvar); putenv(envvar); LEAK(envvar); diff --git a/src/test/testcommon.h b/src/test/testcommon.h index ae106255..75daa394 100644 --- a/src/test/testcommon.h +++ b/src/test/testcommon.h @@ -23,12 +23,6 @@ # include "test/sha1.h" #endif -#ifdef ANDROID -# define HOMEDIR data_dir -#else -# define HOMEDIR getenv("HOME") -#endif - #define TEST_FINISHED 0xff #define MIXSWITCH_ADDR 0x1f32 // PEEK(7986) -- NOTE : value is hardcoded in various places #define WATCHPOINT_ADDR 0x1f33 // PEEK(7987) -- NOTE : value is hardcoded in various places diff --git a/src/test/testprefs.c b/src/test/testprefs.c index ff1891e0..cbe33bd2 100644 --- a/src/test/testprefs.c +++ b/src/test/testprefs.c @@ -272,7 +272,7 @@ TEST test_json_serialization() { ASSERT(tokCount > 0); char *tmpFile = NULL; - ASPRINTF(&tmpFile, "%s/json-XXXXXX", getenv("HOME")); + ASPRINTF(&tmpFile, "%s/json-XXXXXX", HOMEDIR); ASSERT(tmpFile); int fd = mkstemp(tmpFile); ASSERT(fd > 0); @@ -304,7 +304,7 @@ TEST test_json_serialization_pretty() { ASSERT(parsedData); char *tmpFile = NULL; - ASPRINTF(&tmpFile, "%s/json-pretty-XXXXXX", getenv("HOME")); + ASPRINTF(&tmpFile, "%s/json-pretty-XXXXXX", HOMEDIR); ASSERT(tmpFile); int fd = mkstemp(tmpFile); ASSERT(fd > 0); @@ -1896,12 +1896,12 @@ TEST test_prefs_set_props() { TEST test_prefs_load_and_save() { char *apple2JSON = NULL; - ASPRINTF(&apple2JSON, "%s/%s", getenv("HOME"), TEST_JSON); + ASPRINTF(&apple2JSON, "%s/%s", HOMEDIR, TEST_JSON); ASSERT(apple2JSON); unlink(apple2JSON); char *apple2JSONEnv = NULL; - ASPRINTF(&apple2JSONEnv, "APPLE2IX_JSON=%s/%s", getenv("HOME"), TEST_JSON); + ASPRINTF(&apple2JSONEnv, "APPLE2IX_JSON=%s/%s", HOMEDIR, TEST_JSON); ASSERT(apple2JSONEnv); putenv(apple2JSONEnv); LEAK(apple2JSONEnv);