Mercurial > wgsdk
comparison src/dirtools.c @ 0:d91dfd53b8b4
Initial commit
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 07 Aug 2022 07:26:27 -0400 |
parents | |
children | 7abb5d8b20ea |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d91dfd53b8b4 |
---|---|
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) { | |
18 CreateDirectoryA(alltoks, NULL); | |
19 } | |
20 } | |
21 | |
22 return 0; | |
23 } | |
24 | |
25 char* dirtools_concat_paths(char* a, char* b) { | |
26 if (a[0] == '\0' || b[0] == '\0') | |
27 return NULL; | |
28 char* out = calloc((strlen(a) + strlen(b) + 2), sizeof(char)); | |
29 if (out == NULL) | |
30 return out; | |
31 strcpy(out, a); | |
32 if (a[strlen(a)] != '\\' && b[0] != '\\') | |
33 strcat(out, "\\"); | |
34 strcat(out, b); | |
35 return out; | |
36 } |