Fix klibc getopt_long_only() for optional arguments
[fio.git] / lib / getopt_long.c
index 3d80627f5395c6bba4d5d28ac73170c46290e198..70894e3281e04f7830cc583c2079affb9c545518 100644 (file)
@@ -6,12 +6,15 @@
  * - Option reordering is not supported
  * - -W foo is not supported
  * - First optstring character "-" not supported.
+ *
+ * This file was imported from the klibc library from hpa
  */
 
 #include <stdint.h>
 #include <unistd.h>
 #include <string.h>
-#include <getopt.h>
+
+#include "getopt.h"
 
 char *optarg;
 int optind, opterr, optopt;
@@ -123,7 +126,16 @@ int getopt_long_only(int argc, char *const *argv, const char *optstring,
                        } else {
                                /* Argument-taking option with non-attached
                                   argument */
-                               if (argv[optind + 1]) {
+                               if (osptr[2] == ':') {
+                                       if (argv[optind + 1]) {
+                                               optarg = (char *)argv[optind+1];
+                                               optind += 2;
+                                       } else {
+                                               optarg = NULL;
+                                               optind++;
+                                       }
+                                       return opt;
+                               } else if (argv[optind + 1]) {
                                        optarg = (char *)argv[optind+1];
                                        optind += 2;
                                } else {