+ /* First try to see if we are linked to the framework */
+ for (i = 0; i < _dyld_image_count(); i++)
+ {
+ const char * psz_img_name = _dyld_get_image_name(i);
+ /* Check for "VLCKit.framework/Versions/Current/VLCKit",
+ * as well as "VLCKit.framework/Versions/A/VLCKit" and
+ * "VLC.framework/Versions/B/VLCKit" */
+ if( (p_char = strstr( psz_img_name, "VLCKit.framework/Versions/" )) )
+ {
+ /* Look for the next forward slash */
+ p_char += 26; /* p_char += strlen(" VLCKit.framework/Versions/" ) */
+ while( *p_char != '\0' && *p_char != '/')
+ p_char++;
+
+ /* If the string ends with VLC then we've found a winner */
+ if ( !strcmp( p_char, "/VLCKit" ) )
+ {
+ p_char = strdup( psz_img_name );
+ break;
+ }
+ else
+ p_char = NULL;
+ }
+ else
+ {
+ size_t len = strlen(psz_img_name);
+ /* Do we end by "VLC"? If so we are the legacy VLC.app that doesn't
+ * link to VLCKit. */
+ if( !strcmp( psz_img_name + len - 3, "VLC") )
+ {
+ p_char = strdup( psz_img_name );
+ break;
+ }
+ }
+ }
+ if ( !p_char )
+ {
+ /* We are not linked to the VLC.framework, let's use dladdr to figure
+ * libvlc path */
+ Dl_info info;
+ if( dladdr(system_Init, &info) )
+ p_char = strdup(dirname( info.dli_fname ));
+ }
+ if( !p_char )
+ {
+ char path[MAXPATHLEN+1];
+ uint32_t path_len = MAXPATHLEN;
+ if ( !_NSGetExecutablePath(path, &path_len) )
+ p_char = strdup(path);
+ }
+ if( !p_char )
+ {
+ /* We are not linked to the VLC.framework, return the executable path */
+ p_char = strdup( ppsz_argv[ 0 ] );
+ }
+
+ free(psz_vlcpath);
+ psz_vlcpath = p_char;