]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Remove some system errors from errno.h
authorAndre Noll <maan@systemlinux.org>
Tue, 9 Oct 2007 19:11:05 +0000 (21:11 +0200)
committerAndre Noll <maan@systemlinux.org>
Tue, 9 Oct 2007 19:11:05 +0000 (21:11 +0200)
No need to have system errors duplicated in error.h. Just return
-ERRNO_TO_PARA_ERROR(errno) in these cases.

afs.c
aft.c
attribute.c
blob.c
error.h
fd.c
fsck.c
osl.c

diff --git a/afs.c b/afs.c
index e13e257bc66556dc035440aa62055f5152905902..17557e5eaa789831f136e758a3a31fe5903e7271 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -537,7 +537,7 @@ static int make_database_dir(void)
        }
        PARA_INFO_LOG("afs_database dir %s\n", database_dir);
        ret = para_mkdir(database_dir, 0777);
-       if (ret >= 0 || ret == -E_EXIST)
+       if (ret >= 0 || is_errno(-ret, EEXIST))
                return 1;
        free(database_dir);
        database_dir = NULL;
diff --git a/aft.c b/aft.c
index c6ca289f18229b28ecf0ee45fba49d06fc1791fc..5112affacdcd29ebcaf51b82eb9d6980035d5f88 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -2213,5 +2213,7 @@ int aft_init(struct table_info *ti, const char *db)
        }
        PARA_INFO_LOG("failed to open audio file table\n");
        audio_file_table = NULL;
-       return ret == -E_NOENT? 1 : ret;
+       if (ret >= 0 || is_errno(-ret, ENOENT))
+               return 1;
+       return ret;
 }
index d34f7d6371f7995f17a23fa9df4d3ec8b39f363e..e0a7392fdc99d86f6225c5ac43e1ab690e0bce50 100644 (file)
@@ -538,7 +538,7 @@ int attribute_init(struct table_info *ti, const char *db)
                return ret;
        }
        attribute_table = NULL;
-       if (ret == -E_NOENT)
+       if (ret >= 0 || is_errno(-ret, ENOENT))
                return 1;
        return ret;
 }
diff --git a/blob.c b/blob.c
index 150a15e4cfe72bd56ced02ff848a2cea7ac23f3b..9282b5f58bd83f04d1a9147efd9e8ba08ff20d6d 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -471,7 +471,9 @@ static int blob_init(struct osl_table **table,
        if (ret >= 0)
                return ret;
        *table = NULL;
-       return ret == -E_NOENT? 1 : ret;
+       if (ret >= 0 || is_errno(-ret, -ENOENT))
+               return 1;
+       return ret;
 }
 
 /** Define the \p init function for this blob type. */
diff --git a/error.h b/error.h
index 62540f4fcf78ba0a086390859077e2f74e8fba0c..537e7393b3e038d5e380de9512c93965248d11c3 100644 (file)
--- a/error.h
+++ b/error.h
@@ -408,18 +408,10 @@ extern const char **para_errlist[];
 
 
 #define FD_ERRORS \
-       PARA_ERROR(NOTDIR, "error: not a directory"), \
        PARA_ERROR(FGETS, "fgets error"), \
-       PARA_ERROR(EXIST, "file or directory already exists"), \
-       PARA_ERROR(ISDIR, "error: is a directory"), \
-       PARA_ERROR(NOENT, "no such file or directory"), \
-       PARA_ERROR(OPEN_PERM, "open error (permission denied)"), \
-       PARA_ERROR(MKDIR_PERM, "mkdir error (permission denied)"), \
-       PARA_ERROR(MKDIR, "failed to create directory"), \
        PARA_ERROR(CHDIR, "failed to change directory"), \
        PARA_ERROR(FCHDIR, "fchdir failed"), \
        PARA_ERROR(OPENDIR, "can not open directory"), \
