Annotation of parser3/src/lib/ltdl/lt_error.c, revision 1.2

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

E-mail: