X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=osl.c;h=cce01aac4dc7c7fc6be09d47f274e12a5e0209fb;hb=903c582ebba832333f869a2803fe84e23edc0980;hp=957e9a7edefa7fb7ebda9ab2eff424482fcc4d77;hpb=026cd39b227af84bf84f52c40d1910dcd265b93e;p=osl.git diff --git a/osl.c b/osl.c index 957e9a7..cce01aa 100644 --- 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 +#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. *