diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-05-13 12:43:58 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-05-14 08:35:54 +0200 |
commit | 6188685091c58c9772b990cf0ca6ac522f97a9d0 (patch) | |
tree | ff994e79773e3bab5abe1b79129cbb08ddf9f754 /lib | |
parent | 2f05b6925676e5f3263e0d51ed2f0a92201400d8 (diff) | |
download | barebox-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 'lib')
-rw-r--r-- | lib/make_directory.c | 13 | ||||
-rw-r--r-- | lib/parameter.c | 16 |
2 files changed, 17 insertions, 12 deletions
diff --git a/lib/make_directory.c b/lib/make_directory.c index 274bc146cf..c14c86d45b 100644 --- a/lib/make_directory.c +++ b/lib/make_directory.c @@ -12,6 +12,7 @@ int make_directory(const char *dir) char *s = strdup(dir); char *path = s; char c; + int ret = 0; do { c = 0; @@ -33,12 +34,10 @@ int make_directory(const char *dir) /* If we failed for any other reason than the directory * already exists, output a diagnostic and return -1.*/ -#ifdef __BAREBOX__ - if (errno != -EEXIST) -#else - if (errno != EEXIST) -#endif + if (errno != EEXIST) { + ret = -errno; break; + } } if (!c) goto out; @@ -50,7 +49,9 @@ int make_directory(const char *dir) out: free(path); - return errno; + if (ret) + errno = -ret; + return ret; } #ifdef __BAREBOX__ EXPORT_SYMBOL(make_directory); diff --git a/lib/parameter.c b/lib/parameter.c index c75c21e768..b2b8d945a6 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -54,7 +54,7 @@ const char *dev_get_param(struct device_d *dev, const char *name) struct param_d *param = get_param_by_name(dev, name); if (!param) { - errno = -EINVAL; + errno = EINVAL; return NULL; } @@ -87,26 +87,30 @@ int dev_set_param_ip(struct device_d *dev, char *name, IPaddr_t ip) int dev_set_param(struct device_d *dev, const char *name, const char *val) { struct param_d *param; + int ret; if (!dev) { - errno = -ENODEV; + errno = ENODEV; return -ENODEV; } param = get_param_by_name(dev, name); if (!param) { - errno = -EINVAL; + errno = EINVAL; return -EINVAL; } if (param->flags & PARAM_FLAG_RO) { - errno = -EACCES; + errno = EACCES; return -EACCES; } - errno = param->set(dev, param, val); - return errno; + ret = param->set(dev, param, val); + if (ret) + errno = -ret; + + return ret; } /** |