summaryrefslogtreecommitdiff
path: root/legacy/ecore/src/lib/ecore_file/ecore_file.c
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2009-04-11 06:33:00 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2009-04-11 06:33:00 +0000
commit33183982b0783b33ae623542cc17c99eb349277e (patch)
tree45fbc83695e51a62e0166066103932b2f45da2a3 /legacy/ecore/src/lib/ecore_file/ecore_file.c
parent4467ac1c39eddda223ac491ac2c08b46af0501a7 (diff)
minor optimizations to ecore_file_mkpath()
* check if path is already valid, not doing further work if that's the case; * less stats; * check error of ecore_file_mkdir(); * better usage of 'ss' string. SVN revision: 39964
Diffstat (limited to '')
-rw-r--r--legacy/ecore/src/lib/ecore_file/ecore_file.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/legacy/ecore/src/lib/ecore_file/ecore_file.c b/legacy/ecore/src/lib/ecore_file/ecore_file.c
index 7593e2c3e6..60b476c8a0 100644
--- a/legacy/ecore/src/lib/ecore_file/ecore_file.c
+++ b/legacy/ecore/src/lib/ecore_file/ecore_file.c
@@ -250,6 +250,18 @@ ecore_file_recursive_rm(const char *dir)
250 return 1; 250 return 1;
251} 251}
252 252
253static inline int
254_ecore_file_mkpath_if_not_exists(const char *path)
255{
256 struct stat st;
257 if (stat(path, &st) < 0)
258 return ecore_file_mkdir(path);
259 else if (!S_ISDIR(st.st_mode))
260 return 0;
261 else
262 return 1;
263}
264
253/** 265/**
254 * Create a complete path 266 * Create a complete path
255 * @param path The path to create 267 * @param path The path to create
@@ -261,27 +273,23 @@ EAPI int
261ecore_file_mkpath(const char *path) 273ecore_file_mkpath(const char *path)
262{ 274{
263 char ss[PATH_MAX]; 275 char ss[PATH_MAX];
264 int i; 276 unsigned int i;
277
278 if (ecore_file_is_dir(path))
279 return 1;
265 280
266 ss[0] = 0; 281 for (i = 0; path[i] != '\0'; ss[i] = path[i], i++)
267 i = 0;
268 while (path[i])
269 { 282 {
270 if (i == sizeof(ss) - 1) return 0; 283 if (i == sizeof(ss) - 1) return 0;
271 ss[i] = path[i]; 284 if ((path[i] == '/') && (i > 0))
272 ss[i + 1] = 0;
273 if (path[i] == '/')
274 { 285 {
275 ss[i] = 0; 286 ss[i] = '\0';
276 if ((ecore_file_exists(ss)) && (!ecore_file_is_dir(ss))) return 0; 287 if (!_ecore_file_mkpath_if_not_exists(ss))
277 else if (!ecore_file_exists(ss)) ecore_file_mkdir(ss); 288 return 0;
278 ss[i] = '/';
279 } 289 }
280 i++;
281 } 290 }
282 if ((ecore_file_exists(ss)) && (!ecore_file_is_dir(ss))) return 0; 291 ss[i] = '\0';
283 else if (!ecore_file_exists(ss)) ecore_file_mkdir(ss); 292 return _ecore_file_mkpath_if_not_exists(ss);
284 return 1;
285} 293}
286 294
287/** 295/**