From 0e34eaaa50bfdefa546988edc0c8efa1bf280130 Mon Sep 17 00:00:00 2001 From: Matt Zykan Date: Sat, 14 Sep 2024 11:20:14 -0500 Subject: [PATCH] break out fs_isdir and use it to test fs argument (#2680) * break out fs_isdir and use it to test fs argument * restore defined(BAREMETALPI) condition to isdir implementation --- src/studio/fs.c | 22 +++++++++++++++------- src/studio/fs.h | 1 + src/studio/studio.c | 4 ++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/studio/fs.c b/src/studio/fs.c index 248107273..c3e059d28 100644 --- a/src/studio/fs.c +++ b/src/studio/fs.c @@ -545,6 +545,20 @@ static void onEnumPublicDirsDone(void* data) free(enumPublicDirsData); } +bool fs_isdir(const char* path) +{ +#if defined(BAREMETALPI) + // This function isn't applicable to baremetal. + return false; +#else + struct tic_stat_struct s; + const FsString* pathString = utf8ToString(path); + bool isdir = tic_stat(pathString, &s) == 0 && S_ISDIR(s.st_mode); + freeString(pathString); + return isdir; +#endif +} + bool tic_fs_isdir(tic_fs* fs, const char* name) { if (*name == '.') return false; @@ -559,13 +573,7 @@ bool tic_fs_isdir(tic_fs* fs, const char* name) return s.fattrib & AM_DIR; #else - const char* path = tic_fs_path(fs, name); - struct tic_stat_struct s; - const FsString* pathString = utf8ToString(path); - bool ret = tic_stat(pathString, &s) == 0 && S_ISDIR(s.st_mode); - freeString(pathString); - - return ret; + return fs_isdir(tic_fs_path(fs, name)); #endif } diff --git a/src/studio/fs.h b/src/studio/fs.h index 11abffb47..a965779df 100644 --- a/src/studio/fs.h +++ b/src/studio/fs.h @@ -59,6 +59,7 @@ void tic_fs_homedir (tic_fs* fs); u64 fs_date (const char* name); bool fs_exists (const char* name); +bool fs_isdir (const char* path); void* fs_read (const char* path, s32* size); bool fs_write (const char* path, const void* data, s32 size); void fs_enum (const char* path, fs_list_callback callback, void* data); diff --git a/src/studio/studio.c b/src/studio/studio.c index e6af17b83..77a62929a 100644 --- a/src/studio/studio.c +++ b/src/studio/studio.c @@ -2756,7 +2756,7 @@ Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_f { const char *path = args.fs ? args.fs : folder; - if (fs_exists(path)) + if (fs_isdir(path)) { studio->fs = tic_fs_create(path, #if defined(BUILD_EDITORS) @@ -2768,7 +2768,7 @@ Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_f } else { - fprintf(stderr, "error: folder `%s` doesn't exist\n", path); + fprintf(stderr, "error: `%s` is not a folder\n", path); exit(1); } }