1/* lt_error.c -- error propagation interface
2
3 Copyright (C) 1999-2001, 2004-2005, 2007, 2011-2015 Free Software
4 Foundation, Inc.
5 Written by Thomas Tanner, 1999
6
7 NOTE: The canonical source of this file is maintained with the
8 GNU Libtool package. Report bugs to bug-libtool@gnu.org.
9
10GNU Libltdl is free software; you can redistribute it and/or
11modify it under the terms of the GNU Lesser General Public
12License as published by the Free Software Foundation; either
13version 2 of the License, or (at your option) any later version.
14
15As a special exception to the GNU Lesser General Public License,
16if you distribute this file as part of a program or library that
17is built using GNU Libtool, you may include this file under the
18same distribution terms that you use for the rest of that program.
19
20GNU Libltdl is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23GNU Lesser General Public License for more details.
24
25You should have received a copy of the GNU Lesser General Public
26License along with GNU Libltdl; see the file COPYING.LIB. If not, a
27copy can be downloaded from http://www.gnu.org/licenses/lgpl.html,
28or obtained by writing to the Free Software Foundation, Inc.,
2951 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30*/
31
32#include "lt__private.h"
33#include "lt_error.h"
34
35static const char *last_error = 0;
36static const char error_strings[LT_ERROR_MAX][LT_ERROR_LEN_MAX + 1] =
37 {
38#define LT_ERROR(name, diagnostic) diagnostic,
39 lt_dlerror_table
40#undef LT_ERROR
41 };
42
43static const char **user_error_strings = 0;
44static int errorcount = LT_ERROR_MAX;
45
46int
47lt_dladderror (const char *diagnostic)
48{
49 int errindex = 0;
50 int result = -1;
51 const char **temp = (const char **) 0;
52
53 assert (diagnostic);
54
55 errindex = errorcount - LT_ERROR_MAX;
56 temp = REALLOC (const char *, user_error_strings, 1 + errindex);
57 if (temp)
58 {
59 user_error_strings = temp;
60 user_error_strings[errindex] = diagnostic;
61 result = errorcount++;
62 }
63
64 return result;
65}
66
67int
68lt_dlseterror (int errindex)
69{
70 int errors = 0;
71
72 if (errindex >= errorcount || errindex < 0)
73 {
74 /* Ack! Error setting the error message! */
75 LT__SETERROR (INVALID_ERRORCODE);
76 ++errors;
77 }
78 else if (errindex < LT_ERROR_MAX)
79 {
80 /* No error setting the error message! */
81 LT__SETERRORSTR (error_strings[errindex]);
82 }
83 else
84 {
85 /* No error setting the error message! */
86 LT__SETERRORSTR (user_error_strings[errindex - LT_ERROR_MAX]);
87 }
88
89 return errors;
90}
91
92const char *
93lt__error_string (int errorcode)
94{
95 assert (errorcode >= 0);
96 assert (errorcode < LT_ERROR_MAX);
97
98 return error_strings[errorcode];
99}
100
101const char *
102lt__get_last_error (void)
103{
104 return last_error;
105}
106
107const char *
108lt__set_last_error (const char *errormsg)
109{
110 return last_error = errormsg;
111}
112