diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index e6e0806ac5..0e256f20a5 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -594,6 +594,28 @@ void fill_pathname_basedir_noext(char *out_dir, path_remove_extension(out_dir); } +/** + * fill_pathname_parent_dir_name: + * @out_dir : output directory + * @in_dir : input directory + * @size : size of output directory + * + * Copies only the parent directory name of @in_dir into @out_dir. + * The two buffers must not overlap. Removes trailing '/'. + **/ +void fill_pathname_parent_dir_name(char *out_dir, + const char *in_dir, size_t size) +{ + char *temp = strdup(in_dir); + char *last = find_last_slash(temp); + + *last = '\0'; + + in_dir = find_last_slash(temp) + 1; + + strlcpy(out_dir, in_dir, size); +} + /** * fill_pathname_parent_dir: * @out_dir : output directory diff --git a/libretro-common/include/file/file_path.h b/libretro-common/include/file/file_path.h index 0485821ebb..2bba202781 100644 --- a/libretro-common/include/file/file_path.h +++ b/libretro-common/include/file/file_path.h @@ -290,6 +290,18 @@ void fill_pathname_basedir(char *out_path, const char *in_path, size_t size); void fill_pathname_basedir_noext(char *out_dir, const char *in_path, size_t size); +/** + * fill_pathname_parent_dir_name: + * @out_dir : output directory + * @in_dir : input directory + * @size : size of output directory + * + * Copies only the parent directory name of @in_dir into @out_dir. + * The two buffers must not overlap. Removes trailing '/'. + **/ +void fill_pathname_parent_dir_name(char *out_dir, + const char *in_dir, size_t size); + /** * fill_pathname_parent_dir: * @out_dir : output directory