]> git.sesse.net Git - vlc/blobdiff - src/misc/darwin_specific.c
Removes trailing spaces. Removes tabs.
[vlc] / src / misc / darwin_specific.c
index da939ac87a847d949e5ae5e9aafffc54180c9736..f14d54b8ce8d575eddc85d2fc7eff0a6f1700f2f 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
-#include <string.h>                                              /* strdup(), strstr() */
-#include <stdlib.h>                                                /* free() */
-#include <dirent.h>                                                /* *dir() */
 
 #include <vlc/vlc.h>
+#include "../libvlc.h"
+#include <dirent.h>                                                /* *dir() */
 
 #include <CoreFoundation/CoreFoundation.h>
 
@@ -50,7 +49,7 @@ static CFArrayRef copy_all_locale_indentifiers(void)
     while ( (file = readdir(dir)) )
     {
         /* we should probably filter out garbage */
-        /* we can't use CFStringCreateWithFileSystemRepresentation as it is 
+        /* we can't use CFStringCreateWithFileSystemRepresentation as it is
          * supported only on post-10.4 (and this function is only for pre-10.4) */
         CFStringRef locale = CFStringCreateWithCString( kCFAllocatorDefault, file->d_name, kCFStringEncodingUTF8 );
         CFArrayAppendValue( available_locales, (void*)locale );
@@ -67,10 +66,27 @@ static CFArrayRef copy_all_locale_indentifiers(void)
 void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] )
 {
     char i_dummy;
-    char *p_char, *p_oldchar = &i_dummy;
+    char *p_char = NULL;
+    char *p_oldchar = &i_dummy;
+    int i;
 
     /* Get the full program path and name */
-    p_char = vlc_global( p_this )->psz_vlcpath = strdup( ppsz_argv[ 0 ] );
+
+    /* First try to see if we are linked to the framework */
+    for (i = 0; i < _dyld_image_count(); i++)
+    {
+        char * psz_img_name = _dyld_get_image_name(i);
+        if( strstr( psz_img_name, "VLC.framework/Version/Current/VLC" ) )
+            p_char = strdup( psz_img_name );
+    }
+
+    if( !p_char )
+    {
+        /* We are not linked to the VLC.framework, return the executable path */
+        p_char = strdup( ppsz_argv[ 0 ] );
+    }
+
+    vlc_global()->psz_vlcpath = p_char;
 
     /* Remove trailing program name */
     for( ; *p_char ; )
@@ -91,7 +107,7 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] )
         /*
            Retrieve the preferred language as chosen in  System Preferences.app
            (note that CFLocaleCopyCurrent() is not used because it returns the
-            prefered locale not language) 
+            prefered locale not language)
         */
         CFArrayRef all_locales, preferred_locales;
         char psz_locale[50];
@@ -116,8 +132,8 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] )
         CFRelease( all_locales );
     }
 
-    vlc_mutex_init( p_this, &vlc_global( p_this )->iconv_lock );
-    vlc_global( p_this )->iconv_macosx = vlc_iconv_open( "UTF-8", "UTF-8-MAC" );
+    vlc_mutex_init( p_this, &vlc_global()->iconv_lock );
+    vlc_global()->iconv_macosx = vlc_iconv_open( "UTF-8", "UTF-8-MAC" );
 }
 
 /*****************************************************************************
@@ -133,10 +149,10 @@ void system_Configure( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] )
  *****************************************************************************/
 void system_End( libvlc_int_t *p_this )
 {
-    free( vlc_global( p_this )->psz_vlcpath );
+    free( vlc_global()->psz_vlcpath );
 
-    if ( vlc_global( p_this )->iconv_macosx != (vlc_iconv_t)-1 )
-        vlc_iconv_close( vlc_global( p_this )->iconv_macosx );
-    vlc_mutex_destroy( &vlc_global( p_this )->iconv_lock );
+    if ( vlc_global()->iconv_macosx != (vlc_iconv_t)-1 )
+        vlc_iconv_close( vlc_global()->iconv_macosx );
+    vlc_mutex_destroy( &vlc_global()->iconv_lock );
 }