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 5b9308e..a9dcc29 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 */
-               ret = stat(dirname, &statbuf);
+               ret = osl_stat(dirname, &statbuf);
                free(dirname);
-               if (ret < 0) {
-                       ret = -E_OSL_STAT;
+               if (ret < 0)
                        goto err;
-               }
                ret = -E_OSL_NOTDIR;
                if (!S_ISDIR(statbuf.st_mode))
                        goto err;
diff --git a/util.c b/util.c
index 7500c08..64d83c8 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;
-       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) {
-               ret = -E_OSL_FSTAT;
+               ret = errno == ENOENT? -E_OSL_NOENT : -E_OSL_STAT;
                goto out;
        }
        *size = file_status.st_size;
diff --git a/util.h b/util.h
index f4c26ad..79b0d0e 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;
-       return -E_OSL_STAT;
+       return errno == ENOENT? -E_OSL_NOENT : -E_OSL_STAT;
 }