diff options
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 36 |
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); + } +} + |