jag

jagWrite_c

public

library to write to files for my games

Star0
Watch0
33d0ad331ce34fe025de52bcb74091c67f1c9a0a
1
ssh://git@git.jaglekon.de:30/jag/jagWrite_c.git
source/jag_write.cC41 lines709 B
1
#include <jag_write.h>
2
3
uint8_t make_folder(char *path) {
4
 
5
  errno = 0;
6
  if (mkdir(path, 0755) && errno != EEXIST) {
7
    return 0;
8
  }
9
10
  return 1;
11
}
12
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