From cf207dcadaa03addb1381012f9b822a754a526af Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Fri, 12 Jun 2009 21:54:19 +0200 Subject: [PATCH 1/1] Return -E_OSL_NOENT if stat/open fails with errno == ENOENT. This often indicates a non-fatal error, so callers might want to know. --- osl.c | 6 ++---- util.c | 4 ++-- util.h | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/osl.c b/osl.c index 5b9308e..a9dcc29 100644 --- 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 --- 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 --- 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; } -- 2.30.2