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. |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 3 | This file is part of Red Hat elfutils. |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 4 | Written by Ulrich Drepper <drepper@redhat.com>, 2002. |
| 5 | |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 6 | 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 Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 9 | |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 10 | 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 Drepper | 1e9ef50 | 2006-04-04 22:29:06 +0000 | [diff] [blame] | 17 | Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 18 | |
| 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 Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 26 | |
| 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 Drepper | 7e678fa | 2009-01-10 18:02:05 -0800 | [diff] [blame] | 39 | static __thread int global_error; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 40 | |
| 41 | |
| 42 | int |
| 43 | asm_errno (void) |
| 44 | { |
Ulrich Drepper | 7e678fa | 2009-01-10 18:02:05 -0800 | [diff] [blame] | 45 | int result = global_error; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 46 | global_error = ASM_E_NOERROR; |
| 47 | return result; |
| 48 | } |
| 49 | |
| 50 | |
| 51 | void |
| 52 | __libasm_seterrno (value) |
| 53 | int value; |
| 54 | { |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 55 | global_error = value; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | /* Return the appropriate message for the error. */ |
| 60 | static 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 Drepper | a38998e | 2005-08-03 02:05:39 +0000 | [diff] [blame] | 69 | [ASM_E_TYPE] = N_("invalid section type for operation"), |
| 70 | [ASM_E_IOERROR] = N_("error during output of data"), |
Ulrich Drepper | 3cbdd38 | 2008-01-02 17:44:39 +0000 | [diff] [blame] | 71 | [ASM_E_ENOSUP] = N_("no backend support available"), |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | const char * |
| 75 | asm_errmsg (error) |
| 76 | int error; |
| 77 | { |
Ulrich Drepper | 7e678fa | 2009-01-10 18:02:05 -0800 | [diff] [blame] | 78 | int last_error = global_error; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 79 | |
| 80 | if (error < -1) |
Ulrich Drepper | 5d59876 | 2005-09-03 06:05:45 +0000 | [diff] [blame] | 81 | return _("unknown error"); |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 82 | 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 | } |