Fix klibc getopt_long_only() for optional arguments
authorJens Axboe <axboe@kernel.dk>
Tue, 18 Oct 2011 11:26:01 +0000 (13:26 +0200)
committerJens Axboe <axboe@kernel.dk>
Tue, 18 Oct 2011 11:26:01 +0000 (13:26 +0200)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
lib/getopt_long.c

index 6e8abc0..70894e3 100644 (file)
@@ -126,7 +126,16 @@ int getopt_long_only(int argc, char *const *argv, const char *optstring,
                        } else {
                                /* Argument-taking option with non-attached
                                   argument */
                        } 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 {
                                        optarg = (char *)argv[optind+1];
                                        optind += 2;
                                } else {