Mercurial > wgsdk
annotate src/dirtools.c @ 3:8df8af626dca
dirtools: sys/stat.h->windows.h
committer: GitHub <noreply@github.com>
author | Paper <37962225+mrpapersonic@users.noreply.github.com> |
---|---|
date | Sun, 07 Aug 2022 22:47:41 -0400 |
parents | 7abb5d8b20ea |
children | 59bf702b2b21 |
rev | line source |
---|---|
0 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #ifndef WIN32_LEAN_AND_MEAN | |
5 # define WIN32_LEAN_AND_MEAN | |
6 #endif | |
7 #include <windows.h> | |
8 #include "dirtools.h" | |
9 | |
3
8df8af626dca
dirtools: sys/stat.h->windows.h
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
1
diff
changeset
|
10 int dirtools_directory_exists(char* path) { |
8df8af626dca
dirtools: sys/stat.h->windows.h
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
1
diff
changeset
|
11 DWORD attrib = GetFileAttributesA(path); |
8df8af626dca
dirtools: sys/stat.h->windows.h
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
1
diff
changeset
|
12 return (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY)); |
8df8af626dca
dirtools: sys/stat.h->windows.h
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
1
diff
changeset
|
13 } |
8df8af626dca
dirtools: sys/stat.h->windows.h
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
1
diff
changeset
|
14 |
0 | 15 int dirtools_create_directory(char* path) { |
16 char* alltoks = calloc(strlen(path), sizeof(char)), *tok; | |
17 | |
18 for (tok = strtok(path, "\\"); tok != NULL; tok = strtok(NULL, "\\")) { | |
19 strcat(alltoks, tok); | |
3
8df8af626dca
dirtools: sys/stat.h->windows.h
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
1
diff
changeset
|
20 if (dirtools_directory_exists(path)) { |
1 | 21 if (!CreateDirectoryA(alltoks, NULL)) { |
22 if (GetLastError() == ERROR_PATH_NOT_FOUND) { | |
23 /* ERROR_PATH_NOT_FOUND should NOT happen here */ | |
24 return 1; | |
25 } | |
26 } | |
0 | 27 } |
28 } | |
29 | |
1 | 30 free(alltoks); |
31 | |
0 | 32 return 0; |
33 } | |
34 | |
35 char* dirtools_concat_paths(char* a, char* b) { | |
36 if (a[0] == '\0' || b[0] == '\0') | |
37 return NULL; | |
38 char* out = calloc((strlen(a) + strlen(b) + 2), sizeof(char)); | |
39 if (out == NULL) | |
40 return out; | |
41 strcpy(out, a); | |
42 if (a[strlen(a)] != '\\' && b[0] != '\\') | |
43 strcat(out, "\\"); | |
44 strcat(out, b); | |
45 return out; | |
46 } |