2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2012-04-13 19:29:11 +00:00
|
|
|
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2012-04-13 19:29:11 +00:00
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2012-04-13 19:29:11 +00:00
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
2012-04-21 21:31:57 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2012-04-13 19:29:11 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "file.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "boolean.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include "compat/strl.h"
|
2012-06-18 18:37:35 +00:00
|
|
|
#include "compat/posix_string.h"
|
2012-04-13 19:29:11 +00:00
|
|
|
|
2012-09-11 07:17:25 +00:00
|
|
|
#if defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)
|
2012-06-23 17:17:41 +00:00
|
|
|
#include <unistd.h> //stat() is defined here
|
2012-06-18 20:59:33 +00:00
|
|
|
#define S_ISDIR(x) (x & CELL_FS_S_IFDIR)
|
2012-04-13 19:29:11 +00:00
|
|
|
#endif
|
|
|
|
|
2012-06-24 21:14:49 +00:00
|
|
|
#ifdef _XBOX
|
2012-06-24 20:54:43 +00:00
|
|
|
#include <xtl.h>
|
|
|
|
#endif
|
|
|
|
|
2012-04-13 19:29:11 +00:00
|
|
|
#if defined(_WIN32) && !defined(_XBOX)
|
|
|
|
#include <io.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define setmode _setmode
|
|
|
|
#endif
|
|
|
|
#elif defined(_XBOX)
|
|
|
|
#define setmode _setmode
|
|
|
|
#define INVALID_FILE_ATTRIBUTES -1
|
|
|
|
#else
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#endif
|
|
|
|
|
2012-10-11 20:31:47 +00:00
|
|
|
void string_list_free(struct string_list *list)
|
2012-04-13 19:29:11 +00:00
|
|
|
{
|
2012-06-23 13:31:22 +00:00
|
|
|
if (!list)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < list->size; i++)
|
|
|
|
free(list->elems[i].data);
|
|
|
|
free(list->elems);
|
|
|
|
free(list);
|
|
|
|
}
|
2012-04-13 19:29:11 +00:00
|
|
|
|
2012-06-17 22:34:47 +00:00
|
|
|
static bool string_list_capacity(struct string_list *list, size_t cap)
|
|
|
|
{
|
|
|
|
rarch_assert(cap > list->size);
|
2012-04-13 19:29:11 +00:00
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
struct string_list_elem *new_data = (struct string_list_elem*)realloc(list->elems, cap * sizeof(*new_data));
|
2012-06-17 22:34:47 +00:00
|
|
|
if (!new_data)
|
|
|
|
return false;
|
2012-04-13 19:29:11 +00:00
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
list->elems = new_data;
|
|
|
|
list->cap = cap;
|
2012-06-17 22:34:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
static struct string_list *string_list_new(void)
|
2012-06-17 22:34:47 +00:00
|
|
|
{
|
2012-06-23 13:31:22 +00:00
|
|
|
struct string_list *list = (struct string_list*)calloc(1, sizeof(*list));
|
|
|
|
if (!list)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!string_list_capacity(list, 32))
|
|
|
|
{
|
|
|
|
string_list_free(list);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
2012-06-17 22:34:47 +00:00
|
|
|
}
|
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
static bool string_list_append(struct string_list *list, const char *elem, union string_list_elem_attr attr)
|
2012-06-17 22:34:47 +00:00
|
|
|
{
|
2012-06-23 13:31:22 +00:00
|
|
|
if (list->size >= list->cap &&
|
|
|
|
!string_list_capacity(list, list->cap * 2))
|
2012-06-17 22:34:47 +00:00
|
|
|
return false;
|
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
char *dup = strdup(elem);
|
|
|
|
if (!dup)
|
2012-06-17 22:34:47 +00:00
|
|
|
return false;
|
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
list->elems[list->size].data = dup;
|
|
|
|
list->elems[list->size].attr = attr;
|
|
|
|
|
2012-06-17 22:34:47 +00:00
|
|
|
list->size++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-27 12:31:16 +00:00
|
|
|
struct string_list *string_split(const char *str, const char *delim)
|
2012-06-17 22:34:47 +00:00
|
|
|
{
|
2012-06-17 23:11:03 +00:00
|
|
|
char *copy = NULL;
|
|
|
|
const char *tmp = NULL;
|
2012-06-24 00:11:22 +00:00
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
struct string_list *list = string_list_new();
|
|
|
|
if (!list)
|
2012-04-13 19:29:11 +00:00
|
|
|
goto error;
|
|
|
|
|
2012-06-17 22:34:47 +00:00
|
|
|
copy = strdup(str);
|
|
|
|
if (!copy)
|
2012-06-23 13:31:22 +00:00
|
|
|
goto error;
|
2012-06-17 22:34:47 +00:00
|
|
|
|
2012-06-24 00:11:22 +00:00
|
|
|
char *save;
|
|
|
|
tmp = strtok_r(copy, delim, &save);
|
2012-06-17 22:34:47 +00:00
|
|
|
while (tmp)
|
2012-04-13 19:29:11 +00:00
|
|
|
{
|
2012-06-23 13:31:22 +00:00
|
|
|
union string_list_elem_attr attr;
|
|
|
|
memset(&attr, 0, sizeof(attr));
|
|
|
|
|
|
|
|
if (!string_list_append(list, tmp, attr))
|
2012-04-13 19:29:11 +00:00
|
|
|
goto error;
|
2012-06-17 22:34:47 +00:00
|
|
|
|
2012-06-24 00:11:22 +00:00
|
|
|
tmp = strtok_r(NULL, delim, &save);
|
2012-04-13 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 22:34:47 +00:00
|
|
|
free(copy);
|
2012-06-23 13:31:22 +00:00
|
|
|
return list;
|
2012-06-17 22:34:47 +00:00
|
|
|
|
|
|
|
error:
|
2012-06-23 13:31:22 +00:00
|
|
|
string_list_free(list);
|
2012-06-17 22:34:47 +00:00
|
|
|
free(copy);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-27 12:31:16 +00:00
|
|
|
bool string_list_find_elem(const struct string_list *list, const char *elem)
|
2012-06-17 22:34:47 +00:00
|
|
|
{
|
|
|
|
if (!list)
|
|
|
|
return false;
|
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
for (size_t i = 0; i < list->size; i++)
|
|
|
|
{
|
|
|
|
if (strcmp(list->elems[i].data, elem) == 0)
|
2012-06-17 22:34:47 +00:00
|
|
|
return true;
|
2012-06-23 13:31:22 +00:00
|
|
|
}
|
2012-06-17 22:34:47 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-22 20:43:09 +00:00
|
|
|
bool string_list_find_elem_prefix(const struct string_list *list, const char *prefix, const char *elem)
|
|
|
|
{
|
|
|
|
if (!list)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
char prefixed[PATH_MAX];
|
|
|
|
snprintf(prefixed, sizeof(prefixed), "%s%s", prefix, elem);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < list->size; i++)
|
|
|
|
{
|
|
|
|
if (strcmp(list->elems[i].data, elem) == 0 ||
|
|
|
|
strcmp(list->elems[i].data, prefixed) == 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-27 12:31:16 +00:00
|
|
|
const char *path_get_extension(const char *path)
|
2012-06-17 22:34:47 +00:00
|
|
|
{
|
|
|
|
const char *ext = strrchr(path, '.');
|
|
|
|
if (ext)
|
|
|
|
return ext + 1;
|
|
|
|
else
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
static int qstrcmp_plain(const void *a_, const void *b_)
|
2012-06-17 23:11:03 +00:00
|
|
|
{
|
2012-06-23 13:31:22 +00:00
|
|
|
const struct string_list_elem *a = (const struct string_list_elem*)a_;
|
|
|
|
const struct string_list_elem *b = (const struct string_list_elem*)b_;
|
2012-06-17 23:11:03 +00:00
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
return strcasecmp(a->data, b->data);
|
2012-06-18 22:00:20 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 22:16:59 +00:00
|
|
|
static int qstrcmp_dir(const void *a_, const void *b_)
|
2012-06-18 22:00:20 +00:00
|
|
|
{
|
2012-06-23 13:31:22 +00:00
|
|
|
const struct string_list_elem *a = (const struct string_list_elem*)a_;
|
|
|
|
const struct string_list_elem *b = (const struct string_list_elem*)b_;
|
2012-06-18 22:00:20 +00:00
|
|
|
|
2012-06-18 22:16:59 +00:00
|
|
|
// Sort directories before files.
|
2012-06-23 13:31:22 +00:00
|
|
|
int a_dir = a->attr.b;
|
|
|
|
int b_dir = b->attr.b;
|
2012-06-18 22:16:59 +00:00
|
|
|
if (a_dir != b_dir)
|
|
|
|
return b_dir - a_dir;
|
2012-06-23 13:31:22 +00:00
|
|
|
else
|
|
|
|
return strcasecmp(a->data, b->data);
|
2012-06-17 23:11:03 +00:00
|
|
|
}
|
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
void dir_list_sort(struct string_list *list, bool dir_first)
|
2012-06-17 23:11:03 +00:00
|
|
|
{
|
2012-06-23 13:31:22 +00:00
|
|
|
if (!list)
|
2012-06-17 23:11:03 +00:00
|
|
|
return;
|
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
qsort(list->elems, list->size, sizeof(struct string_list_elem),
|
|
|
|
dir_first ? qstrcmp_dir : qstrcmp_plain);
|
2012-06-17 23:11:03 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 22:34:47 +00:00
|
|
|
#ifdef _WIN32 // Because the API is just fucked up ...
|
2012-06-23 13:31:22 +00:00
|
|
|
struct string_list *dir_list_new(const char *dir, const char *ext, bool include_dirs)
|
2012-06-17 22:34:47 +00:00
|
|
|
{
|
2012-06-23 13:31:22 +00:00
|
|
|
struct string_list *list = string_list_new();
|
|
|
|
if (!list)
|
2012-06-17 22:34:47 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
HANDLE hFind = INVALID_HANDLE_VALUE;
|
|
|
|
WIN32_FIND_DATA ffd;
|
|
|
|
|
|
|
|
char path_buf[PATH_MAX];
|
|
|
|
snprintf(path_buf, sizeof(path_buf), "%s\\*", dir);
|
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
struct string_list *ext_list = NULL;
|
2012-06-17 22:34:47 +00:00
|
|
|
if (ext)
|
|
|
|
ext_list = string_split(ext, "|");
|
|
|
|
|
2012-04-13 19:29:11 +00:00
|
|
|
hFind = FindFirstFile(path_buf, &ffd);
|
|
|
|
if (hFind == INVALID_HANDLE_VALUE)
|
|
|
|
goto error;
|
2012-06-17 22:34:47 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
const char *name = ffd.cFileName;
|
|
|
|
const char *file_ext = path_get_extension(name);
|
2012-06-18 21:43:24 +00:00
|
|
|
bool is_dir = ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
|
2012-06-17 22:34:47 +00:00
|
|
|
|
2012-06-18 21:43:24 +00:00
|
|
|
if (!include_dirs && is_dir)
|
2012-06-17 22:34:47 +00:00
|
|
|
continue;
|
|
|
|
|
2012-08-22 20:43:09 +00:00
|
|
|
if (!is_dir && ext_list && !string_list_find_elem_prefix(ext_list, ".", file_ext))
|
2012-06-17 22:34:47 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
char file_path[PATH_MAX];
|
|
|
|
snprintf(file_path, sizeof(file_path), "%s\\%s", dir, name);
|
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
union string_list_elem_attr attr;
|
|
|
|
attr.b = is_dir;
|
|
|
|
|
|
|
|
if (!string_list_append(list, file_path, attr))
|
2012-06-17 22:34:47 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
while (FindNextFile(hFind, &ffd) != 0);
|
|
|
|
|
|
|
|
FindClose(hFind);
|
|
|
|
string_list_free(ext_list);
|
2012-06-23 13:31:22 +00:00
|
|
|
return list;
|
2012-06-17 22:34:47 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
RARCH_ERR("Failed to open directory: \"%s\"\n", dir);
|
|
|
|
if (hFind != INVALID_HANDLE_VALUE)
|
|
|
|
FindClose(hFind);
|
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
string_list_free(list);
|
2012-06-17 22:34:47 +00:00
|
|
|
string_list_free(ext_list);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-13 19:29:11 +00:00
|
|
|
#else
|
2012-06-23 13:31:22 +00:00
|
|
|
struct string_list *dir_list_new(const char *dir, const char *ext, bool include_dirs)
|
2012-06-17 22:34:47 +00:00
|
|
|
{
|
2012-06-23 13:31:22 +00:00
|
|
|
struct string_list *list = string_list_new();
|
|
|
|
if (!list)
|
2012-06-17 22:34:47 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-04-13 19:29:11 +00:00
|
|
|
DIR *directory = NULL;
|
|
|
|
const struct dirent *entry = NULL;
|
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
struct string_list *ext_list = NULL;
|
2012-06-17 22:34:47 +00:00
|
|
|
if (ext)
|
|
|
|
ext_list = string_split(ext, "|");
|
|
|
|
|
2012-04-13 19:29:11 +00:00
|
|
|
directory = opendir(dir);
|
|
|
|
if (!directory)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
while ((entry = readdir(directory)))
|
|
|
|
{
|
2012-06-17 22:34:47 +00:00
|
|
|
const char *name = entry->d_name;
|
|
|
|
const char *file_ext = path_get_extension(name);
|
2012-06-18 21:27:49 +00:00
|
|
|
bool is_dir = entry->d_type == DT_DIR;
|
2012-04-13 19:29:11 +00:00
|
|
|
|
2012-06-18 21:27:49 +00:00
|
|
|
if (!include_dirs && is_dir)
|
2012-06-17 22:34:47 +00:00
|
|
|
continue;
|
2012-04-13 19:29:11 +00:00
|
|
|
|
2012-07-29 22:36:09 +00:00
|
|
|
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
|
|
|
|
continue;
|
|
|
|
|
2012-08-22 20:43:09 +00:00
|
|
|
if (!is_dir && ext_list && !string_list_find_elem_prefix(ext_list, ".", file_ext))
|
2012-06-17 22:34:47 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
char file_path[PATH_MAX];
|
|
|
|
snprintf(file_path, sizeof(file_path), "%s/%s", dir, name);
|
2012-04-13 19:29:11 +00:00
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
union string_list_elem_attr attr;
|
|
|
|
attr.b = is_dir;
|
|
|
|
|
|
|
|
if (!string_list_append(list, file_path, attr))
|
2012-06-17 22:34:47 +00:00
|
|
|
goto error;
|
2012-04-13 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
closedir(directory);
|
2012-06-17 22:34:47 +00:00
|
|
|
|
|
|
|
string_list_free(ext_list);
|
2012-06-23 13:31:22 +00:00
|
|
|
return list;
|
2012-04-13 19:29:11 +00:00
|
|
|
|
|
|
|
error:
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to open directory: \"%s\"\n", dir);
|
2012-06-17 22:34:47 +00:00
|
|
|
|
2012-04-13 19:29:11 +00:00
|
|
|
if (directory)
|
|
|
|
closedir(directory);
|
2012-06-17 22:34:47 +00:00
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
string_list_free(list);
|
2012-06-17 22:34:47 +00:00
|
|
|
string_list_free(ext_list);
|
2012-04-13 19:29:11 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-06-17 22:34:47 +00:00
|
|
|
#endif
|
2012-04-13 19:29:11 +00:00
|
|
|
|
2012-06-23 13:31:22 +00:00
|
|
|
void dir_list_free(struct string_list *list)
|
2012-04-13 19:29:11 +00:00
|
|
|
{
|
2012-06-23 13:31:22 +00:00
|
|
|
string_list_free(list);
|
2012-04-13 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool path_is_directory(const char *path)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
DWORD ret = GetFileAttributes(path);
|
|
|
|
return (ret & FILE_ATTRIBUTE_DIRECTORY) && (ret != INVALID_FILE_ATTRIBUTES);
|
|
|
|
#else
|
|
|
|
struct stat buf;
|
|
|
|
if (stat(path, &buf) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return S_ISDIR(buf.st_mode);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool path_file_exists(const char *path)
|
|
|
|
{
|
|
|
|
FILE *dummy = fopen(path, "rb");
|
|
|
|
if (dummy)
|
|
|
|
{
|
|
|
|
fclose(dummy);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fill_pathname(char *out_path, const char *in_path, const char *replace, size_t size)
|
|
|
|
{
|
|
|
|
char tmp_path[PATH_MAX];
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
rarch_assert(strlcpy(tmp_path, in_path, sizeof(tmp_path)) < sizeof(tmp_path));
|
2012-04-13 19:29:11 +00:00
|
|
|
char *tok = strrchr(tmp_path, '.');
|
|
|
|
if (tok)
|
|
|
|
*tok = '\0';
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
rarch_assert(strlcpy(out_path, tmp_path, size) < size);
|
|
|
|
rarch_assert(strlcat(out_path, replace, size) < size);
|
2012-04-13 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void fill_pathname_noext(char *out_path, const char *in_path, const char *replace, size_t size)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
rarch_assert(strlcpy(out_path, in_path, size) < size);
|
|
|
|
rarch_assert(strlcat(out_path, replace, size) < size);
|
2012-04-13 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void fill_pathname_dir(char *in_dir, const char *in_basename, const char *replace, size_t size)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
rarch_assert(strlcat(in_dir, "/", size) < size);
|
2012-04-13 19:29:11 +00:00
|
|
|
|
|
|
|
const char *base = strrchr(in_basename, '/');
|
|
|
|
if (!base)
|
|
|
|
base = strrchr(in_basename, '\\');
|
|
|
|
|
|
|
|
if (base)
|
|
|
|
base++;
|
|
|
|
else
|
|
|
|
base = in_basename;
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
rarch_assert(strlcat(in_dir, base, size) < size);
|
|
|
|
rarch_assert(strlcat(in_dir, replace, size) < size);
|
2012-04-13 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
2012-10-11 20:54:07 +00:00
|
|
|
void fill_pathname_base(char *out, const char *in_path, size_t size)
|
2012-04-13 19:29:11 +00:00
|
|
|
{
|
|
|
|
const char *ptr = strrchr(in_path, '/');
|
|
|
|
if (!ptr)
|
|
|
|
ptr = strrchr(in_path, '\\');
|
|
|
|
|
|
|
|
if (ptr)
|
|
|
|
ptr++;
|
|
|
|
else
|
|
|
|
ptr = in_path;
|
|
|
|
|
2012-10-11 20:54:07 +00:00
|
|
|
rarch_assert(strlcpy(out, ptr, size) < size);
|
2012-04-13 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
2012-07-28 18:43:34 +00:00
|
|
|
void fill_pathname_basedir(char *out_dir, const char *in_path, size_t size)
|
|
|
|
{
|
2012-07-29 07:23:04 +00:00
|
|
|
rarch_assert(strlcpy(out_dir, in_path, size) < size);
|
2012-07-28 18:43:34 +00:00
|
|
|
|
|
|
|
char *base = strrchr(out_dir, '/');
|
|
|
|
if (!base)
|
|
|
|
base = strrchr(out_dir, '\\');
|
|
|
|
|
|
|
|
if (base)
|
|
|
|
*base = '\0';
|
2012-07-29 07:23:04 +00:00
|
|
|
else if (size >= 2)
|
|
|
|
{
|
|
|
|
out_dir[0] = '.';
|
|
|
|
out_dir[1] = '\0';
|
|
|
|
}
|
2012-07-28 18:43:34 +00:00
|
|
|
}
|
2012-07-28 20:36:49 +00:00
|
|
|
|
2012-07-29 07:23:04 +00:00
|
|
|
size_t convert_char_to_wchar(wchar_t *out_wchar, const char *in_char, size_t size)
|
2012-07-28 20:36:49 +00:00
|
|
|
{
|
2012-07-29 07:23:04 +00:00
|
|
|
return mbstowcs(out_wchar, in_char, size / sizeof(wchar_t));
|
2012-07-28 20:36:49 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 07:23:04 +00:00
|
|
|
size_t convert_wchar_to_char(char *out_char, const wchar_t *in_wchar, size_t size)
|
2012-07-28 20:36:49 +00:00
|
|
|
{
|
2012-07-29 07:23:04 +00:00
|
|
|
return wcstombs(out_char, in_wchar, size);
|
2012-07-28 20:36:49 +00:00
|
|
|
}
|
2012-09-07 20:20:49 +00:00
|
|
|
|