/* * getopt.c */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/kernel.h> #include <linux/string.h> #include <asm/errno.h> #include "getopt.h" /** * ncp_getopt - option parser * @caller: name of the caller, for error messages * @options: the options string * @opts: an array of &struct option entries controlling parser operations * @optopt: output; will contain the current option * @optarg: output; will contain the value (if one exists) * @value: output; may be NULL; will be overwritten with the integer value * of the current argument. * * Helper to parse options on the format used by mount ("a=b,c=d,e,f"). * Returns opts->val if a matching entry in the 'opts' array is found, * 0 when no more tokens are found, -1 if an error is encountered. */ int ncp_getopt(const char *caller, char **options, const struct ncp_option *opts, char **optopt, char **optarg, unsigned long *value) { char *token; char *val; do { if ((token = strsep(options, ",")) == NULL) return 0; } while (*token == '\0'); if (optopt) *optopt = token; if ((val = strchr (token, '=')) != NULL) { *val++ = 0; } *optarg = val; for (; opts->name; opts++) { if (!strcmp(opts->name, token)) { if (!val) { if (opts->has_arg & OPT_NOPARAM) { return opts->val; } pr_info("%s: the %s option requires an argument\n", caller, token); return -EINVAL; } if (opts->has_arg & OPT_INT) { int rc = kstrtoul(val, 0, value); if (rc) { pr_info("%s: invalid numeric value in %s=%s\n", caller, token, val); return rc; } return opts->val; } if (opts->has_arg & OPT_STRING) { return opts->val; } pr_info("%s: unexpected argument %s to the %s option\n", caller, val, token); return -EINVAL; } } pr_info("%s: Unrecognized mount option %s\n", caller, token); return -EOPNOTSUPP; } a href='/cgit.cgi/linux/net-next.git/commit/sound/soc/qcom/lpass-platform.c?id=740117a8e2b0e89c5fd6f1d5bbc12f87c46c80d7'>commit</a><a href='/cgit.cgi/linux/net-next.git/diff/sound/soc/qcom/lpass-platform.c?id=740117a8e2b0e89c5fd6f1d5bbc12f87c46c80d7'>diff</a></td><td class='form'><form class='right' method='get' action='/cgit.cgi/linux/net-next.git/log/sound/soc/qcom/lpass-platform.c'> <input type='hidden' name='id' value='740117a8e2b0e89c5fd6f1d5bbc12f87c46c80d7'/><select name='qt'> <option value='grep'>log msg</option> <option value='author'>author</option> <option value='committer'>committer</option> <option value='range'>range</option> </select> <input class='txt' type='search' size='10' name='q' value=''/> <input type='submit' value='search'/> </form> </td></tr></table> <div class='path'>path: <a href='/cgit.cgi/linux/net-next.git/log/?id=740117a8e2b0e89c5fd6f1d5bbc12f87c46c80d7'>root</a>/<a href='/cgit.cgi/linux/net-next.git/log/sound?id=740117a8e2b0e89c5fd6f1d5bbc12f87c46c80d7'>sound</a>/<a href='/cgit.cgi/linux/net-next.git/log/sound/soc?id=740117a8e2b0e89c5fd6f1d5bbc12f87c46c80d7'>soc</a>/<a href='/cgit.cgi/linux/net-next.git/log/sound/soc/qcom?id=740117a8e2b0e89c5fd6f1d5bbc12f87c46c80d7'>qcom</a>/<a href='/cgit.cgi/linux/net-next.git/log/sound/soc/qcom/lpass-platform.c?id=740117a8e2b0e89c5fd6f1d5bbc12f87c46c80d7'>lpass-platform.c</a></div><div class='content'><table class='list nowrap'><tr class='nohover'><th class='left'>Age</th><th class='left'>Commit message (<a href='/cgit.cgi/linux/net-next.git/log/sound/soc/qcom/lpass-platform.c?id=740117a8e2b0e89c5fd6f1d5bbc12f87c46c80d7&showmsg=1'>Expand</a>)</th><th class='left'>Author</th><th class='left'>Files</th><th class='left'>Lines</th></tr>