From 7f42e055f359bbb4d136c1b5c554baa2b23b52a2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sun, 21 Oct 2007 11:06:37 +0000 Subject: [PATCH] Changing the order of parameters may be needed, but changing the parameters themselves is definitely not (it would crash in some cases anyway): add some const qualifiers --- include/main.h | 2 +- include/vlc/vlc.h | 2 +- src/control/core.c | 9 ++++++++- src/control/libvlc_internal.h | 2 +- src/libvlc-common.c | 9 +++++---- src/libvlc.c | 2 +- src/modules/configuration.c | 7 ++++--- src/modules/configuration.h | 2 +- src/vlc.c | 2 +- 9 files changed, 23 insertions(+), 14 deletions(-) diff --git a/include/main.h b/include/main.h index 69e290db18..29e90605d6 100644 --- a/include/main.h +++ b/include/main.h @@ -37,7 +37,7 @@ struct libvlc_int_t /* Global properties */ int i_argc; ///< command line arguments count - char ** ppsz_argv; ///< command line arguments + const char ** ppsz_argv; ///< command line arguments char * psz_homedir; ///< user's home directory char * psz_configdir; ///< user's configuration directory diff --git a/include/vlc/vlc.h b/include/vlc/vlc.h index 06f3f0b4f3..d8e00dcd9e 100644 --- a/include/vlc/vlc.h +++ b/include/vlc/vlc.h @@ -250,7 +250,7 @@ VLC_PUBLIC_API int VLC_Create( void ); * \param ppsz_argv an array of arguments * \return VLC_SUCCESS on success */ -VLC_PUBLIC_API int VLC_Init( int, int, char *[] ); +VLC_PUBLIC_API int VLC_Init( int, int, const char *[] ); /** * Add an interface diff --git a/src/control/core.c b/src/control/core.c index a079e2e6bf..d52023597f 100644 --- a/src/control/core.c +++ b/src/control/core.c @@ -90,10 +90,17 @@ libvlc_instance_t * libvlc_new( int argc, const char *const *argv, p_new = (libvlc_instance_t *)malloc( sizeof( libvlc_instance_t ) ); if( !p_new ) RAISENULL( "Out of memory" ); + const char *my_argv[argc + 2]; + + my_argv[0] = "libvlc"; /* dummy arg0, skipped by getopt() et al */ + for( int i = 0; i < argc; i++ ) + my_argv[i + 1] = argv[i]; + my_argv[argc + 1] = NULL; /* C calling conventions require a NULL */ + /** \todo Look for interface settings. If we don't have any, add -I dummy */ /* Because we probably don't want a GUI by default */ - if( libvlc_InternalInit( p_libvlc_int, argc, argv ) ) + if( libvlc_InternalInit( p_libvlc_int, argc + 1, my_argv ) ) RAISENULL( "VLC initialization failed" ); p_new->p_libvlc_int = p_libvlc_int; diff --git a/src/control/libvlc_internal.h b/src/control/libvlc_internal.h index 6f07ce07d5..f6aa779e6d 100644 --- a/src/control/libvlc_internal.h +++ b/src/control/libvlc_internal.h @@ -39,7 +39,7 @@ extern "C" { * Internal creation and destruction functions ***************************************************************************/ VLC_EXPORT (libvlc_int_t *, libvlc_InternalCreate, ( void ) ); -VLC_EXPORT (int, libvlc_InternalInit, ( libvlc_int_t *, int, char *ppsz_argv[] ) ); +VLC_EXPORT (int, libvlc_InternalInit, ( libvlc_int_t *, int, const char *ppsz_argv[] ) ); VLC_EXPORT (int, libvlc_InternalCleanup, ( libvlc_int_t * ) ); VLC_EXPORT (int, libvlc_InternalDestroy, ( libvlc_int_t *, vlc_bool_t ) ); diff --git a/src/libvlc-common.c b/src/libvlc-common.c index e087faf8eb..e3df03e4fc 100644 --- a/src/libvlc-common.c +++ b/src/libvlc-common.c @@ -105,7 +105,7 @@ static volatile unsigned int i_instances = 0; static void SetLanguage ( char const * ); #endif static inline int LoadMessages (void); -static int GetFilenames ( libvlc_int_t *, int, char *[] ); +static int GetFilenames ( libvlc_int_t *, int, const char *[] ); static void Help ( libvlc_int_t *, char const *psz_help_name ); static void Usage ( libvlc_int_t *, char const *psz_module_name ); static void ListModules ( libvlc_int_t *, vlc_bool_t ); @@ -235,7 +235,8 @@ libvlc_int_t * libvlc_InternalCreate( void ) * - message queue, module bank and playlist initialization * - configuration and commandline parsing */ -int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] ) +int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, + const char *ppsz_argv[] ) { char p_capabilities[200]; char * p_tmp = NULL; @@ -1238,7 +1239,7 @@ static inline int LoadMessages (void) * Parse command line for input files as well as their associated options. * An option always follows its associated input and begins with a ":". *****************************************************************************/ -static int GetFilenames( libvlc_int_t *p_vlc, int i_argc, char *ppsz_argv[] ) +static int GetFilenames( libvlc_int_t *p_vlc, int i_argc, const char *ppsz_argv[] ) { int i_opt, i_options; @@ -1259,7 +1260,7 @@ static int GetFilenames( libvlc_int_t *p_vlc, int i_argc, char *ppsz_argv[] ) * unnecessary lookups. */ VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[i_opt], - (char const **)( i_options ? &ppsz_argv[i_opt + 1] : + ( i_options ? &ppsz_argv[i_opt + 1] : NULL ), i_options, PLAYLIST_INSERT, 0 ); } diff --git a/src/libvlc.c b/src/libvlc.c index 00cc81d9e0..d62a2a9e5a 100644 --- a/src/libvlc.c +++ b/src/libvlc.c @@ -115,7 +115,7 @@ int VLC_Create( void ) * - message queue, module bank and playlist initialization * - configuration and commandline parsing *****************************************************************************/ -int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) +int VLC_Init( int i_object, int i_argc, const char *ppsz_argv[] ) { int i_ret; LIBVLC_FUNC; diff --git a/src/modules/configuration.c b/src/modules/configuration.c index e47539c79d..a5b82fcfea 100644 --- a/src/modules/configuration.c +++ b/src/modules/configuration.c @@ -1401,7 +1401,8 @@ int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name ) * because we don't know (and don't want to know) in advance the configuration * options used (ie. exported) by each module. *****************************************************************************/ -int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[], +int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, + const char *ppsz_argv[], vlc_bool_t b_ignore_errors ) { int i_cmd, i_index, i_opts, i_shortopts, flag, i_verbose = 0; @@ -1480,7 +1481,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[], * us, ignoring the arity of the options */ if( b_ignore_errors ) { - ppsz_argv = (char**)malloc( *pi_argc * sizeof(char *) ); + ppsz_argv = (const char**)malloc( *pi_argc * sizeof(char *) ); if( ppsz_argv == NULL ) { msg_Err( p_this, "out of memory" ); @@ -1588,7 +1589,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[], */ opterr = 0; optind = 0; /* set to 0 to tell GNU getopt to reinitialize */ - while( ( i_cmd = getopt_long( *pi_argc, ppsz_argv, psz_shortopts, + while( ( i_cmd = getopt_long( *pi_argc, (char **)ppsz_argv, psz_shortopts, p_longopts, &i_index ) ) != -1 ) { /* A long option has been recognized */ diff --git a/src/modules/configuration.h b/src/modules/configuration.h index 038d65f70b..3e02b6be20 100644 --- a/src/modules/configuration.h +++ b/src/modules/configuration.h @@ -42,7 +42,7 @@ void config_UnsetCallbacks( module_config_t *, size_t ); #define config_LoadCmdLine(a,b,c,d) __config_LoadCmdLine(VLC_OBJECT(a),b,c,d) #define config_LoadConfigFile(a,b) __config_LoadConfigFile(VLC_OBJECT(a),b) -int __config_LoadCmdLine ( vlc_object_t *, int *, char *[], vlc_bool_t ); +int __config_LoadCmdLine ( vlc_object_t *, int *, const char *[], vlc_bool_t ); char *config_GetHomeDir ( void ); char *config_GetConfigDir ( libvlc_int_t * ); char *config_GetUserDataDir( libvlc_int_t * ); diff --git a/src/vlc.c b/src/vlc.c index f1d34dcfd9..77dd66f429 100644 --- a/src/vlc.c +++ b/src/vlc.c @@ -59,7 +59,7 @@ static void *SigHandler (void *set); /***************************************************************************** * main: parse command line, start interface and spawn threads. *****************************************************************************/ -int main( int i_argc, char *ppsz_argv[] ) +int main( int i_argc, const char *ppsz_argv[] ) { int i_ret; -- 2.39.2