diff --git a/file.h b/file.h index 08c0b33bb8..69ec514bd6 100644 --- a/file.h +++ b/file.h @@ -95,9 +95,10 @@ void fill_pathname_dir(char *in_dir, const char *in_basename, const char *replac void fill_pathname_base(char *out_path, const char *in_path, size_t size); // Copies base directory of in_path into out_path. +// If in_path is a path without any slashes (relative current directory), out_path will get path ".". void fill_pathname_basedir(char *out_path, const char *in_path, size_t size); -void convert_char_to_wchar(wchar_t *out_wchar, const char *in_char, size_t size); -void convert_wchar_to_char(char *out_char, const wchar_t * in_wchar, size_t size); +size_t convert_char_to_wchar(wchar_t *out_wchar, const char *in_char, size_t size); +size_t convert_wchar_to_char(char *out_char, const wchar_t *in_wchar, size_t size); #endif diff --git a/file_path.c b/file_path.c index bb74aa8874..9646877c16 100644 --- a/file_path.c +++ b/file_path.c @@ -388,8 +388,7 @@ void fill_pathname_base(char *out_dir, const char *in_path, size_t size) void fill_pathname_basedir(char *out_dir, const char *in_path, size_t size) { - strncpy(out_dir, in_path, size - 1); - out_dir[size - 1] = '\0'; + rarch_assert(strlcpy(out_dir, in_path, size) < size); char *base = strrchr(out_dir, '/'); if (!base) @@ -397,16 +396,19 @@ void fill_pathname_basedir(char *out_dir, const char *in_path, size_t size) if (base) *base = '\0'; - else - out_dir[0] = '\0'; + else if (size >= 2) + { + out_dir[0] = '.'; + out_dir[1] = '\0'; + } } -void convert_char_to_wchar(wchar_t *out_wchar, const char *in_char, size_t size) +size_t convert_char_to_wchar(wchar_t *out_wchar, const char *in_char, size_t size) { - mbstowcs(out_wchar, in_char, size / sizeof(wchar_t)); + return mbstowcs(out_wchar, in_char, size / sizeof(wchar_t)); } -void convert_wchar_to_char(char *out_char, const wchar_t * in_wchar, size_t size) +size_t convert_wchar_to_char(char *out_char, const wchar_t *in_wchar, size_t size) { - wcstombs(out_char, in_wchar, size / sizeof(char)); + return wcstombs(out_char, in_wchar, size); }