[PATCH 2 of 3] Add recursive mkdir and mkdir for windows
Wald Commits
scm-commit at wald.intevation.org
Fri Aug 29 17:13:50 CEST 2014
# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1409325155 -7200
# Node ID faf58e9f518bb19186104f8a753650d6eb414aa4
# Parent 427e2e18b8c85fdc708f9b1417e10a772d0d16b5
Add recursive mkdir and mkdir for windows
mkdir for windows is based on the create restricted directory
function that was used in nssstore_win
diff -r 427e2e18b8c8 -r faf58e9f518b common/portpath.c
--- 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
diff -r 427e2e18b8c8 -r faf58e9f518b common/portpath.h
--- 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
More information about the Trustbridge-commits
mailing list