jag

jagWrite_c

public

library to write to files for my games

Star0
Watch0
82c2bdb279879c9fd7fc736710fde72956b49bde
1
ssh://git@git.jaglekon.de:30/jag/jagWrite_c.git
source/jag_write.cC52 lines969 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
42
uint8_t create_folder(char *folder_name, char *folder_path, char output_path[PATH_MAX]) {
43
  
44
  sprintf(output_path, "%s/%s", folder_path, folder_name);
45
  if (!make_folder(output_path)) {
46
    printf("Failed to create Folder");
47
    return 0;
48
  }
49
50
  return 1;
51
}
52