diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2019-06-11 11:33:34 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2019-06-11 11:33:34 +0200 |
commit | 06b8bc4d708b8ff4eba1dd9b48ec110a8019d2c8 (patch) | |
tree | 3c7c238c81aa91405159959906f31f6195aa6217 /commands | |
parent | b697fba4a5c5395a9db271efa286870191418040 (diff) | |
parent | b917f7864115a35fbb9e69af2c1d553a110a37fc (diff) | |
download | barebox-06b8bc4d708b8ff4eba1dd9b48ec110a8019d2c8.tar.gz barebox-06b8bc4d708b8ff4eba1dd9b48ec110a8019d2c8.tar.xz |
Merge branch 'for-next/misc'
Diffstat (limited to 'commands')
-rw-r--r-- | commands/memcmp.c | 41 | ||||
-rw-r--r-- | commands/memcpy.c | 41 |
2 files changed, 4 insertions, 78 deletions
diff --git a/commands/memcmp.c b/commands/memcmp.c index 48957b4500..d1c4f5205d 100644 --- a/commands/memcmp.c +++ b/commands/memcmp.c @@ -34,54 +34,17 @@ #include <linux/stat.h> #include <xfuncs.h> -static char *devmem = "/dev/mem"; - static int do_memcmp(int argc, char *argv[]) { - loff_t addr1, addr2, count = ~0; - int mode = O_RWSIZE_1; - char *sourcefile = devmem; - char *destfile = devmem; + loff_t count; int sourcefd, destfd; char *buf, *source_data, *dest_data; int ret = 1; int offset = 0; - struct stat statbuf; - - if (mem_parse_options(argc, argv, "bwlqs:d:", &mode, &sourcefile, - &destfile, NULL) < 0) - return 1; - - if (optind + 2 > argc) - return COMMAND_ERROR_USAGE; - - addr1 = strtoull_suffix(argv[optind], NULL, 0); - addr2 = 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 - addr1; - } else { - count = strtoull_suffix(argv[optind + 2], NULL, 0); - } - sourcefd = open_and_lseek(sourcefile, mode | O_RDONLY, addr1); - if (sourcefd < 0) + if (memcpy_parse_options(argc, argv, &sourcefd, &destfd, &count) < 0) return 1; - destfd = open_and_lseek(destfile, mode | O_RDONLY, addr2); - if (destfd < 0) { - close(sourcefd); - return 1; - } - buf = xmalloc(RW_BUF_SIZE + RW_BUF_SIZE); source_data = buf; dest_data = buf + RW_BUF_SIZE; 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) { |