summaryrefslogtreecommitdiffstats
path: root/commands/mem.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2012-05-13 12:43:58 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2012-05-14 08:35:54 +0200
commit6188685091c58c9772b990cf0ca6ac522f97a9d0 (patch)
treeff994e79773e3bab5abe1b79129cbb08ddf9f754 /commands/mem.c
parent2f05b6925676e5f3263e0d51ed2f0a92201400d8 (diff)
downloadbarebox-6188685091c58c9772b990cf0ca6ac522f97a9d0.tar.gz
barebox-6188685091c58c9772b990cf0ca6ac522f97a9d0.tar.xz
Make errno a positive value
Normally errno contains a positive error value. A certain unnamed developer mixed this up while implementing U-Boot-v2. Also, normally errno is never set to zero by any library function. This patch fixes this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/mem.c')
-rw-r--r--commands/mem.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/commands/mem.c b/commands/mem.c
index d8e90e056f..f32e5d8299 100644
--- a/commands/mem.c
+++ b/commands/mem.c
@@ -122,7 +122,7 @@ static int open_and_lseek(const char *filename, int mode, off_t pos)
return fd;
ret = lseek(fd, pos, SEEK_SET);
- if (ret == -1) {
+ if (ret < 0) {
perror("lseek");
close(fd);
return ret;
@@ -170,7 +170,6 @@ static int do_mem_md(int argc, char *argv[])
char *filename = DEVMEM;
int mode = O_RWSIZE_4;
- errno = 0;
if (mem_parse_options(argc, argv, "bwls:", &mode, &filename, NULL) < 0)
return 1;
@@ -207,7 +206,7 @@ static int do_mem_md(int argc, char *argv[])
out:
close(fd);
- return errno;
+ return ret ? 1 : 0;
}
static const __maybe_unused char cmd_md_help[] =
@@ -243,8 +242,6 @@ static int do_mem_mw(int argc, char *argv[])
int mode = O_RWSIZE_4;
ulong adr;
- errno = 0;
-
if (mem_parse_options(argc, argv, "bwld:", &mode, NULL, &filename) < 0)
return 1;
@@ -279,12 +276,13 @@ static int do_mem_mw(int argc, char *argv[])
perror("write");
break;
}
+ ret = 0;
optind++;
}
close(fd);
- return errno;
+ return ret ? 1 : 0;
}
static const __maybe_unused char cmd_mw_help[] =