summaryrefslogtreecommitdiff
path: root/libelf/errmsg.c
blob: 3b3cbb2cf6881b0391c422a40151f0f6e1b5c667 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
errmsg.c - implementation of the elf_errmsg(3) function.
Copyright (C) 1995 Michael Riepe <riepe@ifwsn4.ifw.uni-hannover.de>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <private.h>

#if HAVE_NLS
# include <nl_types.h>
static nl_catd _libelf_cat = (nl_catd)0;
static const char domain[] = "libelf";
#endif

static const char *_messages[] = {
#define __err__(a,b)	b,
#include <errors.h>		/* include string tables from errors.h */
#undef __err__
};

const char*
elf_errmsg(int err) {
    if (err == 0) {
	err = _elf_errno;
	if (err == 0) {
	    return NULL;
	}
    }
    else if (err == -1) {
	err = _elf_errno;
    }

    if (err < 0 || err >= ERROR_NUM) {
	err = ERROR_UNKNOWN;
    }

#if HAVE_NLS
    if (_libelf_cat == (nl_catd)0) {
	_libelf_cat = catopen(domain, 0);
    }
    if (_libelf_cat != (nl_catd)-1) {
	return catgets(_libelf_cat, 1, err + 1, _messages[err]);
    }
#endif
    return _messages[err];
}