aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ncpfs/getopt.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /fs/ncpfs/getopt.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'fs/ncpfs/getopt.c')
-rw-r--r--fs/ncpfs/getopt.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/fs/ncpfs/getopt.c b/fs/ncpfs/getopt.c
new file mode 100644
index 000000000000..335b003dddf9
--- /dev/null
+++ b/fs/ncpfs/getopt.c
@@ -0,0 +1,75 @@
1/*
2 * getopt.c
3 */
4
5#include <linux/kernel.h>
6#include <linux/string.h>
7
8#include <asm/errno.h>
9
10#include "getopt.h"
11
12/**
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.
22 *
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.
26 */
27int ncp_getopt(const char *caller, char **options, const struct ncp_option *opts,
28 char **optopt, char **optarg, unsigned long *value)
29{
30 char *token;
31 char *val;
32
33 do {
34 if ((token = strsep(options, ",")) == NULL)
35 return 0;
36 } while (*token == '\0');
37 if (optopt)
38 *optopt = token;
39
40 if ((val = strchr (token, '=')) != NULL) {
41 *val++ = 0;
42 }
43 *optarg = val;
44 for (; opts->name; opts++) {
45 if (!strcmp(opts->name, token)) {
46 if (!val) {
47 if (opts->has_arg & OPT_NOPARAM) {
48 return opts->val;
49 }
50 printk(KERN_INFO "%s: the %s option requires an argument\n",
51 caller, token);
52 return -EINVAL;
53 }
54 if (opts->has_arg & OPT_INT) {
55 char* v;
56
57 *value = simple_strtoul(val, &v, 0);
58 if (!*v) {
59 return opts->val;
60 }
61 printk(KERN_INFO "%s: invalid numeric value in %s=%s\n",
62 caller, token, val);
63 return -EDOM;
64 }
65 if (opts->has_arg & OPT_STRING) {
66 return opts->val;
67 }
68 printk(KERN_INFO "%s: unexpected argument %s to the %s option\n",
69 caller, val, token);
70 return -EINVAL;
71 }
72 }
73 printk(KERN_INFO "%s: Unrecognized mount option %s\n", caller, token);
74 return -EOPNOTSUPP;
75}