Fix checking of return values from osl_open().
[paraslash.git] / aft.c
diff --git a/aft.c b/aft.c
index 995c7552129512c6e2dc6228c165779c9e7979a0..f425b6d3d81431b61fe0541742905c4af6b1af96 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -7,6 +7,7 @@
 /** \file aft.c Audio file table functions. */
 
 #include <dirent.h> /* readdir() */
+#include <osl.h>
 #include "para.h"
 #include "error.h"
 #include "string.h"
@@ -218,12 +219,27 @@ enum audio_file_table_columns {
        NUM_AFT_COLUMNS
 };
 
+/**
+ * Compare two osl objects pointing to hash values.
+ *
+ * \param obj1 Pointer to the first hash object.
+ * \param obj2 Pointer to the second hash object.
+ *
+ * \return The values required for an osl compare function.
+ *
+ * \sa osl_compare_func, uint32_compare().
+ */
+int aft_hash_compare(const struct osl_object *obj1, const struct osl_object *obj2)
+{
+       return hash_compare((HASH_TYPE *)obj1->data, (HASH_TYPE *)obj2->data);
+}
+
 static struct osl_column_description aft_cols[] = {
        [AFTCOL_HASH] = {
                .storage_type = OSL_MAPPED_STORAGE,
                .storage_flags = OSL_RBTREE | OSL_FIXED_SIZE | OSL_UNIQUE,
                .name = "hash",
-               .compare_function = osl_hash_compare,
+               .compare_function = aft_hash_compare,
                .data_size = HASH_SIZE
        },
        [AFTCOL_PATH] = {
@@ -417,13 +433,13 @@ static void load_chunk_table(struct afh_info *afhi, char *buf)
  * \param path The full path of the audio file.
  * \param row Result pointer.
  *
- * \return The return value of the underlying call to osl_get_row().
+ * \return Standard.
  */
 int aft_get_row_of_path(const char *path, struct osl_row **row)
 {
        struct osl_object obj = {.data = (char *)path, .size = strlen(path) + 1};
 
-       return osl_get_row(audio_file_table, AFTCOL_PATH, &obj, row);
+       return osl(osl_get_row(audio_file_table, AFTCOL_PATH, &obj, row));
 }
 
 /**
@@ -432,12 +448,12 @@ int aft_get_row_of_path(const char *path, struct osl_row **row)
  * \param hash The hash value of the desired audio file.
  * \param row resul pointer.
  *
- * \return The return value of the underlying call to osl_get_row().
+ * \return Standard.
  */
 int aft_get_row_of_hash(HASH_TYPE *hash, struct osl_row **row)
 {
        const struct osl_object obj = {.data = hash, .size = HASH_SIZE};
-       return osl_get_row(audio_file_table, AFTCOL_HASH, &obj, row);
+       return osl(osl_get_row(audio_file_table, AFTCOL_HASH, &obj, row));
 }
 
 /**
@@ -446,11 +462,11 @@ int aft_get_row_of_hash(HASH_TYPE *hash, struct osl_row **row)
  * \param row Pointer to a row in the audio file table.
  * \param obj Result pointer.
  *
- * \return The return value of the underlying call to osl_get_object().
+ * \return Standard.
  */
 int get_afsi_object_of_row(const struct osl_row *row, struct osl_object *obj)
 {
-       return osl_get_object(audio_file_table, row, AFTCOL_AFSI, obj);
+       return osl(osl_get_object(audio_file_table, row, AFTCOL_AFSI, obj));
 }
 
 /**
@@ -519,8 +535,8 @@ int get_afsi_of_path(const char *path, struct afs_info *afsi)
 int get_audio_file_path_of_row(const struct osl_row *row, char **path)
 {
        struct osl_object path_obj;
-       int ret = osl_get_object(audio_file_table, row, AFTCOL_PATH,
-               &path_obj);
+       int ret = osl(osl_get_object(audio_file_table, row, AFTCOL_PATH,
+               &path_obj));
        if (ret < 0)
                return ret;
        *path = path_obj.data;
@@ -537,9 +553,10 @@ int get_audio_file_path_of_row(const struct osl_row *row, char **path)
  *
  * \sa get_hash_of_row().
  */
-static int get_hash_object_of_aft_row(const struct osl_row *row, struct osl_object *obj)
+static int get_hash_object_of_aft_row(const struct osl_row *row,
+               struct osl_object *obj)
 {
-       return osl_get_object(audio_file_table, row, AFTCOL_HASH, obj);
+       return osl(osl_get_object(audio_file_table, row, AFTCOL_HASH, obj));
 }
 
 /**
@@ -577,8 +594,8 @@ static int get_hash_of_row(const struct osl_row *row, HASH_TYPE **hash)
 int get_afhi_of_row(const struct osl_row *row, struct afh_info *afhi)
 {
        struct osl_object obj;
-       int ret = osl_get_object(audio_file_table, row, AFTCOL_AFHI,
-               &obj);
+       int ret = osl(osl_get_object(audio_file_table, row, AFTCOL_AFHI,
+               &obj));
        if (ret < 0)
                return ret;
        load_afhi(obj.data, afhi);
@@ -1368,8 +1385,8 @@ static void com_ls_callback(int fd, const struct osl_object *query)
        if (opts->flags & LS_FLAG_ADMISSIBLE_ONLY)
                ret = admissible_file_loop(opts, prepare_ls_row);
        else
-               ret = osl_rbtree_loop(audio_file_table, AFTCOL_PATH, opts,
-                       prepare_ls_row);
+               ret = osl(osl_rbtree_loop(audio_file_table, AFTCOL_PATH, opts,
+                       prepare_ls_row));
        if (ret < 0)
                goto out;
        if (!opts->num_matching_paths)
@@ -1517,12 +1534,12 @@ int com_ls(int fd, int argc, char * const * const argv)
  * \param private_data An arbitrary data pointer, passed to \a func.
  * \param func The custom function to be called.
  *
- * \return The return value of the underlying call to osl_rbtree_loop().
+ * \return Standard.
  */
 int audio_file_loop(void *private_data, osl_rbtree_loop_func *func)
 {
-       return osl_rbtree_loop(audio_file_table, AFTCOL_HASH, private_data,
-               func);
+       return osl(osl_rbtree_loop(audio_file_table, AFTCOL_HASH, private_data,
+               func));
 }
 
 static struct osl_row *find_hash_sister(HASH_TYPE *hash)
@@ -1682,7 +1699,7 @@ static void com_add_callback(int fd, const struct osl_object *query)
        PARA_INFO_LOG("request to add %s\n", path);
        hs = find_hash_sister(hash);
        ret = aft_get_row_of_path(path, &pb);
-       if (ret < 0 && ret != -E_RB_KEY_NOT_FOUND)
+       if (ret < 0 && ret != -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND))
                goto out;
        if (hs && pb && hs == pb && !(flags & ADD_FLAG_FORCE)) {
                if (flags & ADD_FLAG_VERBOSE)
@@ -1699,23 +1716,23 @@ static void com_add_callback(int fd, const struct osl_object *query)
                                if (ret < 0)
                                        goto out;
                        }
-                       ret = osl_del_row(audio_file_table, pb);
+                       ret = osl(osl_del_row(audio_file_table, pb));
                        if (ret < 0)
                                goto out;
                        pb = NULL;
                }
                /* file rename, update hs' path */
                if (flags & ADD_FLAG_VERBOSE) {
-                       ret = osl_get_object(audio_file_table, hs,
-                               AFTCOL_PATH, &obj);
+                       ret = osl(osl_get_object(audio_file_table, hs,
+                               AFTCOL_PATH, &obj));
                        if (ret < 0)
                                goto out;
                        ret = para_printf(&msg, "renamed from %s\n", (char *)obj.data);
                        if (ret < 0)
                                goto out;
                }
