Mercurial > wgsdk
comparison 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 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 2:712c7fd6702a | 3:8df8af626dca | 
|---|---|
| 1 #include <stdio.h> | 1 #include <stdio.h> | 
| 2 #include <stdlib.h> | 2 #include <stdlib.h> | 
| 3 #include <string.h> | 3 #include <string.h> | 
| 4 #include <sys/stat.h> | |
| 5 #ifndef WIN32_LEAN_AND_MEAN | 4 #ifndef WIN32_LEAN_AND_MEAN | 
| 6 # define WIN32_LEAN_AND_MEAN | 5 # define WIN32_LEAN_AND_MEAN | 
| 7 #endif | 6 #endif | 
| 8 #include <windows.h> | 7 #include <windows.h> | 
| 9 #include "dirtools.h" | 8 #include "dirtools.h" | 
| 10 | 9 | 
| 10 int dirtools_directory_exists(char* path) { | |
| 11 DWORD attrib = GetFileAttributesA(path); | |
| 12 return (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY)); | |
| 13 } | |
| 14 | |
| 11 int dirtools_create_directory(char* path) { | 15 int dirtools_create_directory(char* path) { | 
| 12 struct stat st = {0}; | |
| 13 char* alltoks = calloc(strlen(path), sizeof(char)), *tok; | 16 char* alltoks = calloc(strlen(path), sizeof(char)), *tok; | 
| 14 | 17 | 
| 15 for (tok = strtok(path, "\\"); tok != NULL; tok = strtok(NULL, "\\")) { | 18 for (tok = strtok(path, "\\"); tok != NULL; tok = strtok(NULL, "\\")) { | 
| 16 strcat(alltoks, tok); | 19 strcat(alltoks, tok); | 
| 17 if (stat(alltoks, &st) == -1) { | 20 if (dirtools_directory_exists(path)) { | 
| 18 if (!CreateDirectoryA(alltoks, NULL)) { | 21 if (!CreateDirectoryA(alltoks, NULL)) { | 
| 19 if (GetLastError() == ERROR_PATH_NOT_FOUND) { | 22 if (GetLastError() == ERROR_PATH_NOT_FOUND) { | 
| 20 /* ERROR_PATH_NOT_FOUND should NOT happen here */ | 23 /* ERROR_PATH_NOT_FOUND should NOT happen here */ | 
| 21 return 1; | 24 return 1; | 
| 22 } | 25 } | 
