aboutsummaryrefslogtreecommitdiffstats
path: root/src/easydir.c
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-02-26 16:16:13 +0000
committerJoursoir <chat@joursoir.net>2021-02-26 16:16:13 +0000
commit3aabad59dc2bbdb74777f2d0dc195fb0bbe75bfc (patch)
tree7c340979b1f3466b4b78f3c03ac5fd311d617d92 /src/easydir.c
parenta8fe7bce0ea33f71485cf8c2e4c8330831c849ce (diff)
downloadlock-password-3aabad59dc2bbdb74777f2d0dc195fb0bbe75bfc.tar.gz
lock-password-3aabad59dc2bbdb74777f2d0dc195fb0bbe75bfc.tar.bz2
lock-password-3aabad59dc2bbdb74777f2d0dc195fb0bbe75bfc.zip
improve code and codestyle; mv/rm cmd don't use global vars anymore
Diffstat (limited to 'src/easydir.c')
-rw-r--r--src/easydir.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/easydir.c b/src/easydir.c
index e1a4394..18f6ec8 100644
--- a/src/easydir.c
+++ b/src/easydir.c
@@ -4,17 +4,37 @@
#include <unistd.h>
#include <sys/wait.h>
#include <errno.h>
+#include <dirent.h>
#include "easydir.h"
#include "xstd.h"
-int checkFileExist(char *source)
+int file_exist(const char *path)
{
- FILE *file = fopen(source, "r+"); // r+ so that errno can equal EISDIR
+ FILE *file = fopen(path, "r+"); // r+ so that errno can equal EISDIR
if(!file)
return errno == EISDIR ? F_ISDIR : F_NOEXIST;
fclose(file);
- return F_NOEXIST;
+ return F_ISFILE;
+}
+
+int count_dir_entries(const char *path)
+{
+ int counter = 0;
+ DIR *dir;
+ struct dirent *dir_entry;
+
+ dir = opendir(path);
+ if(dir == NULL)
+ return 0;
+
+ while((dir_entry = readdir(dir))) {
+ if(dir_entry->d_name[0] == '.')
+ continue;
+ counter++;
+ }
+ closedir(dir);
+ return counter;
}
char *fileCropLineFeed(char *path, char *text, int maxlen)