2 * lifted from fs/ncpfs/getopt.c
9 #include <linux/kernel.h>
10 #include <linux/string.h>
15 * krping_getopt - option parser
16 * @caller: name of the caller, for error messages
17 * @options: the options string
18 * @opts: an array of &struct option entries controlling parser operations
19 * @optopt: output; will contain the current option
20 * @optarg: output; will contain the value (if one exists)
21 * @flag: output; may be NULL; should point to a long for or'ing flags
22 * @value: output; may be NULL; will be overwritten with the integer value
23 * of the current argument.
25 * Helper to parse options on the format used by mount ("a=b,c=d,e,f").
26 * Returns opts->val if a matching entry in the 'opts' array is found,
27 * 0 when no more tokens are found, -1 if an error is encountered.
29 int krping_getopt(const char *caller, char **options,
30 const struct krping_option *opts, char **optopt,
31 char **optarg, unsigned long *value)
37 if ((token = strsep(options, ",")) == NULL)
39 } while (*token == '\0');
43 if ((val = strchr (token, '=')) != NULL) {
47 for (; opts->name; opts++) {
48 if (!strcmp(opts->name, token)) {
50 if (opts->has_arg & OPT_NOPARAM) {
53 printk(KERN_INFO "%s: the %s option requires "
54 "an argument\n", caller, token);
57 if (opts->has_arg & OPT_INT) {
60 *value = simple_strtoul(val, &v, 0);
64 printk(KERN_INFO "%s: invalid numeric value "
65 "in %s=%s\n", caller, token, val);
68 if (opts->has_arg & OPT_STRING) {
71 printk(KERN_INFO "%s: unexpected argument %s to the "
72 "%s option\n", caller, val, token);
76 printk(KERN_INFO "%s: Unrecognized option %s\n", caller, token);