Fix subtle bug in file_path_basedir.

Also applies minor stylistic fixes to file_path.c.
Adds return type to wchar/char conversion functions.
This commit is contained in:
Themaister 2012-07-29 09:23:04 +02:00
parent a75ca75fd1
commit e5a7ef7cf5
2 changed files with 13 additions and 10 deletions

5
file.h
View File

@ -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

View File

@ -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);
}