summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--commands/mem.c40
-rw-r--r--lib/misc.c42
2 files changed, 42 insertions, 40 deletions
diff --git a/commands/mem.c b/commands/mem.c
index a9e12f3..62488bf 100644
--- a/commands/mem.c
+++ b/commands/mem.c
@@ -41,46 +41,6 @@
char *mem_rw_buf;
-/*
- * Common function for parsing options for the 'md', 'mw', 'memcpy', 'memcmp'
- * commands.
- */
-int mem_parse_options(int argc, char *argv[], char *optstr, int *mode,
- char **sourcefile, char **destfile, int *swab)
-{
- int opt;
-
- while((opt = getopt(argc, argv, optstr)) > 0) {
- switch(opt) {
- case 'b':
- *mode = O_RWSIZE_1;
- break;
- case 'w':
- *mode = O_RWSIZE_2;
- break;
- case 'l':
- *mode = O_RWSIZE_4;
- break;
- case 'q':
- *mode = O_RWSIZE_8;
- break;
- case 's':
- *sourcefile = optarg;
- break;
- case 'd':
- *destfile = optarg;
- break;
- case 'x':
- *swab = 1;
- break;
- default:
- return COMMAND_ERROR_USAGE;
- }
- }
-
- return 0;
-}
-
static struct cdev_operations memops = {
.read = mem_read,
.write = mem_write,
diff --git a/lib/misc.c b/lib/misc.c
index 1d20e1b..cd420a5 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -23,6 +23,7 @@
#include <fs.h>
#include <string.h>
#include <linux/ctype.h>
+#include <getopt.h>
/*
* Like simple_strtoull() but handles an optional G, M, K or k
@@ -129,3 +130,44 @@ success:
return 0;
}
EXPORT_SYMBOL(parse_area_spec);
+
+/*
+ * Common function for parsing options for the 'md', 'mw', 'memcpy', 'memcmp'
+ * commands.
+ */
+int mem_parse_options(int argc, char *argv[], char *optstr, int *mode,
+ char **sourcefile, char **destfile, int *swab)
+{
+ int opt;
+
+ while((opt = getopt(argc, argv, optstr)) > 0) {
+ switch(opt) {
+ case 'b':
+ *mode = O_RWSIZE_1;
+ break;
+ case 'w':
+ *mode = O_RWSIZE_2;
+ break;
+ case 'l':
+ *mode = O_RWSIZE_4;
+ break;
+ case 'q':
+ *mode = O_RWSIZE_8;
+ break;
+ case 's':
+ *sourcefile = optarg;
+ break;
+ case 'd':
+ *destfile = optarg;
+ break;
+ case 'x':
+ *swab = 1;
+ break;
+ default:
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
+