From 7cd03c4bbaba01e6b3c46ef5eb61825b34e60643 Mon Sep 17 00:00:00 2001 From: Joursoir Date: Wed, 24 Feb 2021 18:11:03 +0000 Subject: refactor code --- src/easydir.c | 41 +++++++---------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) (limited to 'src/easydir.c') diff --git a/src/easydir.c b/src/easydir.c index 162bae7..6de77bc 100644 --- a/src/easydir.c +++ b/src/easydir.c @@ -5,43 +5,16 @@ #include #include +#include "easydir.h" #include "handerror.h" -int deleteFile(char *file_path) +int checkFileExist(char *source) { - char *arguments[] = {"rm", file_path, NULL}; - easyFork("rm", arguments); - - return 1; -} - -int deleteEmptyDir(char *dir_path) -{ - #if defined(DEBUG) - char *arguments[] = {"rmdir", "-p", dir_path, NULL}; - #else - char *arguments[] = {"rmdir", "-p", "--ignore-fail-on-non-empty", dir_path, NULL}; - #endif - easyFork("rmdir", arguments); - - return 1; -} - -int checkFileExist(char *path_to_file) -{ - FILE *pFile; - - pFile = fopen(path_to_file, "r+"); // r+ so that errno can equal EISDIR - if(pFile == NULL) { - if(errno == ENOENT) // file doesn't exist - return 0; - if(errno == EISDIR) // it's directory - return 2; - else callError(120); - } - fclose(pFile); - - return 1; + FILE *file = fopen(source, "r+"); // r+ so that errno can equal EISDIR + if(!file) + return errno == EISDIR ? F_ISDIR : F_NOEXIST; + fclose(file); + return F_NOEXIST; } char *fileCropLineFeed(char *path, char *text, int maxlen) -- cgit v1.2.3-18-g5258