|
Packit |
032894 |
/* Error handling in libasm.
|
|
Packit |
032894 |
Copyright (C) 2002, 2004, 2005, 2009 Red Hat, Inc.
|
|
Packit |
032894 |
This file is part of elfutils.
|
|
Packit |
032894 |
Written by Ulrich Drepper <drepper@redhat.com>, 2002.
|
|
Packit |
032894 |
|
|
Packit |
032894 |
This file is free software; you can redistribute it and/or modify
|
|
Packit |
032894 |
it under the terms of either
|
|
Packit |
032894 |
|
|
Packit |
032894 |
* the GNU Lesser General Public License as published by the Free
|
|
Packit |
032894 |
Software Foundation; either version 3 of the License, or (at
|
|
Packit |
032894 |
your option) any later version
|
|
Packit |
032894 |
|
|
Packit |
032894 |
or
|
|
Packit |
032894 |
|
|
Packit |
032894 |
* the GNU General Public License as published by the Free
|
|
Packit |
032894 |
Software Foundation; either version 2 of the License, or (at
|
|
Packit |
032894 |
your option) any later version
|
|
Packit |
032894 |
|
|
Packit |
032894 |
or both in parallel, as here.
|
|
Packit |
032894 |
|
|
Packit |
032894 |
elfutils is distributed in the hope that it will be useful, but
|
|
Packit |
032894 |
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
032894 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
032894 |
General Public License for more details.
|
|
Packit |
032894 |
|
|
Packit |
032894 |
You should have received copies of the GNU General Public License and
|
|
Packit |
032894 |
the GNU Lesser General Public License along with this program. If
|
|
Packit |
032894 |
not, see <http://www.gnu.org/licenses/>. */
|
|
Packit |
032894 |
|
|
Packit |
032894 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
032894 |
# include <config.h>
|
|
Packit |
032894 |
#endif
|
|
Packit |
032894 |
|
|
Packit |
032894 |
#include <libintl.h>
|
|
Packit |
032894 |
#include <stdbool.h>
|
|
Packit |
032894 |
#include <stdlib.h>
|
|
Packit |
032894 |
|
|
Packit |
032894 |
#include "libasmP.h"
|
|
Packit |
032894 |
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* This is the key for the thread specific memory. */
|
|
Packit |
032894 |
static __thread int global_error;
|
|
Packit |
032894 |
|
|
Packit |
032894 |
|
|
Packit |
032894 |
int
|
|
Packit |
032894 |
asm_errno (void)
|
|
Packit |
032894 |
{
|
|
Packit |
032894 |
int result = global_error;
|
|
Packit |
032894 |
global_error = ASM_E_NOERROR;
|
|
Packit |
032894 |
return result;
|
|
Packit |
032894 |
}
|
|
Packit |
032894 |
|
|
Packit |
032894 |
|
|
Packit |
032894 |
void
|
|
Packit |
032894 |
internal_function
|
|
Packit |
032894 |
__libasm_seterrno (int value)
|
|
Packit |
032894 |
{
|
|
Packit |
032894 |
global_error = value;
|
|
Packit |
032894 |
}
|
|
Packit |
032894 |
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* Return the appropriate message for the error. */
|
|
Packit |
032894 |
static const char *msgs[ASM_E_NUM] =
|
|
Packit |
032894 |
{
|
|
Packit |
032894 |
[ASM_E_NOERROR] = N_("no error"),
|
|
Packit |
032894 |
[ASM_E_NOMEM] = N_("out of memory"),
|
|
Packit |
032894 |
[ASM_E_CANNOT_CREATE] = N_("cannot create output file"),
|
|
Packit |
032894 |
[ASM_E_INVALID] = N_("invalid parameter"),
|
|
Packit |
032894 |
[ASM_E_CANNOT_CHMOD] = N_("cannot change mode of output file"),
|
|
Packit |
032894 |
[ASM_E_CANNOT_RENAME] = N_("cannot rename output file"),
|
|
Packit |
032894 |
[ASM_E_DUPLSYM] = N_("duplicate symbol"),
|
|
Packit |
032894 |
[ASM_E_TYPE] = N_("invalid section type for operation"),
|
|
Packit |
032894 |
[ASM_E_IOERROR] = N_("error during output of data"),
|
|
Packit |
032894 |
[ASM_E_ENOSUP] = N_("no backend support available"),
|
|
Packit |
032894 |
};
|
|
Packit |
032894 |
|
|
Packit |
032894 |
const char *
|
|
Packit |
032894 |
asm_errmsg (int error)
|
|
Packit |
032894 |
{
|
|
Packit |
032894 |
int last_error = global_error;
|
|
Packit |
032894 |
|
|
Packit |
032894 |
if (error < -1)
|
|
Packit |
032894 |
return _("unknown error");
|
|
Packit |
032894 |
if (error == 0 && last_error == 0)
|
|
Packit |
032894 |
/* No error. */
|
|
Packit |
032894 |
return NULL;
|
|
Packit |
032894 |
|
|
Packit |
032894 |
if (error != -1)
|
|
Packit |
032894 |
last_error = error;
|
|
Packit |
032894 |
|
|
Packit |
032894 |
if (last_error == ASM_E_LIBELF)
|
|
Packit |
032894 |
return elf_errmsg (-1);
|
|
Packit |
032894 |
|
|
Packit |
032894 |
return _(msgs[last_error]);
|
|
Packit |
032894 |
}
|