refactor(file): use glib helpers for file checking

This commit is contained in:
Jeremy Attali 2019-12-30 00:00:51 -05:00
parent aed2bfe294
commit 319a6107f5
2 changed files with 3 additions and 11 deletions

View File

@ -18,7 +18,7 @@ bool config_get_storage_path(struct swappy_state *state) {
if (wordexp(storage_paths[i], &p, 0) == 0) {
char *path = g_strdup(p.we_wordv[0]);
wordfree(&p);
if (folder_exists(path)) {
if (path && folder_exists(path)) {
g_info("storage path is: %s", path);
state->storage_path = path;
return true;

View File

@ -12,19 +12,11 @@
#define BLOCK_SIZE 1024
bool folder_exists(const char *path) {
struct stat sb;
stat(path, &sb);
return (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode));
return g_file_test(path, G_FILE_TEST_IS_DIR);
}
bool file_exists(const char *path) {
struct stat sb;
stat(path, &sb);
return (stat(path, &sb) == 0 && S_ISREG(sb.st_mode));
return g_file_test(path, G_FILE_TEST_EXISTS);
}
char *file_dump_stdin_into_a_temp_file() {