-       PARA_ERROR(NOSPC, "no space left on device"), \
        PARA_ERROR(OPEN, "failed to open file"), \
        PARA_ERROR(CHDIR_PERM, "insufficient permissions to chdir"), \
 
@@ -520,7 +512,11 @@ extern const char **para_errlist[];
 
 #define ERRNO_TO_PARA_ERROR(num) ((num) | (1 << SYSTEM_ERROR_BIT))
 
-#define IS_SYSTEM_ERRNO(val, _errno) (ERRNO_TO_PARA_ERROR(_errno) == (val))
+static inline int is_errno(int val, int _errno)
+{
+       assert(val > 0 && _errno > 0);
+       return ERRNO_TO_PARA_ERROR(_errno) == val;
+}
 
 /**
  * paraslash's version of strerror(3)
diff --git a/fd.c b/fd.c
index 6bd21b5bda7411d7f4444e1c985a5c661ccadec2..ed61664545817d51774bdff4d1502a019f8bdfe8 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -170,7 +170,7 @@ void *para_mmap(size_t length, int prot, int flags, int fd, off_t offset)
  * The mode parameter must be specified when O_CREAT is in the flags, and is ignored
  * otherwise.
  *
- * \return Positive on success, negative on errors.
+ * \return The file descriptor on success, negative on errors.
  *
  * \sa open(2).
  */
@@ -180,22 +180,7 @@ int para_open(const char *path, int flags, mode_t mode)
 
        if (ret >= 0)
                return ret;
-       switch (errno) {
-       case EEXIST:
-               ret = -E_EXIST;
-               break;
-       case EISDIR:
-               ret = -E_ISDIR;
-               break;
-       case ENOENT:
-               ret = -E_NOENT;
-               break;
-       case EPERM:
-               ret = -E_OPEN_PERM;
-               break;
-       };
-       PARA_ERROR_LOG("failed to open %s: %s\n", path, strerror(errno));
-       return -E_OPEN;
+       return -ERRNO_TO_PARA_ERROR(errno);
 }
 
 /**
@@ -211,13 +196,7 @@ int para_chdir(const char *path)
 
        if (ret >= 0)
                return 1;
-       switch (errno) {
-       case ENOENT:
-               return -E_NOENT;
-       case EACCES:
-               return -E_CHDIR_PERM;
-       };
-       return -E_CHDIR;
+       return -ERRNO_TO_PARA_ERROR(errno);
 }
 
 /**
@@ -292,19 +271,11 @@ int para_fchdir(int fd)
  * \param path Name of the directory to create.
  * \param mode The permissions to use.
  *
- * \return positive on success, negative on errors.
+ * \return Standard.
  */
 int para_mkdir(const char *path, mode_t mode)
 {
        if (!mkdir(path, mode))
                return 1;
-       if (errno == EEXIST)
-               return -E_EXIST;
-       if (errno == ENOSPC)
-               return -E_NOSPC;
-       if (errno == ENOTDIR)
-               return -E_NOTDIR;
-       if (errno == EPERM)
-               return -E_MKDIR_PERM;
-       return -E_MKDIR;
+       return -ERRNO_TO_PARA_ERROR(errno);
 }
diff --git a/fsck.c b/fsck.c
index 4d7198202a41363b822e8ea29b56383135eb853c..19f7be67739a5f1a0751e4f9dcb1460a4f45084b 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -789,12 +789,12 @@ static int dump_rows(char *dump_dir, struct osl_table *t)
                        current_dir = make_message("%s/rows_%u-%u", dump_dir, i, i + 999);
                        PARA_NOTICE_LOG("dumping rows %u - %u\n", i, i + 999);
                        ret = para_mkdir(current_dir, 0777);
-                       if (ret < 0 && ret != -E_EXIST)
+                       if (ret < 0 && !is_errno(-ret, EEXIST))
                                goto out;
                }
                row_dir = make_message("%s/row_%03u", current_dir, i);
                ret = para_mkdir(row_dir, 0777);
