btrfs-progs: new helper for option parsing, more permissive for "no options"
authorDavid Sterba <dsterba@suse.com>
Thu, 16 Jun 2016 11:27:18 +0000 (13:27 +0200)
committerDavid Sterba <dsterba@suse.com>
Fri, 17 Jun 2016 15:01:25 +0000 (17:01 +0200)
Signed-off-by: David Sterba <dsterba@suse.com>
utils.c
utils.h

diff --git a/utils.c b/utils.c
index 72dc7d2..578fdb0 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -3930,6 +3930,24 @@ void clean_args_no_options(int argc, char *argv[], const char * const *usagestr)
        }
 }
 
+/*
+ * Same as clean_args_no_options but pass through arguments that could look
+ * like short options. Eg. reisze which takes a negative resize argument like
+ * '-123M' .
+ *
+ * This accepts only two forms:
+ * - "-- option1 option2 ..."
+ * - "option1 option2 ..."
+ */
+void clean_args_no_options_relaxed(int argc, char *argv[], const char * const *usagestr)
+{
+       if (argc <= 1)
+               return;
+
+       if (strcmp(argv[1], "--") == 0)
+               optind = 2;
+}
+
 /* Subvolume helper functions */
 /*
  * test if name is a correct subvolume name
diff --git a/utils.h b/utils.h
index c79f81e..98bfb34 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -303,6 +303,8 @@ const char *get_argv0_buf(void);
 
 unsigned int get_unit_mode_from_arg(int *argc, char *argv[], int df_mode);
 void clean_args_no_options(int argc, char *argv[], const char * const *usage);
+void clean_args_no_options_relaxed(int argc, char *argv[],
+               const char * const *usagestr);
 int string_is_numerical(const char *str);
 
 __attribute__ ((format (printf, 1, 2)))