]> git.tuebingen.mpg.de Git - osl.git/blobdiff - osl.c
Switch to the new error code handling.
[osl.git] / osl.c
diff --git a/osl.c b/osl.c
index 957e9a7edefa7fb7ebda9ab2eff424482fcc4d77..cce01aac4dc7c7fc6be09d47f274e12a5e0209fb 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,34 @@ 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.
  *