From 2650712cb333f5672268a5a66cdca700e1c8b50d Mon Sep 17 00:00:00 2001 From: Eric Warmenhoven Date: Wed, 18 Dec 2024 14:29:58 -0500 Subject: [PATCH] Small tweaks to fill_pathname_application_path (#17268) --- libretro-common/file/file_path.c | 27 +++++++++++++----------- libretro-common/include/file/file_path.h | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index b8d4b4b4bb..0b52b86f38 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -1369,7 +1369,7 @@ void path_basedir_wrapper(char *path) } #if !defined(RARCH_CONSOLE) && defined(RARCH_INTERNAL) -void fill_pathname_application_path(char *s, size_t len) +size_t fill_pathname_application_path(char *s, size_t len) { size_t i; #ifdef __APPLE__ @@ -1386,7 +1386,7 @@ void fill_pathname_application_path(char *s, size_t len) (void)i; if (!len) - return; + return 0; #if defined(_WIN32) #ifdef LEGACY_WIN32 @@ -1406,9 +1406,11 @@ void fill_pathname_application_path(char *s, size_t len) } #endif s[ret] = '\0'; + return ret; #elif defined(__APPLE__) if (bundle) { + size_t rv = 0; CFURLRef bundle_url = CFBundleCopyBundleURL(bundle); CFStringRef bundle_path = CFURLCopyPath(bundle_url); CFStringGetCString(bundle_path, s, len, kCFStringEncodingUTF8); @@ -1423,35 +1425,35 @@ void fill_pathname_application_path(char *s, size_t len) size_t _len = strlcpy(s, resolved_bundle_dir_buf, len - 1); s[ _len] = '/'; s[++_len] = '\0'; + rv = _len; } } +#else + rv = CFStringGetLength(bundle_path); #endif CFRelease(bundle_path); CFRelease(bundle_url); -#ifndef HAVE_COCOATOUCH - /* Not sure what this does but it breaks - * stuff for iOS, so skipping */ - strlcat(s, "nobin", len); -#endif - return; + return rv; } + return 0; #elif defined(__HAIKU__) while (get_next_image_info(0, &cookie, &info) == B_OK) { if (info.type == B_APP_IMAGE) { - strlcpy(s, info.name, len); - return; + return strlcpy(s, info.name, len); } } #elif defined(__QNX__) char *buff = malloc(len); + size_t rv = 0; if (_cmdname(buff)) - strlcpy(s, buff, len); + rv = strlcpy(s, buff, len); free(buff); + return rv; #else { static const char *exts[] = { "exe", "file", "path/a.out" }; @@ -1471,9 +1473,10 @@ void fill_pathname_application_path(char *s, size_t len) if ((ret = readlink(link_path, s, len - 1)) >= 0) { s[ret] = '\0'; - return; + return ret; } } + return 0; } #endif } diff --git a/libretro-common/include/file/file_path.h b/libretro-common/include/file/file_path.h index 88ebde2ea8..581e46a716 100644 --- a/libretro-common/include/file/file_path.h +++ b/libretro-common/include/file/file_path.h @@ -642,7 +642,7 @@ void path_basedir_wrapper(char *path); size_t fill_pathname_slash(char *path, size_t size); #if !defined(RARCH_CONSOLE) && defined(RARCH_INTERNAL) -void fill_pathname_application_path(char *buf, size_t size); +size_t fill_pathname_application_path(char *buf, size_t size); void fill_pathname_application_dir(char *buf, size_t size); size_t fill_pathname_home_dir(char *buf, size_t size); #endif