aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common.c36
-rw-r--r--src/common.h20
-rw-r--r--src/config.c11
-rw-r--r--src/config.h4
4 files changed, 57 insertions, 14 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);
+ }
+}
+
diff --git a/src/common.h b/src/common.h
index fba45cd..f33c152 100644
--- a/src/common.h
+++ b/src/common.h
@@ -3,6 +3,8 @@
#include <stddef.h>
#include <stdint.h>
+#include <stdbool.h>
+#include <sys/stat.h>
#define ARRAY_LEN(arr) sizeof(arr) / sizeof(arr[0])
@@ -10,6 +12,16 @@
#define DXVK_API "https://api.github.com/repos/lutris/dxvk/releases"
#define INSTALLER_API "https://lutris.net/api/installers/"
+#ifndef NAME
+#warning "no name specified, setting it to polecat"
+#define NAME "polecat"
+#endif
+
+#ifndef VERSION
+#warning "no version specified, setting it to 0.0.0"
+#define VERSION "0.0.0"
+#endif
+
#define USER_AGENT NAME "/" VERSION
#define USAGE_STR "Usage: " NAME
@@ -27,4 +39,10 @@ struct Command {
void print_help(const struct Command*, size_t);
-#endif \ No newline at end of file
+struct stat getStat(const char* path);
+bool isFile(const char*);
+bool isDir(const char*);
+
+void makeDir(const char* path);
+
+#endif
diff --git a/src/config.c b/src/config.c
index b728e10..4309d87 100644
--- a/src/config.c
+++ b/src/config.c
@@ -13,7 +13,7 @@ static void getXDGDir(const char* envvar, const char* homeext, char* config, con
if (xdg_var)
{
- strcpy(config, xdg_var);
+ strncpy(config, xdg_var, size);
}
else
{
@@ -38,12 +38,3 @@ void getCacheDir(char* config, const size_t size)
getXDGDir("XDG_CACHE_HOME", "/.cache/" NAME, config, size);
}
-void makeDir(const char* path)
-{
- struct stat st = {0};
-
- if (stat(path, &st) == -1)
- {
- mkdir(path, 0755);
- }
-} \ No newline at end of file
diff --git a/src/config.h b/src/config.h
index 07f0dc6..84c3fd0 100644
--- a/src/config.h
+++ b/src/config.h
@@ -7,6 +7,4 @@ void getConfigDir(char*, const size_t);
void getDataDir(char*, const size_t);
void getCacheDir(char*, const size_t);
-void makeDir(const char* path);
-
-#endif \ No newline at end of file
+#endif