library to write to files for my games
Commit 33d0ad331ce3
tarball2 files changed+38-0
@@ -16,6 +16,15 @@
1616
#include <ctype.h>1717
#include <string.h>1818
19
+#include <limits.h>20
+21
+22
+#define LOCAL "/.local"23
+#define SHARE "/share"24
+25
+1926
uint8_t make_folder(char *path);2027
28
+uint8_t create_settings_folder(char folder_path[PATH_MAX]);29
+2130
#endif@@ -10,3 +10,32 @@ uint8_t make_folder(char *path) {
1010
return 1;1111
}1212
13
+14
+uint8_t create_xdg_folder(char folder_path[PATH_MAX]) {15
+ char *env;16
+17
+ if ((env = getenv("XDG_DATA_HOME")) == NULL) {18
+ if ((env = getenv("HOME")) == NULL) {19
+ printf("are you ok?\n");20
+ return 0;21
+ }22
+ 23
+ uint8_t error = 0;24
+25
+ sprintf(folder_path, "%s%s", env, LOCAL);26
+ error += make_folder(folder_path);27
+28
+ strcat(folder_path, SHARE);29
+ error += make_folder(folder_path);30
+31
+ if (error <= 1) {32
+ printf("Failed to create Folder");33
+ return 0;34
+ } 35
+ } else {36
+ sprintf(folder_path, "%s", env);37
+ }38
+39
+ return 1;40
+}41
+