blob: 4d249e9fe2e5b6ed69d9b855cdb93f1d25875203 [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Error handling in libasm.
Ulrich Drepper7e678fa2009-01-10 18:02:05 -08002 Copyright (C) 2002, 2004, 2005, 2009 Red Hat, Inc.
Ulrich Drepper361df7d2006-04-04 21:38:57 +00003 This file is part of Red Hat elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00004 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
5
Ulrich Drepper361df7d2006-04-04 21:38:57 +00006 Red Hat elfutils is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by the
8 Free Software Foundation; version 2 of the License.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00009
Ulrich Drepper361df7d2006-04-04 21:38:57 +000010 Red Hat elfutils is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with Red Hat elfutils; if not, write to the Free Software Foundation,
Ulrich Drepper1e9ef502006-04-04 22:29:06 +000017 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
Ulrich Drepper361df7d2006-04-04 21:38:57 +000018
19 Red Hat elfutils is an included package of the Open Invention Network.
20 An included package of the Open Invention Network is a package for which
21 Open Invention Network licensees cross-license their patents. No patent
22 license is granted, either expressly or impliedly, by designation as an
23 included package. Should you wish to participate in the Open Invention
24 Network licensing program, please visit www.openinventionnetwork.com
25 <http://www.openinventionnetwork.com>. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000026
27#ifdef HAVE_CONFIG_H
28# include <config.h>
29#endif
30
31#include <libintl.h>
32#include <stdbool.h>
33#include <stdlib.h>
34
35#include "libasmP.h"
36
37
38/* This is the key for the thread specific memory. */
Ulrich Drepper7e678fa2009-01-10 18:02:05 -080039static __thread int global_error;
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000040
41
42int
43asm_errno (void)
44{
Ulrich Drepper7e678fa2009-01-10 18:02:05 -080045 int result = global_error;
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000046 global_error = ASM_E_NOERROR;
47 return result;
48}
49
50
51void
52__libasm_seterrno (value)
53 int value;
54{
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000055 global_error = value;
56}
57
58
59/* Return the appropriate message for the error. */
60static const char *msgs[ASM_E_NUM] =
61{
62 [ASM_E_NOERROR] = N_("no error"),
63 [ASM_E_NOMEM] = N_("out of memory"),
64 [ASM_E_CANNOT_CREATE] = N_("cannot create output file"),
65 [ASM_E_INVALID] = N_("invalid parameter"),
66 [ASM_E_CANNOT_CHMOD] = N_("cannot change mode of output file"),
67 [ASM_E_CANNOT_RENAME] = N_("cannot rename output file"),
68 [ASM_E_DUPLSYM] = N_("duplicate symbol"),
Ulrich Dreppera38998e2005-08-03 02:05:39 +000069 [ASM_E_TYPE] = N_("invalid section type for operation"),
70 [ASM_E_IOERROR] = N_("error during output of data"),
Ulrich Drepper3cbdd382008-01-02 17:44:39 +000071 [ASM_E_ENOSUP] = N_("no backend support available"),
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000072};
73
74const char *
75asm_errmsg (error)
76 int error;
77{
Ulrich Drepper7e678fa2009-01-10 18:02:05 -080078 int last_error = global_error;
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000079
80 if (error < -1)
Ulrich Drepper5d598762005-09-03 06:05:45 +000081 return _("unknown error");
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000082 if (error == 0 && last_error == 0)
83 /* No error. */
84 return NULL;
85
86 if (error != -1)
87 last_error = error;
88
89 if (last_error == ASM_E_LIBELF)
90 return elf_errmsg (-1);
91
92 return _(msgs[last_error]);
93}