Return -E_OSL_NOENT if stat/open fails with errno == ENOENT.
authorAndre Noll <maan@systemlinux.org>
Fri, 12 Jun 2009 19:54:19 +0000 (21:54 +0200)
committerAndre Noll <maan@systemlinux.org>
Fri, 12 Jun 2009 19:54:19 +0000 (21:54 +0200)
This often indicates a non-fatal error, so callers might want to
know.

osl.c
util.c
util.h

diff --git a/osl.c b/osl.c
index 5b9308e4bec25185134724a10fe3d8eb2023d84d..a9dcc29bd48790ff93d54027aa2052bc373c6373 100644 (file)
--- a/osl.c
+++ b/osl.c
@@ -1067,12 +1067,10 @@ __export int osl_open_table(const struct osl_table_description *table_desc,
                if (!dirname)
                        goto err;
                /* check if directory exists */
                if (!dirname)
                        goto err;
                /* check if directory exists */
-               ret = stat(dirname, &statbuf);
+               ret = osl_stat(dirname, &statbuf);
                free(dirname);
                free(dirname);
-               if (ret < 0) {
-                       ret = -E_OSL_STAT;
+               if (ret < 0)
                        goto err;
                        goto err;
-               }
                ret = -E_OSL_NOTDIR;
                if (!S_ISDIR(statbuf.st_mode))
                        goto err;
                ret = -E_OSL_NOTDIR;
                if (!S_ISDIR(statbuf.st_mode))
                        goto err;
diff --git a/util.c b/util.c
index 7500c08b2a6f085f4acc4fc77efc985a4351d977..64d83c84f3292ffffa87af4f5129c891f4e3796e 100644 (file)
--- a/util.c
+++ b/util.c
@@ -88,7 +88,7 @@ int osl_open(const char *path, int flags, mode_t mode)
 
        if (ret >= 0)
                return ret;
 
        if (ret >= 0)
                return ret;
-       return -E_OSL_OPEN;
+       return errno == ENOENT? -E_OSL_NOENT : -E_OSL_OPEN;
 }
 
 /**
 }
 
 /**
@@ -152,7 +152,7 @@ int mmap_full_file(const char *path, int open_mode, void **map,
                return ret;
        fd = ret;
        if (fstat(fd, &file_status) < 0) {
                return ret;
        fd = ret;
        if (fstat(fd, &file_status) < 0) {
-               ret = -E_OSL_FSTAT;
+               ret = errno == ENOENT? -E_OSL_NOENT : -E_OSL_STAT;
                goto out;
        }
        *size = file_status.st_size;
                goto out;
        }
        *size = file_status.st_size;
diff --git a/util.h b/util.h
index f4c26ad4934f0b465020732c1397d227c99eb979..79b0d0eb778457d079d207a2537cf6acb5629b19 100644 (file)
--- a/util.h
+++ b/util.h
@@ -50,5 +50,5 @@ _static_inline_ int osl_stat(const char *path, struct stat *buf)
 {
        if (stat(path, buf) >= 0)
                return 1;
 {
        if (stat(path, buf) >= 0)
                return 1;
-       return -E_OSL_STAT;
+       return errno == ENOENT? -E_OSL_NOENT : -E_OSL_STAT;
 }
 }