Returns now GNUNET_SYSERR
[oweals/gnunet.git] / src / util / getopt.c
index e069e76f7fe8f0a600256dd545d7d67b763fd1f5..e525525d7c07a21246dc49c46c45d80fbd54483b 100644 (file)
@@ -135,12 +135,6 @@ static char *GNoptarg = NULL;
 /* 1003.2 says this must be 1 before any call.  */
 static int GNoptind = 1;
 
-/* Formerly, initialization of getopt depended on GNoptind==0, which
-   causes problems with re-calling getopt as programs generally don't
-   know that. */
-
-static int __getopt_initialized = 0;
-
 /* The next char to be scanned in the option-element
    in which the last option character we returned was found.
    This allows us to pick up the scan where we left off.
@@ -150,16 +144,6 @@ static int __getopt_initialized = 0;
 
 static char *nextchar;
 
-/* Callers store zero here to inhibit the error message
-   for unrecognized options.  */
-
-static int GNopterr = 1;
-
-/* Set to an option character which was unrecognized.
-   This must be initialized on some systems to avoid linking in the
-   system's own getopt implementation.  */
-
-static int GNoptopt = '?';
 
 /* Describe how to deal with options that follow non-option ARGV-elements.
 
@@ -513,14 +497,17 @@ _getopt_initialize (argc, argv, optstring)
    long-named options.  */
 
 static int
-GN_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
-     int argc;
-     char *const *argv;
-     const char *optstring;
-     const struct GNoption *longopts;
-     int *longind;
-     int long_only;
+GN_getopt_internal (int argc,
+                   char *const *argv,
+                   const char *optstring,
+                   const struct GNoption *longopts,
+                   int *longind,
+                   int long_only)
 {
+  static int __getopt_initialized = 0;
+  static int GNopterr = 1;
+  static int GNoptopt = '?';
+
   GNoptarg = NULL;
 
   if (GNoptind == 0 || !__getopt_initialized)
@@ -847,6 +834,7 @@ GN_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
 
         /* Test all long options for either exact match
            or abbreviated matches.  */
+       if (longopts != NULL)
         for (p = longopts, option_index = 0; p->name; p++, option_index++)
           if (!strncmp (p->name, nextchar, nameend - nextchar))
             {
@@ -987,8 +975,7 @@ GNgetopt_long (int argc,
 /**
  * Parse the command line.
  *
- * @param binaryName name of the binary / application with options
- * @param cfg for storing/accessing configuration data
+ * @param binaryOptions Name of application with option summary
  * @param allOptions defined options and handlers
  * @param argc number of arguments
  * @param argv actual arguments
@@ -997,7 +984,6 @@ GNgetopt_long (int argc,
  */
 int
 GNUNET_GETOPT_run (const char *binaryOptions,
-                   struct GNUNET_CONFIGURATION_Handle *cfg,
                    const struct GNUNET_GETOPT_CommandLineOption *allOptions,
                    unsigned int argc, char *const *argv)
 {
@@ -1017,7 +1003,6 @@ GNUNET_GETOPT_run (const char *binaryOptions,
   clpc.allOptions = allOptions;
   clpc.argv = argv;
   clpc.argc = argc;
-  clpc.cfg = cfg;
   count = 0;
   while (allOptions[count].name != NULL)
     count++;
@@ -1038,7 +1023,7 @@ GNUNET_GETOPT_run (const char *binaryOptions,
   long_options[count].has_arg = 0;
   long_options[count].flag = NULL;
   long_options[count].val = '\0';
-  shorts[spos++] = '\0';
+  shorts[spos] = '\0';
   cont = GNUNET_OK;
   /* main getopt loop */
   while (cont == GNUNET_OK)