|
1 /* |
|
2 * errmsg.c - implementation of the elf_errmsg(3) function. |
|
3 * Copyright (C) 1995 - 1999, 2004 Michael Riepe |
|
4 * |
|
5 * This library is free software; you can redistribute it and/or |
|
6 * modify it under the terms of the GNU Library General Public |
|
7 * License as published by the Free Software Foundation; either |
|
8 * version 2 of the License, or (at your option) any later version. |
|
9 * |
|
10 * This library is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 * Library General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU Library General Public |
|
16 * License along with this library; if not, write to the Free Software |
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 */ |
|
19 |
|
20 #include <private.h> |
|
21 |
|
22 #ifndef lint |
|
23 static const char rcsid[] = "@(#) $Id: errmsg.c,v 1.10 2005/05/21 15:39:21 michael Exp $"; |
|
24 #endif /* lint */ |
|
25 |
|
26 #if HAVE_DGETTEXT |
|
27 # undef HAVE_CATGETS |
|
28 # include <libintl.h> |
|
29 #else /* HAVE_DGETTEXT */ |
|
30 # define dgettext(dom, str) str |
|
31 #endif /* HAVE_DGETTEXT */ |
|
32 |
|
33 #if HAVE_CATGETS |
|
34 # include <nl_types.h> |
|
35 static nl_catd _libelf_cat = (nl_catd)0; |
|
36 #endif /* HAVE_CATGETS */ |
|
37 |
|
38 #if HAVE_DGETTEXT || HAVE_CATGETS |
|
39 static const char domain[] = "libelf"; |
|
40 #endif /* HAVE_DGETTEXT || HAVE_CATGETS */ |
|
41 |
|
42 #if PIC |
|
43 static const char *_messages[] = { |
|
44 #else /* PIC */ |
|
45 static const char *const _messages[] = { |
|
46 #endif /* PIC */ |
|
47 #define __err__(a,b) b, |
|
48 #include <errors.h> /* include string tables from errors.h */ |
|
49 #undef __err__ |
|
50 }; |
|
51 |
|
52 const char* |
|
53 elf_errmsg(int err) { |
|
54 if (err == 0) { |
|
55 err = _elf_errno; |
|
56 if (err == 0) { |
|
57 return NULL; |
|
58 } |
|
59 } |
|
60 else if (err == -1) { |
|
61 err = _elf_errno; |
|
62 } |
|
63 |
|
64 if (err < 0 || err >= ERROR_NUM || _messages[err] == NULL) { |
|
65 err = ERROR_UNKNOWN; |
|
66 } |
|
67 |
|
68 #if HAVE_CATGETS |
|
69 if (_libelf_cat == (nl_catd)0) { |
|
70 _libelf_cat = catopen(domain, 0); |
|
71 } |
|
72 if (_libelf_cat != (nl_catd)-1) { |
|
73 return catgets(_libelf_cat, 1, err + 1, _messages[err]); |
|
74 } |
|
75 #endif /* HAVE_CATGETS */ |
|
76 return dgettext(domain, _messages[err]); |
|
77 } |