summaryrefslogtreecommitdiffstats
path: root/commands
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
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')
-rw-r--r--commands/crc.c2
-rw-r--r--commands/ls.c6
-rw-r--r--commands/mem.c10
-rw-r--r--commands/saveenv.c6
4 files changed, 11 insertions, 13 deletions
diff --git a/commands/crc.c b/commands/crc.c
index df229410f6..a0d3af63fa 100644
--- a/commands/crc.c
+++ b/commands/crc.c
@@ -48,7 +48,7 @@ static int file_crc(char* filename, ulong start, ulong size, ulong *crc,
if (start > 0) {
ret = lseek(fd, start, SEEK_SET);
- if (ret == -1) {
+ if (ret < 0) {
perror("lseek");
goto out;
}
diff --git a/commands/ls.c b/commands/ls.c
index c98d2dad57..ad609f3133 100644
--- a/commands/ls.c
+++ b/commands/ls.c
@@ -49,7 +49,7 @@ int ls(const char *path, ulong flags)
string_list_init(&sl);
if (stat(path, &s))
- return errno;
+ return -errno;
if (flags & LS_SHOWARG && s.st_mode & S_IFDIR)
printf("%s:\n", path);
@@ -61,7 +61,7 @@ int ls(const char *path, ulong flags)
dir = opendir(path);
if (!dir)
- return errno;
+ return -errno;
while ((d = readdir(dir))) {
sprintf(tmp, "%s/%s", path, d->d_name);
@@ -85,7 +85,7 @@ int ls(const char *path, ulong flags)
dir = opendir(path);
if (!dir) {
- errno = -ENOENT;
+ errno = ENOENT;
return -ENOENT;
}
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[] =
diff --git a/commands/saveenv.c b/commands/saveenv.c
index a4b279676d..549fcd4279 100644
--- a/commands/saveenv.c
+++ b/commands/saveenv.c
@@ -54,7 +54,7 @@ static int do_saveenv(int argc, char *argv[])
ret = protect(fd, ~0, 0, 0);
/* ENOSYS is no error here, many devices do not need it */
- if (ret && errno != -ENOSYS) {
+ if (ret && errno != ENOSYS) {
printf("could not unprotect %s: %s\n", filename, errno_str());
close(fd);
return 1;
@@ -63,7 +63,7 @@ static int do_saveenv(int argc, char *argv[])
ret = erase(fd, ~0, 0);
/* ENOSYS is no error here, many devices do not need it */
- if (ret && errno != -ENOSYS) {
+ if (ret && errno != ENOSYS) {
printf("could not erase %s: %s\n", filename, errno_str());
close(fd);
return 1;
@@ -82,7 +82,7 @@ static int do_saveenv(int argc, char *argv[])
ret = protect(fd, ~0, 0, 1);
/* ENOSYS is no error here, many devices do not need it */
- if (ret && errno != -ENOSYS) {
+ if (ret && errno != ENOSYS) {
printf("could not protect %s: %s\n", filename, errno_str());
close(fd);
return 1;