-               if (ret < 0 && ret != -E_EXIST) {
+               if (ret < 0 && !is_errno(-ret, EEXIST)) {
                        free(row_dir);
                        goto out;
                }
@@ -818,11 +818,11 @@ static int dump_table(char *dump_dir, struct osl_table_description *desc)
        if (ret < 0)
                goto out;
        ret = para_mkdir(dump_dir, 0777);
-       if (ret < 0 && ret != -E_EXIST)
+       if (ret < 0 && !is_errno(-ret, EEXIST))
                goto out;
        table_dump_dir = make_message("%s/%s", dump_dir, desc->name);
        ret = para_mkdir(table_dump_dir, 0777);
-       if (ret < 0 && ret != -E_EXIST)
+       if (ret < 0 && !is_errno(-ret, EEXIST))
                goto out;
        desc_file = make_message("%s/table_description.c", table_dump_dir);
        ret = para_open(desc_file, O_WRONLY | O_CREAT | O_EXCL, 0644);
diff --git a/osl.c b/osl.c
index 0b14447b296c736ecaed7d831e0801a45c99296f..19d7961ecc261dfe497e2a81361ae24ba53eb529 100644 (file)
--- a/osl.c
+++ b/osl.c
@@ -679,7 +679,7 @@ int osl_create_table(const struct osl_table_description *desc)
                        continue;
                if (!table_dir) {
                        ret = para_mkdir(desc->dir, 0777);
-                       if (ret < 0 && ret != -E_EXIST)
+                       if (ret < 0 && !is_errno(-ret, EEXIST))
                                goto out;
                        table_dir = make_message("%s/%s", desc->dir,
                                desc->name);
@@ -1226,13 +1226,10 @@ int osl_open_table(const struct osl_table_description *table_desc,
                ret = stat(dirname, &statbuf);
                free(dirname);
                if (ret < 0) {
-                       if (errno == ENOENT)
-                               ret = -E_NOENT;
-                       else
-                               ret = -E_STAT;
+                       ret = -ERRNO_TO_PARA_ERROR(errno);
                        goto err;
                }
-               ret = -E_NOTDIR;
+               ret = -ERRNO_TO_PARA_ERROR(ENOTDIR);
                if (!S_ISDIR(statbuf.st_mode))
                        goto err;
        }
@@ -1265,7 +1262,7 @@ static int create_disk_storage_object_dir(const struct osl_table *t,
        dirname = disk_storage_dirname(t, col_num, ds_name);
        ret = para_mkdir(dirname, 0777);
        free(dirname);
-       if (ret < 0 && ret != -E_EXIST)
+       if (ret < 0 && !is_errno(-ret, EEXIST))
                return ret;
        return 1;
 }
@@ -1358,15 +1355,11 @@ static int delete_disk_storage_file(const struct osl_table *t, unsigned col_num,
                const char *ds_name)
 {
        char *dirname, *filename = disk_storage_path(t, col_num, ds_name);
-       int ret = unlink(filename);
+       int ret = unlink(filename), err = errno;
 
-       PARA_DEBUG_LOG("deleted %s\n", filename);
        free(filename);
-       if (ret < 0) {
-               if (errno == ENOENT)
-                       return -E_NOENT;
-               return -E_UNLINK;
-       }
+       if (ret < 0)
+               return -ERRNO_TO_PARA_ERROR(err);
        if (!(t->desc->flags & OSL_LARGE_TABLE))
                return 1;
        dirname = disk_storage_dirname(t, col_num, ds_name);
@@ -1877,7 +1870,7 @@ int osl_update_object(struct osl_table *t, const struct osl_row *r,
                if (ret < 0)
                        return ret;
                ret = delete_disk_storage_file(t, col_num, ds_name);
-               if (ret < 0 && ret != -E_NOENT) {
+               if (ret < 0 && !is_errno(-ret, ENOENT)) {
                        free(ds_name);
                        return ret;
                }