diff options
author | Andrey Smirnov <andrew.smirnov@gmail.com> | 2019-05-27 22:49:00 -0700 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2019-05-28 10:28:15 +0200 |
commit | ddf4cca3397910ed8a342c1f6443637f20bae718 (patch) | |
tree | 036da05982e99d869ced7faa2396e08f21505abd /commands/memcpy.c | |
parent | faf2ad1dc5a1a3fb131559c26675cecdd20b74a8 (diff) | |
download | barebox-ddf4cca3397910ed8a342c1f6443637f20bae718.tar.gz barebox-ddf4cca3397910ed8a342c1f6443637f20bae718.tar.xz |
commands: Introduce memcpy_parse_options()
Both memcpy and memcmp have identical options, so in order to share
code between them, introduce memcpy_parse_options() and change both
tools to use it.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/memcpy.c')
-rw-r--r-- | commands/memcpy.c | 41 |
1 files changed, 2 insertions, 39 deletions
diff --git a/commands/memcpy.c b/commands/memcpy.c index ef25fb7b23..5f0047f87c 100644 --- a/commands/memcpy.c +++ b/commands/memcpy.c @@ -34,53 +34,16 @@ #include <linux/stat.h> #include <xfuncs.h> -static char *devmem = "/dev/mem"; - static int do_memcpy(int argc, char *argv[]) { - loff_t count, dest, src; - char *sourcefile = devmem; - char *destfile = devmem; + loff_t count; int sourcefd, destfd; - int mode = 0; - struct stat statbuf; int ret = 0; char *buf; - if (mem_parse_options(argc, argv, "bwlqs:d:", &mode, &sourcefile, - &destfile, NULL) < 0) - return 1; - - if (optind + 2 > argc) - return COMMAND_ERROR_USAGE; - - src = strtoull_suffix(argv[optind], NULL, 0); - dest = strtoull_suffix(argv[optind + 1], NULL, 0); - - if (optind + 2 == argc) { - if (sourcefile == devmem) { - printf("source and count not given\n"); - return 1; - } - if (stat(sourcefile, &statbuf)) { - perror("stat"); - return 1; - } - count = statbuf.st_size - src; - } else { - count = strtoull_suffix(argv[optind + 2], NULL, 0); - } - - sourcefd = open_and_lseek(sourcefile, mode | O_RDONLY, src); - if (sourcefd < 0) + if (memcpy_parse_options(argc, argv, &sourcefd, &destfd, &count) < 0) return 1; - destfd = open_and_lseek(destfile, O_WRONLY | O_CREAT | mode, dest); - if (destfd < 0) { - close(sourcefd); - return 1; - } - buf = xmalloc(RW_BUF_SIZE); while (count > 0) { |