@@ -451,17 +451,18 @@ void fill_pathname_basedir(char *s, const char *in_path, size_t len)
451451
452452/**
453453 * fill_pathname_parent_dir_name:
454- * @s : output directory
454+ * @s : output string
455455 * @in_dir : input directory
456- * @len : size of output directory
456+ * @len : size of @s
457457 *
458458 * Copies only the parent directory name of @in_dir into @s.
459459 * The two buffers must not overlap. Removes trailing '/'.
460460 *
461- * @return true on success, false if a slash was not found in the path.
461+ * @return Length of the string copied into @s
462462 **/
463- bool fill_pathname_parent_dir_name (char * s , const char * in_dir , size_t len )
463+ size_t fill_pathname_parent_dir_name (char * s , const char * in_dir , size_t len )
464464{
465+ size_t _len = 0 ;
465466 char * tmp = strdup (in_dir );
466467 const char * slash = strrchr (tmp , '/' );
467468 const char * backslash = strrchr (tmp , '\\' );
@@ -493,15 +494,13 @@ bool fill_pathname_parent_dir_name(char *s, const char *in_dir, size_t len)
493494 {
494495 /* If path starts with an slash, eliminate it. */
495496 if (path_is_absolute (in_dir ))
496- strlcpy (s , in_dir + 1 , len );
497+ _len = strlcpy (s , in_dir + 1 , len );
497498 else
498- strlcpy (s , in_dir , len );
499- free (tmp );
500- return true;
499+ _len = strlcpy (s , in_dir , len );
501500 }
502501
503502 free (tmp );
504- return false ;
503+ return _len ;
505504}
506505
507506/**
@@ -1364,91 +1363,73 @@ void path_basedir_wrapper(char *s)
13641363#if !defined(RARCH_CONSOLE ) && defined(RARCH_INTERNAL )
13651364size_t fill_pathname_application_path (char * s , size_t len )
13661365{
1367- size_t i ;
1368- #ifdef __APPLE__
1369- CFBundleRef bundle = CFBundleGetMainBundle ();
1370- #endif
1371- #ifdef _WIN32
1372- DWORD ret = 0 ;
1373- wchar_t wstr [PATH_MAX_LENGTH ] = {0 };
1374- #endif
1375- #ifdef __HAIKU__
1376- image_info info ;
1377- int32_t cookie = 0 ;
1378- #endif
1379- (void )i ;
1380-
1381- if (!len )
1382- return 0 ;
1383-
1366+ if (len )
1367+ {
13841368#if defined(_WIN32 )
13851369#ifdef LEGACY_WIN32
1386- ret = GetModuleFileNameA (NULL , s , len );
1370+ DWORD ret = GetModuleFileNameA (NULL , s , len );
13871371#else
1388- ret = GetModuleFileNameW (NULL , wstr , ARRAY_SIZE (wstr ));
1389-
1390- if (* wstr )
1391- {
1392- char * str = utf16_to_utf8_string_alloc (wstr );
1393-
1394- if (str )
1372+ wchar_t wstr [PATH_MAX_LENGTH ] = {0 };
1373+ DWORD ret = GetModuleFileNameW (NULL , wstr , ARRAY_SIZE (wstr ));
1374+ if (* wstr )
13951375 {
1396- strlcpy (s , str , len );
1397- free (str );
1376+ char * str = utf16_to_utf8_string_alloc (wstr );
1377+ if (str )
1378+ {
1379+ strlcpy (s , str , len );
1380+ free (str );
1381+ }
13981382 }
1399- }
14001383#endif
1401- s [ret ] = '\0' ;
1402- return ret ;
1384+ s [ret ] = '\0' ;
1385+ return ret ;
14031386#elif defined(__APPLE__ )
1404- if (bundle )
1405- {
1406- size_t rv = 0 ;
1407- CFURLRef bundle_url = CFBundleCopyBundleURL (bundle );
1408- CFStringRef bundle_path = CFURLCopyPath (bundle_url );
1409- CFStringGetCString (bundle_path , s , len , kCFStringEncodingUTF8 );
1410- #ifdef HAVE_COCOATOUCH
1387+ CFBundleRef bundle = CFBundleGetMainBundle ();
1388+ if (bundle )
14111389 {
1412- /* This needs to be done so that the path becomes
1413- * /private/var/... and this
1414- * is used consistently throughout for the iOS bundle path */
1415- char resolved_bundle_dir_buf [ DIR_MAX_LENGTH ] = { 0 } ;
1416- if ( realpath ( s , resolved_bundle_dir_buf ))
1390+ size_t rv = 0 ;
1391+ CFURLRef bundle_url = CFBundleCopyBundleURL ( bundle );
1392+ CFStringRef bundle_path = CFURLCopyPath ( bundle_url );
1393+ CFStringGetCString ( bundle_path , s , len , kCFStringEncodingUTF8 ) ;
1394+ #ifdef HAVE_COCOATOUCH
14171395 {
1418- size_t _len = strlcpy (s , resolved_bundle_dir_buf , len - 1 );
1419- s [ _len ] = '/' ;
1420- s [++ _len ] = '\0' ;
1421- rv = _len ;
1396+ /* This needs to be done so that the path becomes
1397+ * /private/var/... and this
1398+ * is used consistently throughout for the iOS bundle path */
1399+ char resolved_bundle_dir_buf [DIR_MAX_LENGTH ] = {0 };
1400+ if (realpath (s , resolved_bundle_dir_buf ))
1401+ {
1402+ size_t _len = strlcpy (s , resolved_bundle_dir_buf , len - 1 );
1403+ s [ _len ] = '/' ;
1404+ s [++ _len ] = '\0' ;
1405+ rv = _len ;
1406+ }
14221407 }
1423- }
14241408#else
1425- rv = CFStringGetLength (bundle_path );
1409+ rv = CFStringGetLength (bundle_path );
14261410#endif
14271411
1428- CFRelease (bundle_path );
1429- CFRelease (bundle_url );
1430- return rv ;
1431- }
1432- return 0 ;
1412+ CFRelease (bundle_path );
1413+ CFRelease (bundle_url );
1414+ return rv ;
1415+ }
14331416#elif defined(__HAIKU__ )
1434- while ( get_next_image_info ( 0 , & cookie , & info ) == B_OK )
1435- {
1436- if ( info . type == B_APP_IMAGE )
1417+ image_info info ;
1418+ int32_t cookie = 0 ;
1419+ while ( get_next_image_info ( 0 , & cookie , & info ) == B_OK )
14371420 {
1438- return strlcpy (s , info .name , len );
1421+ if (info .type == B_APP_IMAGE )
1422+ return strlcpy (s , info .name , len );
14391423 }
1440- }
14411424#elif defined(__QNX__ )
1442- char * buff = malloc (len );
1443- size_t rv = 0 ;
1444-
1445- if (_cmdname (buff ))
1446- rv = strlcpy (s , buff , len );
1447-
1448- free (buff );
1449- return rv ;
1425+ char * buff = malloc (len );
1426+ size_t rv = 0 ;
1427+ if (_cmdname (buff ))
1428+ rv = strlcpy (s , buff , len );
1429+ free (buff );
1430+ return rv ;
14501431#else
1451- {
1432+ size_t i ;
14521433 static const char * exts [] = { "exe" , "file" , "path/a.out" };
14531434 char link_path [255 ];
14541435 pid_t pid = getpid ();
@@ -1469,9 +1450,9 @@ size_t fill_pathname_application_path(char *s, size_t len)
14691450 return ret ;
14701451 }
14711452 }
1472- return 0 ;
1473- }
14741453#endif
1454+ }
1455+ return 0 ;
14751456}
14761457
14771458void fill_pathname_application_dir (char * s , size_t len )
0 commit comments