Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 1 | /* Error handling in libasm. |
Ulrich Drepper | 7e678fa | 2009-01-10 18:02:05 -0800 | [diff] [blame] | 2 | Copyright (C) 2002, 2004, 2005, 2009 Red Hat, Inc. |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 3 | This file is part of elfutils. |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 4 | Written by Ulrich Drepper <drepper@redhat.com>, 2002. |
| 5 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 6 | This file is free software; you can redistribute it and/or modify |
| 7 | it under the terms of either |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 8 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 9 | * the GNU Lesser General Public License as published by the Free |
| 10 | Software Foundation; either version 3 of the License, or (at |
| 11 | your option) any later version |
| 12 | |
| 13 | or |
| 14 | |
| 15 | * the GNU General Public License as published by the Free |
| 16 | Software Foundation; either version 2 of the License, or (at |
| 17 | your option) any later version |
| 18 | |
| 19 | or both in parallel, as here. |
| 20 | |
| 21 | elfutils is distributed in the hope that it will be useful, but |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 22 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 24 | General Public License for more details. |
| 25 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 26 | You should have received copies of the GNU General Public License and |
| 27 | the GNU Lesser General Public License along with this program. If |
| 28 | not, see <http://www.gnu.org/licenses/>. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 29 | |
| 30 | #ifdef HAVE_CONFIG_H |
| 31 | # include <config.h> |
| 32 | #endif |
| 33 | |
| 34 | #include <libintl.h> |
| 35 | #include <stdbool.h> |
| 36 | #include <stdlib.h> |
| 37 | |
| 38 | #include "libasmP.h" |
| 39 | |
| 40 | |
| 41 | /* This is the key for the thread specific memory. */ |
Ulrich Drepper | 7e678fa | 2009-01-10 18:02:05 -0800 | [diff] [blame] | 42 | static __thread int global_error; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 43 | |
| 44 | |
| 45 | int |
| 46 | asm_errno (void) |
| 47 | { |
Ulrich Drepper | 7e678fa | 2009-01-10 18:02:05 -0800 | [diff] [blame] | 48 | int result = global_error; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 49 | global_error = ASM_E_NOERROR; |
| 50 | return result; |
| 51 | } |
| 52 | |
| 53 | |
| 54 | void |
| 55 | __libasm_seterrno (value) |
| 56 | int value; |
| 57 | { |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 58 | global_error = value; |
| 59 | } |
| 60 | |
| 61 | |
| 62 | /* Return the appropriate message for the error. */ |
| 63 | static const char *msgs[ASM_E_NUM] = |
| 64 | { |
| 65 | [ASM_E_NOERROR] = N_("no error"), |
| 66 | [ASM_E_NOMEM] = N_("out of memory"), |
| 67 | [ASM_E_CANNOT_CREATE] = N_("cannot create output file"), |
| 68 | [ASM_E_INVALID] = N_("invalid parameter"), |
| 69 | [ASM_E_CANNOT_CHMOD] = N_("cannot change mode of output file"), |
| 70 | [ASM_E_CANNOT_RENAME] = N_("cannot rename output file"), |
| 71 | [ASM_E_DUPLSYM] = N_("duplicate symbol"), |
Ulrich Drepper | a38998e | 2005-08-03 02:05:39 +0000 | [diff] [blame] | 72 | [ASM_E_TYPE] = N_("invalid section type for operation"), |
| 73 | [ASM_E_IOERROR] = N_("error during output of data"), |
Ulrich Drepper | 3cbdd38 | 2008-01-02 17:44:39 +0000 | [diff] [blame] | 74 | [ASM_E_ENOSUP] = N_("no backend support available"), |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | const char * |
| 78 | asm_errmsg (error) |
| 79 | int error; |
| 80 | { |
Ulrich Drepper | 7e678fa | 2009-01-10 18:02:05 -0800 | [diff] [blame] | 81 | int last_error = global_error; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 82 | |
| 83 | if (error < -1) |
Ulrich Drepper | 5d59876 | 2005-09-03 06:05:45 +0000 | [diff] [blame] | 84 | return _("unknown error"); |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 85 | if (error == 0 && last_error == 0) |
| 86 | /* No error. */ |
| 87 | return NULL; |
| 88 | |
| 89 | if (error != -1) |
| 90 | last_error = error; |
| 91 | |
| 92 | if (last_error == ASM_E_LIBELF) |
| 93 | return elf_errmsg (-1); |
| 94 | |
| 95 | return _(msgs[last_error]); |
| 96 | } |