1 /* lt_error.c -- error propogation interface
3 Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007 Free Software Foundation, Inc.
4 Written by Thomas Tanner, 1999
6 NOTE: The canonical source of this file is maintained with the
7 GNU Libtool package. Report bugs to bug-libtool@gnu.org.
9 GNU Libltdl is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
14 As a special exception to the GNU Lesser General Public License,
15 if you distribute this file as part of a program or library that
16 is built using GNU Libtool, you may include this file under the
17 same distribution terms that you use for the rest of that program.
19 GNU Libltdl is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU Lesser General Public License for more details.
24 You should have received a copy of the GNU Lesser General Public
25 License along with GNU Libltdl; see the file COPYING.LIB. If not, a
26 copy can be downloaded from http://www.gnu.org/licenses/lgpl.html,
27 or obtained by writing to the Free Software Foundation, Inc.,
28 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 #include "lt__private.h"
34 static const char *last_error
= 0;
35 static const char error_strings
[LT_ERROR_MAX
][LT_ERROR_LEN_MAX
+ 1] =
37 #define LT_ERROR(name, diagnostic) diagnostic,
42 static const char **user_error_strings
= 0;
43 static int errorcount
= LT_ERROR_MAX
;
46 lt_dladderror (const char *diagnostic
)
50 const char **temp
= (const char **) 0;
54 errindex
= errorcount
- LT_ERROR_MAX
;
55 temp
= REALLOC (const char *, user_error_strings
, 1 + errindex
);
58 user_error_strings
= temp
;
59 user_error_strings
[errindex
] = diagnostic
;
60 result
= errorcount
++;
67 lt_dlseterror (int errindex
)
71 if (errindex
>= errorcount
|| errindex
< 0)
73 /* Ack! Error setting the error message! */
74 LT__SETERROR (INVALID_ERRORCODE
);
77 else if (errindex
< LT_ERROR_MAX
)
79 /* No error setting the error message! */
80 LT__SETERRORSTR (error_strings
[errindex
]);
84 /* No error setting the error message! */
85 LT__SETERRORSTR (user_error_strings
[errindex
- LT_ERROR_MAX
]);
92 lt__error_string (int errorcode
)
94 assert (errorcode
>= 0);
95 assert (errorcode
< LT_ERROR_MAX
);
97 return error_strings
[errorcode
];
101 lt__get_last_error (void)
107 lt__set_last_error (const char *errormsg
)
109 return last_error
= errormsg
;