2 /*****************************************************************************
3 * darwin_specific.m: Darwin specific features
4 *****************************************************************************
5 * Copyright (C) 2001-2009 the VideoLAN team
8 * Authors: Sam Hocevar <sam@zoy.org>
9 * Christophe Massiot <massiot@via.ecp.fr>
10 * Pierre d'Herbemont <pdherbemont@free.fr>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
31 #include <vlc_common.h>
32 #include "../libvlc.h"
33 #include <dirent.h> /* *dir() */
36 #include <CoreFoundation/CoreFoundation.h>
37 #include <mach-o/dyld.h>
44 # define MAXPATHLEN 1024
47 /*****************************************************************************
48 * system_Init: fill in program path & retrieve language
49 *****************************************************************************/
50 void system_Init(void)
54 char *p_oldchar = &i_dummy;
57 /* Get the full program path and name */
58 /* First try to see if we are linked to the framework */
59 for (i = 0; i < _dyld_image_count(); i++)
61 const char * psz_img_name = _dyld_get_image_name(i);
62 /* Check for "VLCKit.framework/Versions/Current/VLCKit",
63 * as well as "VLCKit.framework/Versions/A/VLCKit" and
64 * "VLC.framework/Versions/B/VLCKit" */
65 if( (p_char = strstr( psz_img_name, "VLCKit.framework/Versions/" )) )
67 /* Look for the next forward slash */
68 p_char += 26; /* p_char += strlen(" VLCKit.framework/Versions/" ) */
69 while( *p_char != '\0' && *p_char != '/')
72 /* If the string ends with VLC then we've found a winner */
73 if ( !strcmp( p_char, "/VLCKit" ) )
75 p_char = strdup( psz_img_name );
83 size_t len = strlen(psz_img_name);
84 /* Do we end by "VLC"? If so we are the legacy VLC.app that doesn't
86 if( !strcmp( psz_img_name + len - 3, "VLC") )
88 p_char = strdup( psz_img_name );
95 /* We are not linked to the VLC.framework, let's use dladdr to figure
98 if( dladdr(system_Init, &info) )
99 p_char = strdup(dirname( info.dli_fname ));
103 char path[MAXPATHLEN+1];
104 uint32_t path_len = MAXPATHLEN;
105 if ( !_NSGetExecutablePath(path, &path_len) )
106 p_char = strdup(path);
110 psz_vlcpath = p_char;
112 /* Remove trailing program name */
125 /* Check if $LANG is set. */
126 if( NULL == getenv("LANG") )
129 Retrieve the preferred language as chosen in System Preferences.app
130 (note that CFLocaleCopyCurrent() is not used because it returns the
131 preferred locale not language)
133 CFArrayRef all_locales, preferred_locales;
136 all_locales = CFLocaleCopyAvailableLocaleIdentifiers();
138 preferred_locales = CFBundleCopyLocalizationsForPreferences( all_locales, NULL );
140 if ( preferred_locales )
142 if ( CFArrayGetCount( preferred_locales ) )
144 CFStringRef user_language_string_ref = CFArrayGetValueAtIndex( preferred_locales, 0 );
145 CFStringGetCString( user_language_string_ref, psz_locale, sizeof(psz_locale), kCFStringEncodingUTF8 );
146 setenv( "LANG", psz_locale, 1 );
148 CFRelease( preferred_locales );
150 CFRelease( all_locales );
155 /*****************************************************************************
156 * system_Configure: check for system specific configuration options.
157 *****************************************************************************/
158 void system_Configure( libvlc_int_t *p_this,
159 int i_argc, const char *const ppsz_argv[] )
166 /*****************************************************************************
167 * system_End: free the program path.
168 *****************************************************************************/
169 void system_End( void )