-               ret = osl_update_object(audio_file_table, hs, AFTCOL_PATH,
-                       &objs[AFTCOL_PATH]);
+               ret = osl(osl_update_object(audio_file_table, hs, AFTCOL_PATH,
+                       &objs[AFTCOL_PATH]));
                if (ret < 0)
                        goto out;
                afs_event(AUDIO_FILE_RENAME, &msg, hs);
@@ -1759,12 +1776,12 @@ static void com_add_callback(int fd, const struct osl_object *query)
                        if (ret < 0)
                                goto out;
                }
-               ret = osl_update_object(audio_file_table, row, AFTCOL_AFHI,
-                       &objs[AFTCOL_AFHI]);
+               ret = osl(osl_update_object(audio_file_table, row, AFTCOL_AFHI,
+                       &objs[AFTCOL_AFHI]));
                if (ret < 0)
                        goto out;
-               ret = osl_update_object(audio_file_table, row, AFTCOL_CHUNKS,
-                       &objs[AFTCOL_CHUNKS]);
+               ret = osl(osl_update_object(audio_file_table, row, AFTCOL_CHUNKS,
+                       &objs[AFTCOL_CHUNKS]));
                if (ret < 0)
                        goto out;
                afs_event(AFHI_CHANGE, &msg, row);
