This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/configurable storage paths (#55)
* when writing files, create directories if they do not exist * revert botched merge file * modify tasks to include debug shared lib builds * use FILENAME_MAX from stdio instead of PATH_MAX from linux/limits * include header guard * Fix windows support for mkdir
- Loading branch information
1 parent
5ebe919
commit fb0fead
Showing
9 changed files
with
160 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
|
||
#include <stdio.h> /* FILENAME_MAX */ | ||
#include <sys/stat.h> /* mkdir(2) */ | ||
#include <errno.h> | ||
|
||
#include "directory.h" | ||
|
||
#ifndef FILENAME_MAX | ||
#define FILENAME_MAX=256 | ||
#endif | ||
|
||
bool create_directory(const char *path) | ||
{ | ||
/* Adapted from http://stackoverflow.com/a/2336245/119527 */ | ||
const size_t len = strlen(path); | ||
char _path[FILENAME_MAX]; | ||
char *p; | ||
|
||
errno = 0; | ||
|
||
/* Copy string so its mutable */ | ||
if (len > sizeof(_path)-1) { | ||
errno = ENAMETOOLONG; | ||
return false; | ||
} | ||
strcpy(_path, path); | ||
|
||
char *directory_separator; | ||
#ifdef _WIN32 | ||
directory_separator = "\\"; | ||
#else | ||
directory_separator = "/"; | ||
#endif | ||
|
||
/* Iterate the string */ | ||
for (p = _path + 1; *p; p++) { | ||
if (*p == directory_separator[0]) { | ||
/* Temporarily truncate */ | ||
*p = '\0'; | ||
|
||
int mk_dir_res = -1; | ||
#ifdef _WIN32 | ||
mk_dir_res = mkdir(_path); | ||
#else | ||
mk_dir_res = mkdir(_path, S_IRWXU); | ||
#endif | ||
if (mk_dir_res != 0) { | ||
if (errno != EEXIST) | ||
return false; | ||
} | ||
|
||
*p = directory_separator[0]; | ||
} | ||
} | ||
|
||
int mk_dir_res = -1; | ||
#ifdef _WIN32 | ||
mk_dir_res = mkdir(_path); | ||
#else | ||
mk_dir_res = mkdir(_path, S_IRWXU); | ||
#endif | ||
|
||
if (mk_dir_res != 0) { | ||
if (errno != EEXIST) | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef __DIRECTORY_H__ | ||
#define __DIRECTORY_H__ | ||
|
||
#include <stdbool.h> | ||
#include <string.h> | ||
|
||
bool create_directory(const char *path); | ||
|
||
#endif /* __DIRECTORY_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters