Add fill_pathname_join().

This commit is contained in:
Themaister 2012-11-25 16:03:16 +01:00
parent f2e02bde1e
commit df40f854cd
3 changed files with 27 additions and 3 deletions

3
file.h
View File

@ -113,6 +113,9 @@ void fill_pathname_basedir(char *out_path, const char *in_path, size_t size);
// E.g.: in_refpath = "/foo/bar/baz.a", in_path = "foobar.cg", out_path = "/foo/bar/foobar.cg".
void fill_pathname_resolve_relative(char *out_path, const char *in_refpath, const char *in_path, size_t size);
// Joins a directory and path together. Makes sure not to get two consecutive slashes between dir and path.
void fill_pathname_join(char *out_path, const char *dir, const char *path, 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);

View File

@ -244,7 +244,7 @@ struct string_list *dir_list_new(const char *dir, const char *ext, bool include_
continue;
char file_path[PATH_MAX];
snprintf(file_path, sizeof(file_path), "%s\\%s", dir, name);
fill_pathname_join(file_path, dir, name, sizeof(file_path));
union string_list_elem_attr attr;
attr.b = is_dir;
@ -307,7 +307,7 @@ struct string_list *dir_list_new(const char *dir, const char *ext, bool include_
const char *file_ext = path_get_extension(name);
char file_path[PATH_MAX];
snprintf(file_path, sizeof(file_path), "%s/%s", dir, name);
fill_pathname_join(file_path, dir, name, sizeof(file_path));
bool is_dir = dirent_is_directory(file_path, entry);
if (!include_dirs && is_dir)
@ -486,6 +486,26 @@ void fill_pathname_resolve_relative(char *out_path, const char *in_refpath, cons
}
}
void fill_pathname_join(char *out_path, const char *dir, const char *path, size_t size)
{
#ifdef _WIN32
const char join_str[] = "\\";
#else
const char join_str[] = "/";
#endif
size_t dir_len;
rarch_assert((dir_len = strlcpy(out_path, dir, size)) < size);
if (dir_len)
{
if (out_path[dir_len - 1] != '/' && out_path[dir_len - 1] != '\\')
rarch_assert(strlcat(out_path, join_str, sizeof(out_path)));
}
rarch_assert(strlcat(out_path, path, size) < size);
}
size_t convert_char_to_wchar(wchar_t *out_wchar, const char *in_char, size_t size)
{
return mbstowcs(out_wchar, in_char, size / sizeof(wchar_t));

View File

@ -21,6 +21,7 @@
#include <stdint.h>
#include <string.h>
#include "general.h"
#include "file.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -234,7 +235,7 @@ bool screenshot_dump(const char *folder, const void *frame,
char shotname[PATH_MAX];
screenshot_generate_filename(shotname, sizeof(shotname));
snprintf(filename, sizeof(filename), "%s/%s", folder, shotname);
fill_pathname_join(filename, folder, shotname, sizeof(filename));
FILE *file = fopen(filename, "wb");
if (!file)