0
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
|
4 #include <sys/stat.h>
|
|
5 #ifndef WIN32_LEAN_AND_MEAN
|
|
6 # define WIN32_LEAN_AND_MEAN
|
|
7 #endif
|
|
8 #include <windows.h>
|
|
9 #include "dirtools.h"
|
|
10
|
|
11 int dirtools_create_directory(char* path) {
|
|
12 struct stat st = {0};
|
|
13 char* alltoks = calloc(strlen(path), sizeof(char)), *tok;
|
|
14
|
|
15 for (tok = strtok(path, "\\"); tok != NULL; tok = strtok(NULL, "\\")) {
|
|
16 strcat(alltoks, tok);
|
|
17 if (stat(alltoks, &st) == -1) {
|
1
|
18 if (!CreateDirectoryA(alltoks, NULL)) {
|
|
19 if (GetLastError() == ERROR_PATH_NOT_FOUND) {
|
|
20 /* ERROR_PATH_NOT_FOUND should NOT happen here */
|
|
21 return 1;
|
|
22 }
|
|
23 }
|
0
|
24 }
|
|
25 }
|
|
26
|
1
|
27 free(alltoks);
|
|
28
|
0
|
29 return 0;
|
|
30 }
|
|
31
|
|
32 char* dirtools_concat_paths(char* a, char* b) {
|
|
33 if (a[0] == '\0' || b[0] == '\0')
|
|
34 return NULL;
|
|
35 char* out = calloc((strlen(a) + strlen(b) + 2), sizeof(char));
|
|
36 if (out == NULL)
|
|
37 return out;
|
|
38 strcpy(out, a);
|
|
39 if (a[strlen(a)] != '\\' && b[0] != '\\')
|
|
40 strcat(out, "\\");
|
|
41 strcat(out, b);
|
|
42 return out;
|
|
43 }
|