]> git.sesse.net Git - vlc/blobdiff - src/config/cmdline.c
Always build and use "our" getopt
[vlc] / src / config / cmdline.c
index 98da1ad3df6683d3c5d4e7e9b33c29a00dce9f13..5316e8288645be197283cff03d4312325034ad39 100644 (file)
 #include <vlc_keys.h>
 #include <vlc_charset.h>
 
-#ifdef HAVE_GETOPT_LONG
-#   ifdef HAVE_GETOPT_H
-#       include <getopt.h>                                       /* getopt() */
-#   endif
-#else
-#   include "../extras/getopt.h"
-#endif
+#include "../extras/getopt.h"
 
 #include "configuration.h"
 #include "modules/modules.h"
 #include <assert.h>
 
 #undef config_LoadCmdLine
-/*****************************************************************************
- * config_LoadCmdLine: parse command line
- *****************************************************************************
+/**
  * Parse command line for configuration options.
+ *
  * Now that the module_bank has been initialized, we can dynamically
  * generate the longopts structure used by getops. We have to do it this way
  * because we don't know (and don't want to know) in advance the configuration
  * options used (ie. exported) by each module.
- *****************************************************************************/
+ *
+ * @param p_this object to write command line options as variables to
+ * @param pi_argc number of command line arguments [IN/OUT]
+ * @param ppsz_args commandl ine arguments [IN/OUT]
+ * @param b_ignore_errors whether to ignore parsing errors
+ * @return 0 on success, -1 on error.
+ *
+ * @warning This function is not re-entrant (because of getopt_long()).
+ * It must be called with the module bank initialization global lock held.
+ * FIXME: this still breaks if getopt() is used outside of LibVLC.
+ */
 int config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc,
                         const char *ppsz_argv[], bool b_ignore_errors )
 {
@@ -210,7 +213,7 @@ int config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc,
      */
     opterr = 0;
     optind = 0; /* set to 0 to tell GNU getopt to reinitialize */
-    while( ( i_cmd = getopt_long( *pi_argc, (char **)ppsz_argv, psz_shortopts,
+    while( ( i_cmd = vlc_getopt_long( *pi_argc, (char **)ppsz_argv, psz_shortopts,
                                   p_longopts, &i_index ) ) != -1 )
     {
         /* A long option has been recognized */