forked from enlightenment/efl
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
This commit is contained in:
parent
4467ac1c39
commit
33183982b0
|
@ -250,6 +250,18 @@ ecore_file_recursive_rm(const char *dir)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
_ecore_file_mkpath_if_not_exists(const char *path)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
if (stat(path, &st) < 0)
|
||||||
|
return ecore_file_mkdir(path);
|
||||||
|
else if (!S_ISDIR(st.st_mode))
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a complete path
|
* Create a complete path
|
||||||
* @param path The path to create
|
* @param path The path to create
|
||||||
|
@ -261,27 +273,23 @@ EAPI int
|
||||||
ecore_file_mkpath(const char *path)
|
ecore_file_mkpath(const char *path)
|
||||||
{
|
{
|
||||||
char ss[PATH_MAX];
|
char ss[PATH_MAX];
|
||||||
int i;
|
unsigned int i;
|
||||||
|
|
||||||
ss[0] = 0;
|
if (ecore_file_is_dir(path))
|
||||||
i = 0;
|
return 1;
|
||||||
while (path[i])
|
|
||||||
|
for (i = 0; path[i] != '\0'; ss[i] = path[i], i++)
|
||||||
{
|
{
|
||||||
if (i == sizeof(ss) - 1) return 0;
|
if (i == sizeof(ss) - 1) return 0;
|
||||||
ss[i] = path[i];
|
if ((path[i] == '/') && (i > 0))
|
||||||
ss[i + 1] = 0;
|
|
||||||
if (path[i] == '/')
|
|
||||||
{
|
{
|
||||||
ss[i] = 0;
|
ss[i] = '\0';
|
||||||
if ((ecore_file_exists(ss)) && (!ecore_file_is_dir(ss))) return 0;
|
if (!_ecore_file_mkpath_if_not_exists(ss))
|
||||||
else if (!ecore_file_exists(ss)) ecore_file_mkdir(ss);
|
return 0;
|
||||||
ss[i] = '/';
|
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
if ((ecore_file_exists(ss)) && (!ecore_file_is_dir(ss))) return 0;
|
ss[i] = '\0';
|
||||||
else if (!ecore_file_exists(ss)) ecore_file_mkdir(ss);
|
return _ecore_file_mkpath_if_not_exists(ss);
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue