Move functions around

This commit is contained in:
twinaphex 2015-09-22 19:34:16 +02:00
parent 5465da0139
commit 385e030261
4 changed files with 79 additions and 64 deletions

View File

@ -31,13 +31,63 @@
#include <kernel/image.h>
#endif
#include <sys/stat.h>
#include <file/file_path.h>
#include <compat/strl.h>
#include <compat/posix_string.h>
#include <retro_assert.h>
#include <retro_stat.h>
#include <retro_miscellaneous.h>
/**
* path_mkdir:
* @dir : directory
*
* Create directory on filesystem.
*
* Returns: true (1) if directory could be created, otherwise false (0).
**/
bool path_mkdir(const char *dir)
{
const char *target = NULL;
/* Use heap. Real chance of stack overflow if we recurse too hard. */
char *basedir = strdup(dir);
bool ret = false;
if (!basedir)
return false;
path_parent_dir(basedir);
if (!*basedir || !strcmp(basedir, dir))
goto end;
if (path_is_directory(basedir))
{
target = dir;
ret = mkdir_norecurse(dir);
}
else
{
target = basedir;
ret = path_mkdir(basedir);
if (ret)
{
target = dir;
ret = mkdir_norecurse(dir);
}
}
end:
if (target && !ret)
printf("Failed to create directory: \"%s\".\n", target);
free(basedir);
return ret;
}
/**
* path_get_extension:
* @path : path

View File

@ -20,6 +20,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@ -56,13 +57,6 @@
#include <kernel/image.h>
#endif
#if (defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)) || defined(__QNX__) || defined(PSP)
#include <unistd.h> /* stat() is defined here */
#endif
#include <file/file_path.h>
#include <retro_miscellaneous.h>
#if defined(__CELLOS_LV2__)
#include <cell/cell_fs.h>
#endif
@ -71,6 +65,13 @@
#define FIO_SO_ISDIR PSP2_S_ISDIR
#endif
#if (defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)) || defined(__QNX__) || defined(PSP)
#include <unistd.h> /* stat() is defined here */
#endif
#include <retro_miscellaneous.h>
#include <boolean.h>
/**
* path_is_directory:
* @path : path
@ -111,7 +112,7 @@ bool path_is_directory(const char *path)
*
* Returns: true (1) if directory could be created, otherwise false (0).
**/
static bool path_mkdir_norecurse(const char *dir)
bool mkdir_norecurse(const char *dir)
{
int ret;
#if defined(_WIN32)
@ -136,52 +137,6 @@ static bool path_mkdir_norecurse(const char *dir)
return ret == 0;
}
/**
* path_mkdir:
* @dir : directory
*
* Create directory on filesystem.
*
* Returns: true (1) if directory could be created, otherwise false (0).
**/
bool path_mkdir(const char *dir)
{
const char *target = NULL;
/* Use heap. Real chance of stack overflow if we recurse too hard. */
char *basedir = strdup(dir);
bool ret = false;
if (!basedir)
return false;
path_parent_dir(basedir);
if (!*basedir || !strcmp(basedir, dir))
goto end;
if (path_is_directory(basedir))
{
target = dir;
ret = path_mkdir_norecurse(dir);
}
else
{
target = basedir;
ret = path_mkdir(basedir);
if (ret)
{
target = dir;
ret = path_mkdir_norecurse(dir);
}
}
end:
if (target && !ret)
printf("Failed to create directory: \"%s\".\n", target);
free(basedir);
return ret;
}
bool stat_is_valid(const char *path)
{
#if defined(VITA) || defined(PSP)

View File

@ -379,6 +379,16 @@ void fill_pathname_slash(char *path, size_t size);
void fill_pathname_application_path(char *buf, size_t size);
#endif
/**
* path_mkdir:
* @dir : directory
*
* Create directory on filesystem.
*
* Returns: true (1) if directory could be created, otherwise false (0).
**/
bool path_mkdir(const char *dir);
#ifdef __cplusplus
}
#endif

View File

@ -28,16 +28,6 @@
#include <boolean.h>
/**
* path_mkdir:
* @dir : directory
*
* Create directory on filesystem.
*
* Returns: true (1) if directory could be created, otherwise false (0).
**/
bool path_mkdir(const char *dir);
/**
* path_is_directory:
* @path : path
@ -50,4 +40,14 @@ bool path_is_directory(const char *path);
bool path_is_valid(const char *path);
/**
* path_mkdir_norecurse:
* @dir : directory
*
* Create directory on filesystem.
*
* Returns: true (1) if directory could be created, otherwise false (0).
**/
bool mkdir_norecurse(const char *dir);
#endif