Skip to content

Commit

Permalink
Fix subtle bug in file_path_basedir.
Browse files Browse the repository at this point in the history
Also applies minor stylistic fixes to file_path.c.
Adds return type to wchar/char conversion functions.
  • Loading branch information
Themaister committed Jul 29, 2012
1 parent a75ca75 commit e5a7ef7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
5 changes: 3 additions & 2 deletions file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 10 additions & 8 deletions file_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,25 +388,27 @@ 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)
base = strrchr(out_dir, '\\');

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

0 comments on commit e5a7ef7

Please sign in to comment.