]> git.tuebingen.mpg.de Git - osl.git/blobdiff - osl.c
Fix a design flaw in osl_rbtree_loop() and osl_rbtree_loop_reverse().
[osl.git] / osl.c
diff --git a/osl.c b/osl.c
index 957e9a7edefa7fb7ebda9ab2eff424482fcc4d77..81b035ddbf8c64588b350506451867a832f2a23e 100644 (file)
--- a/osl.c
+++ b/osl.c
@@ -10,6 +10,7 @@
 
 
 #include "log.h"
+#include "osl.h"
 #include "error.h"
 #include "fd.h"
 #include "list.h"
@@ -60,6 +61,35 @@ static __must_check __printf_1_2 __malloc char *make_message(const char *fmt, ..
        return p;
 }
 
+/* Taken from Drepper: How to write shared libraries, Appendix B. */
+#include <stddef.h>
+#define MSGSTRFIELD(line) MSGSTRFIELD1(line)
+#define MSGSTRFIELD1(line) str##line
+static const union msgstr_t {
+       struct {
+#define _S(n, s) char MSGSTRFIELD(__LINE__)[sizeof(s)];
+#include "errtab.h"
+#undef _S
+       };
+       char str[0];
+} msgstr = { {
+#define _S(n, s) s,
+#include "errtab.h"
+#undef _S
+} };
+static const unsigned int errmsgidx[] = {
+#define _S(n, s) [n] = offsetof(union msgstr_t, MSGSTRFIELD(__LINE__)),
+#include "errtab.h"
+#undef _S
+};
+
+__export const char *osl_strerror(int num)
+{
+       if (IS_SYSTEM_ERROR(num))
+               return strerror((num) & ((1 << SYSTEM_ERROR_BIT) - 1));
+       return msgstr.str + errmsgidx[num];
+}
+
 /**
  * The log function.
  *
@@ -242,28 +272,6 @@ static int verify_name(const char *name)
        return 1;
 }
 
-/**
- * Compare two osl objects pointing to unsigned integers of 32 bit size.
- *
- * \param obj1 Pointer to the first integer.
- * \param obj2 Pointer to the second integer.
- *
- * \return The values required for an osl compare function.
- *
- * \sa osl_compare_func, osl_hash_compare().
- */
-int uint32_compare(const struct osl_object *obj1, const struct osl_object *obj2)
-{
-       uint32_t d1 = read_u32((const char *)obj1->data);
-       uint32_t d2 = read_u32((const char *)obj2->data);
-
-       if (d1 < d2)
-               return 1;
-       if (d1 > d2)
-               return -1;
-       return 0;
-}
-
 /**
  * Compare two osl objects pointing to hash values.
  *
@@ -1731,7 +1739,7 @@ __export int osl_get_row(const struct osl_table *t, unsigned col_num,
        return 1;
 }
 
-static int rbtree_loop(struct osl_column *col,  void *private_data,
+static int rbtree_loop(struct osl_column *col, void *private_data,
                osl_rbtree_loop_func *func)
 {
        struct rb_node *n, *tmp;
@@ -1741,14 +1749,13 @@ static int rbtree_loop(struct osl_column *col,  void *private_data,
                        n;
                        n = tmp, tmp = tmp? rb_next(tmp) : NULL) {
                struct osl_row *r = get_row_pointer(n, col->rbtree_num);
-               int ret = func(r, private_data);
-               if (ret < 0)
-                       return ret;
+               if (func(r, private_data) < 0)
+                       return -E_OSL_LOOP;
        }
        return 1;
 }
 
-static int rbtree_loop_reverse(struct osl_column *col,  void *private_data,
+static int rbtree_loop_reverse(struct osl_column *col, void *private_data,
                osl_rbtree_loop_func *func)
 {
        struct rb_node *n, *tmp;
@@ -1758,9 +1765,8 @@ static int rbtree_loop_reverse(struct osl_column *col,  void *private_data,
                        n;
                        n = tmp, tmp = tmp? rb_prev(tmp) : NULL) {
                struct osl_row *r = get_row_pointer(n, col->rbtree_num);
-               int ret = func(r, private_data);
-               if (ret < 0)
-                       return ret;
+               if (func(r, private_data) < 0)
+                       return -E_OSL_LOOP;
        }
        return 1;
 }
@@ -1784,7 +1790,7 @@ static int rbtree_loop_reverse(struct osl_column *col,  void *private_data,
  *
  *
  * \return Standard. If the termination of the loop was caused by \a func
- * returning a negative value, this value is returned.
+ * returning a negative value, \p -E_OSL_LOOP is returned.
  *
  * \sa osl_storage_flags, osl_rbtree_loop_reverse(), osl_compare_func.
  */