aboutsummaryrefslogtreecommitdiff
path: root/src/common.c
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2020-09-05 14:37:33 +0200
committerJan200101 <sentrycraft123@gmail.com>2020-09-05 14:38:05 +0200
commit2eb15227c79e3a08ce8eed80d41ef07da5b90a78 (patch)
treeb35b4df5857ff4ca9722e8f634707a94be4cdcdc /src/common.c
parente83fafc1895d72f9c1e4bd701c90b325629ea305 (diff)
downloadpolecat-2eb15227c79e3a08ce8eed80d41ef07da5b90a78.tar.gz
polecat-2eb15227c79e3a08ce8eed80d41ef07da5b90a78.zip
move fs related functions to common, add more file related functions
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c
index ca08f07..6d687ee 100644
--- a/src/common.c
+++ b/src/common.c
@@ -1,5 +1,7 @@
#include <stdio.h>
#include <string.h>
+#include <stdbool.h>
+#include <sys/stat.h>
#include "common.h"
@@ -19,3 +21,37 @@ void print_help(const struct Command* commands, const size_t size)
printf("\t%-*s\t %s\n", longestCommand, commands[i].name, commands[i].description);
}
}
+
+struct stat getStat(const char* path)
+{
+ struct stat sb;
+
+ stat(path, &sb);
+
+ return sb;
+}
+
+bool isFile(const char* path)
+{
+ struct stat sb = getStat(path);
+
+ return S_ISREG(sb.st_mode) || S_ISLNK(sb.st_mode);
+}
+
+bool isDir(const char* path)
+{
+ struct stat sb = getStat(path);
+
+ return S_ISDIR(sb.st_mode) || S_ISLNK(sb.st_mode);
+}
+
+void makeDir(const char* path)
+{
+ struct stat st = {0};
+
+ if (stat(path, &st) == -1)
+ {
+ mkdir(path, 0755);
+ }
+}
+