blob: 16c0c45ab35d5fa05c014bc615d20d5884edd468 [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Handle error.
2 Copyright (C) 2000, 2002 Red Hat, Inc.
3 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
4
5 This program is Open Source software; you can redistribute it and/or
6 modify it under the terms of the Open Software License version 1.0 as
7 published by the Open Source Initiative.
8
9 You should have received a copy of the Open Software License along
10 with this program; if not, you may obtain a copy of the Open Software
11 License version 1.0 from http://www.opensource.org/licenses/osl.php or
12 by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
13 3001 King Ranch Road, Ukiah, CA 95482. */
14
15#ifdef HAVE_CONFIG_H
16# include <config.h>
17#endif
18
19#include <assert.h>
20#include <stdlib.h>
21
22#include <libdwarfP.h>
23#include <system.h>
24
25
26void
27internal_function
28__libdwarf_error (Dwarf_Debug dbg, Dwarf_Error *error, int errval)
29{
30 /* Allocate memory for the error structure given to the user. */
31 Dwarf_Error errmem = (Dwarf_Error) malloc (sizeof (*error));
32 /* We cannot report an error if we cannot allocate memory. */
33 if (errmem == NULL)
34 return;
35
36 errmem->de_error = errval;
37
38 /* DBG must never be NULL. */
39 assert (dbg != NULL);
40
41 if (error != NULL)
42 /* If the user provides an ERROR parameter we have to use it. */
43 *error = errmem;
44 else if (likely (dbg->dbg_errhand != NULL))
45 /* Use the handler the user provided if possible. */
46 dbg->dbg_errhand (error, dbg->dbg_errarg);
47 else
48 {
49 assert (! "error and dbg->dbg_errhand == NULL");
50 abort ();
51 }
52}