aboutsummaryrefslogtreecommitdiffstats
path: root/src/easydir.c
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-02-24 18:11:03 +0000
committerJoursoir <chat@joursoir.net>2021-02-24 18:11:03 +0000
commit7cd03c4bbaba01e6b3c46ef5eb61825b34e60643 (patch)
treebcd1159fede206353acfa3b5bd3d11dc5bdb9e19 /src/easydir.c
parentd81afd1cd15df4f789b5fb12c640fcd19312ee0c (diff)
downloadlock-password-7cd03c4bbaba01e6b3c46ef5eb61825b34e60643.tar.gz
lock-password-7cd03c4bbaba01e6b3c46ef5eb61825b34e60643.tar.bz2
lock-password-7cd03c4bbaba01e6b3c46ef5eb61825b34e60643.zip
refactor code
Diffstat (limited to 'src/easydir.c')
-rw-r--r--src/easydir.c41
1 files changed, 7 insertions, 34 deletions
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 <sys/wait.h>
#include <errno.h>
+#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)