source: squid-ssl/trunk/fuentes/libltdl/lt_error.c @ 5496

Last change on this file since 5496 was 5496, checked in by Juanma, 21 months ago

Initial release

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