5 #include <linux/kernel.h>
6 #include <linux/string.h>
13 * ncp_getopt - option parser
14 * @caller: name of the caller, for error messages
15 * @options: the options string
16 * @opts: an array of &struct option entries controlling parser operations
17 * @optopt: output; will contain the current option
18 * @optarg: output; will contain the value (if one exists)
19 * @flag: output; may be NULL; should point to a long for or'ing flags
20 * @value: output; may be NULL; will be overwritten with the integer value
21 * of the current argument.
23 * Helper to parse options on the format used by mount ("a=b,c=d,e,f").
24 * Returns opts->val if a matching entry in the 'opts' array is found,
25 * 0 when no more tokens are found, -1 if an error is encountered.
27 int ncp_getopt(const char *caller, char **options, const struct ncp_option *opts,
28 char **optopt, char **optarg, unsigned long *value)
34 if ((token = strsep(options, ",")) == NULL)
36 } while (*token == '\0');
40 if ((val = strchr (token, '=')) != NULL) {
44 for (; opts->name; opts++) {
45 if (!strcmp(opts->name, token)) {
47 if (opts->has_arg & OPT_NOPARAM) {
50 printk(KERN_INFO "%s: the %s option requires an argument\n",
54 if (opts->has_arg & OPT_INT) {
57 *value = simple_strtoul(val, &v, 0);
61 printk(KERN_INFO "%s: invalid numeric value in %s=%s\n",
65 if (opts->has_arg & OPT_STRING) {
68 printk(KERN_INFO "%s: unexpected argument %s to the %s option\n",
73 printk(KERN_INFO "%s: Unrecognized mount option %s\n", caller, token);