comparison common/portpath.c @ 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 b3695a3399de
children 66f6361fba1b
comparison
equal deleted inserted replaced
983:427e2e18b8c8 984:faf58e9f518b
4 * This file is Free Software under the GNU GPL (v>=2) 4 * This file is Free Software under the GNU GPL (v>=2)
5 * and comes with ABSOLUTELY NO WARRANTY! 5 * and comes with ABSOLUTELY NO WARRANTY!
6 * See LICENSE.txt for details. 6 * See LICENSE.txt for details.
7 */ 7 */
8 #include "portpath.h" 8 #include "portpath.h"
9 #include "strhelp.h"
10 #include "util.h"
9 11
10 #include <libgen.h> 12 #include <libgen.h>
11 #include <limits.h> 13 #include <limits.h>
12 #include <stdio.h> 14 #include <stdio.h>
13 #include <stdlib.h> 15 #include <stdlib.h>
14 #include <sys/stat.h> 16 #include <sys/stat.h>
15 #include <sys/types.h> 17 #include <sys/types.h>
16 #include <unistd.h> 18 #include <unistd.h>
17
18 19
19 char * 20 char *
20 port_dirname(char *path) 21 port_dirname(char *path)
21 { 22 {
22 #ifndef _WIN32 23 #ifndef _WIN32
40 port_mkdir(const char *path) 41 port_mkdir(const char *path)
41 { 42 {
42 #ifndef _WIN32 43 #ifndef _WIN32
43 return mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0; 44 return mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0;
44 #else 45 #else
45 /* TODO */ 46 wchar_t *wchar_path = utf8_to_wchar(path, strlen(path));
46 printf("Should make path: %s\n", path); 47 bool ret;
47 return false; 48
49 if (!wchar_path)
50 {
51 return false;
52 }
53 ret = create_restricted_directory (wchar_path);
54 xfree (wchar_path);
55 return ret;
48 #endif 56 #endif
49 } 57 }
50 58
51 char * 59 char *
52 port_realpath(const char *path) 60 port_realpath(const char *path)
79 else 87 else
80 return false; 88 return false;
81 } 89 }
82 90
83 bool 91 bool
84 port_isdir(char *path) 92 port_mkdir_p(const char *path)
93 {
94 char *parent_path,
95 *p;
96 if (!path) {
97 return false;
98 }
99 if (port_isdir(path)) {
100 return true;
101 }
102 parent_path = xstrndup (path, strlen(path));
103 p = strrchr(parent_path, '/');
104 if (!p)
105 {
106 p = strrchr(parent_path, '\\');
107 }
108 if (!p)
109 {
110 return false;
111 }
112 *p = '\0';
113 if (!port_isdir(parent_path))
114 {
115 port_mkdir_p(parent_path);
116 }
117 return port_mkdir(path);
118 }
119
120 bool
121 port_isdir(const char *path)
85 { 122 {
86 int ret; 123 int ret;
87 #ifndef _WIN32 124 #ifndef _WIN32
88 struct stat sb; 125 struct stat sb;
89 ret = stat(path, &sb); 126 ret = stat(path, &sb);

http://wald.intevation.org/projects/trustbridge/