lt_error.c 2.9 KB

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