Skip to content

Commit

Permalink
break out fs_isdir and use it to test fs argument
Browse files Browse the repository at this point in the history
  • Loading branch information
anescient committed Sep 9, 2024
1 parent 52467ab commit c0b34f6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
17 changes: 10 additions & 7 deletions src/studio/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,15 @@ static void onEnumPublicDirsDone(void* data)
free(enumPublicDirsData);
}

bool fs_isdir(const char* path)
{
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;
}

bool tic_fs_isdir(tic_fs* fs, const char* name)
{
if (*name == '.') return false;
Expand All @@ -559,13 +568,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
}

Expand Down
1 change: 1 addition & 0 deletions src/studio/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/studio/studio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2749,7 +2749,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)
Expand All @@ -2761,7 +2761,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);
}
}
Expand Down

0 comments on commit c0b34f6

Please sign in to comment.