mirror of
https://github.com/libretro/libretro-common.git
synced 2025-02-17 07:18:23 +00:00
Resync
This commit is contained in:
parent
149afd5f21
commit
e9d9371d02
@ -640,8 +640,12 @@ static int config_file_from_string_internal(
|
||||
|
||||
void config_file_set_reference_path(config_file_t *conf, char *path)
|
||||
{
|
||||
/* If a relative path the input path is desired the caller is
|
||||
* responsible for preparing and supplying the relative path*/
|
||||
/* It is expected that the conf has it's path already set */
|
||||
|
||||
char short_path[PATH_MAX_LENGTH];
|
||||
|
||||
short_path[0] = '\0';
|
||||
|
||||
if (!conf)
|
||||
return;
|
||||
|
||||
@ -651,8 +655,9 @@ void config_file_set_reference_path(config_file_t *conf, char *path)
|
||||
conf->reference = NULL;
|
||||
}
|
||||
|
||||
|
||||
conf->reference = strdup(path);
|
||||
fill_pathname_abbreviated_or_relative(short_path, conf->path, path, sizeof(short_path));
|
||||
|
||||
conf->reference = strdup(short_path);
|
||||
}
|
||||
|
||||
bool config_file_deinitialize(config_file_t *conf)
|
||||
@ -1287,7 +1292,10 @@ void config_file_dump_orbis(config_file_t *conf, int fd)
|
||||
struct config_include_list *includes = conf->includes;
|
||||
|
||||
if (conf->reference)
|
||||
{
|
||||
pathname_make_slashes_portable(conf->reference);
|
||||
fprintf(file, "#reference \"%s\"\n", conf->reference);
|
||||
}
|
||||
|
||||
|
||||
list = config_file_merge_sort_linked_list(
|
||||
@ -1330,7 +1338,10 @@ void config_file_dump(config_file_t *conf, FILE *file, bool sort)
|
||||
struct config_include_list *includes = conf->includes;
|
||||
|
||||
if (conf->reference)
|
||||
{
|
||||
pathname_make_slashes_portable(conf->reference);
|
||||
fprintf(file, "#reference \"%s\"\n", conf->reference);
|
||||
}
|
||||
|
||||
if (sort)
|
||||
list = config_file_merge_sort_linked_list(
|
||||
|
@ -1108,6 +1108,98 @@ void fill_pathname_abbreviate_special(char *out_path,
|
||||
retro_assert(strlcpy(out_path, in_path, size) < size);
|
||||
}
|
||||
|
||||
/* Changes the slashes to the correct kind for the os
|
||||
* So forward slash on linux and backslash on Windows */
|
||||
void pathname_conform_slashes_to_os(char *path)
|
||||
{
|
||||
/* Conform slashes to os standard so we get proper matching */
|
||||
char* p;
|
||||
for (p = path; *p; p++)
|
||||
if (*p == '/' || *p == '\\')
|
||||
*p = PATH_DEFAULT_SLASH_C();
|
||||
}
|
||||
|
||||
/* Change all shashes to forward so they are more portable between windows and linux */
|
||||
void pathname_make_slashes_portable(char *path)
|
||||
{
|
||||
/* Conform slashes to os standard so we get proper matching */
|
||||
char* p;
|
||||
for (p = path; *p; p++)
|
||||
if (*p == '/' || *p == '\\')
|
||||
*p = '/';
|
||||
}
|
||||
|
||||
/* Get the number of slashes in a path, returns an integer */
|
||||
int get_pathname_num_slashes(const char *in_path)
|
||||
{
|
||||
int num_slashes = 0;
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < PATH_MAX_LENGTH; i++)
|
||||
{
|
||||
if (PATH_CHAR_IS_SLASH(in_path[i]))
|
||||
num_slashes++;
|
||||
if (in_path[i] == '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
return num_slashes;
|
||||
}
|
||||
|
||||
/* Fills the supplied path with either the abbreviated path or the relative path, which ever
|
||||
* one is has less depth / number of slashes
|
||||
* If lengths of abbreviated and relative paths are the same the relative path will be used
|
||||
* in_path can be an absolute, relative or abbreviated path */
|
||||
void fill_pathname_abbreviated_or_relative(char *out_path, const char *in_refpath, const char *in_path, size_t size)
|
||||
{
|
||||
char in_path_conformed[PATH_MAX_LENGTH];
|
||||
char in_refpath_conformed[PATH_MAX_LENGTH];
|
||||
char expanded_path[PATH_MAX_LENGTH];
|
||||
char absolute_path[PATH_MAX_LENGTH];
|
||||
char relative_path[PATH_MAX_LENGTH];
|
||||
char abbreviated_path[PATH_MAX_LENGTH];
|
||||
|
||||
in_path_conformed[0] = '\0';
|
||||
in_refpath_conformed[0] = '\0';
|
||||
absolute_path[0] = '\0';
|
||||
relative_path[0] = '\0';
|
||||
abbreviated_path[0] = '\0';
|
||||
|
||||
strcpy_literal(in_path_conformed, in_path);
|
||||
strcpy_literal(in_refpath_conformed, in_refpath);
|
||||
|
||||
pathname_conform_slashes_to_os(in_path_conformed);
|
||||
pathname_conform_slashes_to_os(in_refpath_conformed);
|
||||
|
||||
/* Expand paths which start with :\ to an absolute path */
|
||||
fill_pathname_expand_special(expanded_path,
|
||||
in_path_conformed, sizeof(expanded_path));
|
||||
|
||||
/* Get the absolute path if it is not already */
|
||||
if (path_is_absolute(expanded_path))
|
||||
strlcpy(absolute_path, expanded_path, PATH_MAX_LENGTH);
|
||||
else
|
||||
fill_pathname_resolve_relative(absolute_path,
|
||||
in_refpath_conformed, in_path_conformed, PATH_MAX_LENGTH);
|
||||
|
||||
pathname_conform_slashes_to_os(absolute_path);
|
||||
|
||||
/* Get the relative path and see how many directories long it is */
|
||||
path_relative_to(relative_path, absolute_path,
|
||||
in_refpath_conformed, sizeof(relative_path));
|
||||
|
||||
/* Get the abbreviated path and see how many directories long it is */
|
||||
fill_pathname_abbreviate_special(abbreviated_path,
|
||||
absolute_path, sizeof(abbreviated_path));
|
||||
|
||||
/* Use the shortest path, preferring the relative path*/
|
||||
if ( get_pathname_num_slashes(relative_path) <=
|
||||
get_pathname_num_slashes(abbreviated_path))
|
||||
retro_assert(strlcpy(out_path, relative_path, size) < size);
|
||||
else
|
||||
retro_assert(strlcpy(out_path, abbreviated_path, size) < size);
|
||||
}
|
||||
|
||||
/**
|
||||
* path_basedir:
|
||||
* @path : path
|
||||
|
@ -442,6 +442,12 @@ void fill_pathname_expand_special(char *out_path,
|
||||
void fill_pathname_abbreviate_special(char *out_path,
|
||||
const char *in_path, size_t size);
|
||||
|
||||
void fill_pathname_abbreviated_or_relative(char *out_path, const char *in_refpath, const char *in_path, size_t size);
|
||||
|
||||
void pathname_conform_slashes_to_os(char *path);
|
||||
|
||||
void pathname_make_slashes_portable(char *path);
|
||||
|
||||
/**
|
||||
* path_basedir:
|
||||
* @path : path
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user