Mercurial > trustbridge
changeset 984:faf58e9f518b
Add recursive mkdir and mkdir for windows
mkdir for windows is based on the create restricted directory
function that was used in nssstore_win
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Fri, 29 Aug 2014 17:12:35 +0200 |
parents | 427e2e18b8c8 |
children | 1743895b39b8 |
files | common/portpath.c common/portpath.h |
diffstat | 2 files changed, 50 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/common/portpath.c Fri Aug 29 17:11:35 2014 +0200 +++ b/common/portpath.c Fri Aug 29 17:12:35 2014 +0200 @@ -6,6 +6,8 @@ * See LICENSE.txt for details. */ #include "portpath.h" +#include "strhelp.h" +#include "util.h" #include <libgen.h> #include <limits.h> @@ -15,7 +17,6 @@ #include <sys/types.h> #include <unistd.h> - char * port_dirname(char *path) { @@ -42,9 +43,16 @@ #ifndef _WIN32 return mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0; #else - /* TODO */ - printf("Should make path: %s\n", path); - return false; + wchar_t *wchar_path = utf8_to_wchar(path, strlen(path)); + bool ret; + + if (!wchar_path) + { + return false; + } + ret = create_restricted_directory (wchar_path); + xfree (wchar_path); + return ret; #endif } @@ -81,7 +89,36 @@ } bool -port_isdir(char *path) +port_mkdir_p(const char *path) +{ + char *parent_path, + *p; + if (!path) { + return false; + } + if (port_isdir(path)) { + return true; + } + parent_path = xstrndup (path, strlen(path)); + p = strrchr(parent_path, '/'); + if (!p) + { + p = strrchr(parent_path, '\\'); + } + if (!p) + { + return false; + } + *p = '\0'; + if (!port_isdir(parent_path)) + { + port_mkdir_p(parent_path); + } + return port_mkdir(path); +} + +bool +port_isdir(const char *path) { int ret; #ifndef _WIN32
--- a/common/portpath.h Fri Aug 29 17:11:35 2014 +0200 +++ b/common/portpath.h Fri Aug 29 17:12:35 2014 +0200 @@ -53,7 +53,7 @@ * @param[in] path the path to the file * @returns true if the file is an directory and false otherwise */ -bool port_isdir(char *path); +bool port_isdir(const char *path); /** * @brief create a directory @@ -65,4 +65,11 @@ */ bool port_mkdir(const char *path); +/** + * @brief create a directory and its parent directores + * @param[in] path the path to the directory + * @returns true if the directory was created + */ +bool port_mkdir_p(const char *path); + #endif