]> git.sesse.net Git - vlc/blobdiff - src/misc/darwin_specific.c
libebml port to Win64
[vlc] / src / misc / darwin_specific.c
index f751c63c8ea939859b22b35a40ded2b91ad5f4ac..a15671815cf0b52c9b5cb120fb37f64eed574e9b 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * darwin_specific.m: Darwin specific features
  *****************************************************************************
- * Copyright (C) 2001-2007 the VideoLAN team
+ * Copyright (C) 2001-2009 the VideoLAN team
  * $Id$
  *
  * Authors: Sam Hocevar <sam@zoy.org>
 #include <dirent.h>                                                /* *dir() */
 
 #include <CoreFoundation/CoreFoundation.h>
+#include <mach-o/dyld.h>
 
 #ifdef HAVE_LOCALE_H
 #   include <locale.h>
 #endif
-#ifdef HAVE_MACH_O_DYLD_H
-#   include <mach-o/dyld.h>
-#endif
 
 #ifndef MAXPATHLEN
 # define MAXPATHLEN 1024
 #endif
 
-/* CFLocaleCopyAvailableLocaleIdentifiers is present only on post-10.4 */
-extern CFArrayRef CFLocaleCopyAvailableLocaleIdentifiers(void) __attribute__((weak_import));
-
-/* emulate CFLocaleCopyAvailableLocaleIdentifiers on pre-10.4 */
-static CFArrayRef copy_all_locale_indentifiers(void)
-{
-    CFMutableArrayRef available_locales;
-    DIR * dir;
-    struct dirent *file;
-
-    dir = opendir( "/usr/share/locale" );
-    available_locales = CFArrayCreateMutable( kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks );
-
-    while ( (file = readdir(dir)) )
-    {
-        /* we should probably filter out garbage */
-        /* 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 );
-        CFRelease( locale );
-    }
-
-    closedir( dir );
-    return available_locales;
-}
-
 /*****************************************************************************
  * system_Init: fill in program path & retrieve language
  *****************************************************************************/
@@ -84,7 +55,6 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] )
     (void)pi_argc;
 
     /* Get the full program path and name */
-
     /* First try to see if we are linked to the framework */
     for (i = 0; i < _dyld_image_count(); i++)
     {
@@ -123,6 +93,7 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] )
         p_char = strdup( ppsz_argv[ 0 ] );
     }
 
+    free(psz_vlcpath);
     psz_vlcpath = p_char;
 
     /* Remove trailing program name */
@@ -134,12 +105,11 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] )
             *p_char = '\0';
             p_oldchar = p_char;
         }
-
         p_char++;
     }
 
     /* Check if $LANG is set. */
-    if ( (p_char = getenv("LANG")) == NULL )
+    if( NULL == getenv("LANG") )
     {
         /*
            Retrieve the preferred language as chosen in  System Preferences.app
@@ -149,10 +119,7 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] )
         CFArrayRef all_locales, preferred_locales;
         char psz_locale[50];
 
-        if( CFLocaleCopyAvailableLocaleIdentifiers )
-            all_locales = CFLocaleCopyAvailableLocaleIdentifiers();
-        else
-            all_locales = copy_all_locale_indentifiers();
+        all_locales = CFLocaleCopyAvailableLocaleIdentifiers();
 
         preferred_locales = CFBundleCopyLocalizationsForPreferences( all_locales, NULL );
 
@@ -187,5 +154,6 @@ void system_End( libvlc_int_t *p_this )
 {
     (void)p_this;
     free( psz_vlcpath );
+    psz_vlcpath = NULL;
 }