From abc3d1544b8eac3ec6b28c08f4a1bb34c37ab0f3 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 24 Aug 2010 16:17:16 +0200 Subject: [PATCH] libmount: cleanup return codes (cache.c) Signed-off-by: Karel Zak --- shlibs/mount/src/cache.c | 25 +++++++++++++------------ shlibs/mount/src/lock.c | 2 +- shlibs/mount/src/mountP.h | 1 + shlibs/mount/src/optstr.c | 4 ++-- shlibs/mount/src/test.c | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/shlibs/mount/src/cache.c b/shlibs/mount/src/cache.c index 027fda44..7e5c4afe 100644 --- a/shlibs/mount/src/cache.c +++ b/shlibs/mount/src/cache.c @@ -111,7 +111,7 @@ static int mnt_cache_add_entry(mnt_cache *cache, char *native, e = realloc(cache->ents, sz * sizeof(struct mnt_cache_entry)); if (!e) - return -1; + return -ENOMEM; cache->ents = e; cache->nallocs = sz; } @@ -136,6 +136,7 @@ static int mnt_cache_add_tag(mnt_cache *cache, const char *token, { size_t tksz, vlsz; char *native; + int rc; assert(cache); assert(real); @@ -151,17 +152,17 @@ static int mnt_cache_add_tag(mnt_cache *cache, const char *token, native = malloc(tksz + vlsz + 2); if (!native) - goto error; + return -ENOMEM; memcpy(native, token, tksz + 1); /* include '\0' */ memcpy(native + tksz + 1, value, vlsz + 1); - if (mnt_cache_add_entry(cache, native, real, flag | MNT_CACHE_ISTAG)) - goto error; - return 0; -error: + rc = mnt_cache_add_entry(cache, native, real, flag | MNT_CACHE_ISTAG); + if (!rc) + return 0; + free(native); - return -1; + return rc; } @@ -234,7 +235,7 @@ const char *mnt_cache_find_tag(mnt_cache *cache, * Reads @devname LABEL and UUID to the @cache. * * Returns: 0 if at least one tag was added, 1 if no tag was added or - * -1 in case of error. + * negative number in case of error. */ int mnt_cache_read_tags(mnt_cache *cache, const char *devname) { @@ -246,7 +247,7 @@ int mnt_cache_read_tags(mnt_cache *cache, const char *devname) assert(devname); if (!cache || !devname) - return -1; + return -EINVAL; DBG(DEBUG_CACHE, printf("cache: tags for %s requested\n", devname)); @@ -477,7 +478,7 @@ int test_resolve_path(struct mtest *ts, int argc, char *argv[]) cache = mnt_new_cache(); if (!cache) - return -1; + return -ENOMEM; while(fgets(line, sizeof(line), stdin)) { size_t sz = strlen(line); @@ -500,7 +501,7 @@ int test_resolve_spec(struct mtest *ts, int argc, char *argv[]) cache = mnt_new_cache(); if (!cache) - return -1; + return -ENOMEM; while(fgets(line, sizeof(line), stdin)) { size_t sz = strlen(line); @@ -523,7 +524,7 @@ int test_read_tags(struct mtest *ts, int argc, char *argv[]) cache = mnt_new_cache(); if (!cache) - return -1; + return -ENOMEM; while(fgets(line, sizeof(line), stdin)) { size_t sz = strlen(line); diff --git a/shlibs/mount/src/lock.c b/shlibs/mount/src/lock.c index beea2398..9d271828 100644 --- a/shlibs/mount/src/lock.c +++ b/shlibs/mount/src/lock.c @@ -505,7 +505,7 @@ int test_lock(struct mtest *ts, int argc, char *argv[]) if (!lock) return -1; - if (mnt_lock_file(lock) == -1) { + if (mnt_lock_file(lock) != 0) { fprintf(stderr, "%d: failed to lock %s file\n", getpid(), datafile); return -1; diff --git a/shlibs/mount/src/mountP.h b/shlibs/mount/src/mountP.h index d962b679..444d0d77 100644 --- a/shlibs/mount/src/mountP.h +++ b/shlibs/mount/src/mountP.h @@ -11,6 +11,7 @@ #define _LIBMOUNT_PRIVATE_H #include +#include #include "c.h" #define USE_UNSTABLE_LIBMOUNT_API diff --git a/shlibs/mount/src/optstr.c b/shlibs/mount/src/optstr.c index 853f5f9b..ffa93f20 100644 --- a/shlibs/mount/src/optstr.c +++ b/shlibs/mount/src/optstr.c @@ -279,9 +279,9 @@ int mnt_optstr_set_option(char **optstr, const char *name, const char *value) if (*optstr) rc = mnt_optstr_locate_option(*optstr, name, &begin, &end, &val, &valsz); - if (rc == -1) + if (rc < 0) /* parse error */ - return -1; + return rc; if (rc == 1) /* not found */ return mnt_optstr_append_option(optstr, name, value); diff --git a/shlibs/mount/src/test.c b/shlibs/mount/src/test.c index eb4f2d1d..ac2ab175 100644 --- a/shlibs/mount/src/test.c +++ b/shlibs/mount/src/test.c @@ -42,7 +42,7 @@ int mnt_run_test(struct mtest *tests, int argc, char *argv[]) } } - if (rc == -1 && ts->name == NULL) + if (rc < 0 && ts->name == NULL) goto usage; return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE; -- 2.39.5