@@ -1782,7 +1799,7 @@ static void com_add_callback(int fd, const struct osl_object *query)
        objs[AFTCOL_AFSI].data = &afsi_buf;
        objs[AFTCOL_AFSI].size = AFSI_SIZE;
        save_afsi(&default_afsi, &objs[AFTCOL_AFSI]);
-       ret = osl_add_and_get_row(audio_file_table, objs, &aft_row);
+       ret = osl(osl_add_and_get_row(audio_file_table, objs, &aft_row));
        afs_event(AUDIO_FILE_ADD, &msg, aft_row);
 out:
        if (ret < 0)
@@ -1845,7 +1862,7 @@ static int add_one_audio_file(const char *path, void *private_data)
        query.size = strlen(path) + 1;
        ret = send_callback_request(path_brother_callback, &query,
                get_row_pointer_from_result, &pb);
-       if (ret < 0 && ret != -E_RB_KEY_NOT_FOUND)
+       if (ret < 0 && ret != -OSL_ERRNO_TO_PARA_ERROR(E_OSL_RB_KEY_NOT_FOUND))
                goto out_free;
        ret = 1;
        if (pb && (pad->flags & ADD_FLAG_LAZY)) { /* lazy is really cheap */
@@ -2209,7 +2226,7 @@ static int remove_audio_file(__a_unused struct osl_table *table,
                        return ret;
        }
        afs_event(AUDIO_FILE_REMOVE, &crd->pb, row);
-       ret = osl_del_row(audio_file_table, row);
+       ret = osl(osl_del_row(audio_file_table, row));
        if (ret < 0)
                para_printf(&crd->pb, "%s: %s\n", name, para_strerror(-ret));
        else
@@ -2548,7 +2565,7 @@ static int aft_open(const char *dir)
        int ret;
 
        audio_file_table_desc.dir = dir;
-       ret = osl_open_table(&audio_file_table_desc, &audio_file_table);
+       ret = osl(osl_open_table(&audio_file_table_desc, &audio_file_table));
        if (ret >= 0) {
                unsigned num;
                osl_get_num_rows(audio_file_table, &num);
@@ -2557,7 +2574,7 @@ static int aft_open(const char *dir)
        }
        PARA_INFO_LOG("failed to open audio file table\n");
        audio_file_table = NULL;
-       if (ret >= 0 || is_errno(-ret, ENOENT))
+       if (ret >= 0 || ret == -OSL_ERRNO_TO_PARA_ERROR(E_OSL_NOENT))
                return 1;
        return ret;
 }
@@ -2565,7 +2582,7 @@ static int aft_open(const char *dir)
 static int aft_create(const char *dir)
 {
        audio_file_table_desc.dir = dir;
-       return osl_create_table(&audio_file_table_desc);
+       return osl(osl_create_table(&audio_file_table_desc));
 }
 
 static int clear_attribute(struct osl_row *row, void *data)