summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-02-13 20:31:47 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2019-02-13 20:31:47 +0100
commit314ad8e28161be580af1271bdaf05a4c6e7f6bd1 (patch)
treea98f1b35cddef99c60fc255bc1ae5408974fc19f /lib
parent3fe0effd52c960dc3dce0b731ef266113f2d1893 (diff)
parent504ac299a531a0bd601e6db05dc1c2d3b86a9700 (diff)
downloadbarebox-314ad8e28161be580af1271bdaf05a4c6e7f6bd1.tar.gz
barebox-314ad8e28161be580af1271bdaf05a4c6e7f6bd1.tar.xz
Merge branch 'for-next/lseek'
Diffstat (limited to 'lib')
-rw-r--r--lib/libfile.c3
-rw-r--r--lib/misc.c42
2 files changed, 43 insertions, 2 deletions
diff --git a/lib/libfile.c b/lib/libfile.c
index 8f2aed2309..9a223d2328 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -556,8 +556,7 @@ int open_and_lseek(const char *filename, int mode, loff_t pos)
}
}
- ret = lseek(fd, pos, SEEK_SET);
- if (ret == -1) {
+ if (lseek(fd, pos, SEEK_SET) != pos) {
perror("lseek");
close(fd);
return -errno;
diff --git a/lib/misc.c b/lib/misc.c
index 1d20e1b092..cd420a57d8 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;
+}
+