X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmisc%2Fdarwin_specific.c;h=810bd1b27ae175a7935d64dddd90eff13edf6154;hb=55b7b5bdb7e65e94465d4ff5660cfc2964d7a18f;hp=77dff2f85e40a617783e6528fe6c6673309c0b27;hpb=64659b286cac3e29ca1fb48c826d7674e4f751ea;p=vlc diff --git a/src/misc/darwin_specific.c b/src/misc/darwin_specific.c index 77dff2f85e..810bd1b27a 100644 --- a/src/misc/darwin_specific.c +++ b/src/misc/darwin_specific.c @@ -1,7 +1,8 @@ + /***************************************************************************** * darwin_specific.m: Darwin specific features ***************************************************************************** - * Copyright (C) 2001-2007 the VideoLAN team + * Copyright (C) 2001-2009 the VideoLAN team * $Id$ * * Authors: Sam Hocevar @@ -23,71 +24,55 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include #include "../libvlc.h" #include /* *dir() */ - +#include +#include #include +#include #ifdef HAVE_LOCALE_H # include #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; -} +#ifndef MAXPATHLEN +# define MAXPATHLEN 1024 +#endif /***************************************************************************** * system_Init: fill in program path & retrieve language *****************************************************************************/ -void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] ) +void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] ) { + VLC_UNUSED(p_this); char i_dummy; char *p_char = NULL; char *p_oldchar = &i_dummy; - int i; + unsigned int i; + (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++) { - char * psz_img_name = _dyld_get_image_name(i); - /* Check for "VLC.framework/Versions/Current/VLC", - * as well as "VLC.framework/Versions/A/VLC" and - * "VLC.framework/Versions/B/VLC" */ - if( p_char = strstr( psz_img_name, "VLC.framework/Versions/" )) + 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 += 23; /* p_char += strlen(" VLC.framework/Versions/" ) */ + 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, "/VLC" ) ) + if ( !strcmp( p_char, "/VLCKit" ) ) { p_char = strdup( psz_img_name ); break; @@ -95,15 +80,41 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] ) 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 ] ); } - vlc_global()->psz_vlcpath = p_char; + free(psz_vlcpath); + psz_vlcpath = p_char; /* Remove trailing program name */ for( ; *p_char ; ) @@ -114,25 +125,22 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] ) *p_char = '\0'; p_oldchar = p_char; } - p_char++; } +#ifdef ENABLE_NLS /* 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 (note that CFLocaleCopyCurrent() is not used because it returns the - prefered locale not language) + preferred locale not language) */ 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 ); @@ -148,17 +156,18 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] ) } CFRelease( all_locales ); } - - vlc_mutex_init( p_this, &vlc_global()->iconv_lock ); - vlc_global()->iconv_macosx = vlc_iconv_open( "UTF-8", "UTF-8-MAC" ); +#endif } /***************************************************************************** * system_Configure: check for system specific configuration options. *****************************************************************************/ -void system_Configure( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] ) +void system_Configure( libvlc_int_t *p_this, + int i_argc, const char *const ppsz_argv[] ) { - + (void)p_this; + (void)i_argc; + (void)ppsz_argv; } /***************************************************************************** @@ -166,10 +175,8 @@ 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()->psz_vlcpath ); - - if ( vlc_global()->iconv_macosx != (vlc_iconv_t)-1 ) - vlc_iconv_close( vlc_global()->iconv_macosx ); - vlc_mutex_destroy( &vlc_global()->iconv_lock ); + (void)p_this; + free( psz_vlcpath ); + psz_vlcpath = NULL; }