From aaf35f53f80850bbd06a920c9bc0a8de540f8cc7 Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Thu, 8 Feb 2018 23:19:12 -0500 Subject: [PATCH] fill_pathname_parent_dir_name: return failure if path has no slash --- libretro-common/file/file_path.c | 16 +++++++++++++--- libretro-common/include/file/file_path.h | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 4e2374004c..4ba3670262 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -602,20 +602,30 @@ void fill_pathname_basedir_noext(char *out_dir, * * Copies only the parent directory name of @in_dir into @out_dir. * The two buffers must not overlap. Removes trailing '/'. + * Returns true on success, false if a slash was not found in the path. **/ -void fill_pathname_parent_dir_name(char *out_dir, +bool 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); + bool ret = false; *last = '\0'; - in_dir = find_last_slash(temp) + 1; + in_dir = find_last_slash(temp); - strlcpy(out_dir, in_dir, size); + if (in_dir && in_dir + 1) + { + strlcpy(out_dir, in_dir + 1, size); + ret = true; + } + else + ret = false; free(temp); + + return ret; } /** diff --git a/libretro-common/include/file/file_path.h b/libretro-common/include/file/file_path.h index 8d54de7c69..85f190c6ad 100644 --- a/libretro-common/include/file/file_path.h +++ b/libretro-common/include/file/file_path.h @@ -298,8 +298,9 @@ void fill_pathname_basedir_noext(char *out_dir, * * Copies only the parent directory name of @in_dir into @out_dir. * The two buffers must not overlap. Removes trailing '/'. + * Returns true on success, false if a slash was not found in the path. **/ -void fill_pathname_parent_dir_name(char *out_dir, +bool fill_pathname_parent_dir_name(char *out_dir, const char *in_dir, size_t size); /**