tif_error.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (c) 1988-1997 Sam Leffler
  3. * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  4. *
  5. * Permission to use, copy, modify, distribute, and sell this software and
  6. * its documentation for any purpose is hereby granted without fee, provided
  7. * that (i) the above copyright notices and this permission notice appear in
  8. * all copies of the software and related documentation, and (ii) the names of
  9. * Sam Leffler and Silicon Graphics may not be used in any advertising or
  10. * publicity relating to the software without the specific, prior written
  11. * permission of Sam Leffler and Silicon Graphics.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  14. * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  15. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  18. * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  19. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
  21. * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  22. * OF THIS SOFTWARE.
  23. */
  24. /*
  25. * TIFF Library.
  26. */
  27. #include "tiffiop.h"
  28. TIFFErrorHandlerExt _TIFFerrorHandlerExt = NULL;
  29. TIFFErrorHandler TIFFSetErrorHandler(TIFFErrorHandler handler)
  30. {
  31. TIFFErrorHandler prev = _TIFFerrorHandler;
  32. _TIFFerrorHandler = handler;
  33. return (prev);
  34. }
  35. TIFFErrorHandlerExt TIFFSetErrorHandlerExt(TIFFErrorHandlerExt handler)
  36. {
  37. TIFFErrorHandlerExt prev = _TIFFerrorHandlerExt;
  38. _TIFFerrorHandlerExt = handler;
  39. return (prev);
  40. }
  41. void TIFFError(const char *module, const char *fmt, ...)
  42. {
  43. va_list ap;
  44. if (_TIFFerrorHandler)
  45. {
  46. va_start(ap, fmt);
  47. (*_TIFFerrorHandler)(module, fmt, ap);
  48. va_end(ap);
  49. }
  50. if (_TIFFerrorHandlerExt)
  51. {
  52. va_start(ap, fmt);
  53. (*_TIFFerrorHandlerExt)(0, module, fmt, ap);
  54. va_end(ap);
  55. }
  56. }
  57. void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt, ...)
  58. {
  59. va_list ap;
  60. if (_TIFFerrorHandler)
  61. {
  62. va_start(ap, fmt);
  63. (*_TIFFerrorHandler)(module, fmt, ap);
  64. va_end(ap);
  65. }
  66. if (_TIFFerrorHandlerExt)
  67. {
  68. va_start(ap, fmt);
  69. (*_TIFFerrorHandlerExt)(fd, module, fmt, ap);
  70. va_end(ap);
  71. }
  72. }
  73. void _TIFFErrorEarly(TIFFOpenOptions *opts, thandle_t clientdata,
  74. const char *module, const char *fmt, ...)
  75. {
  76. va_list ap;
  77. if (opts && opts->errorhandler)
  78. {
  79. va_start(ap, fmt);
  80. int stop = opts->errorhandler(NULL, opts->errorhandler_user_data,
  81. module, fmt, ap);
  82. va_end(ap);
  83. if (stop)
  84. return;
  85. }
  86. if (_TIFFerrorHandler)
  87. {
  88. va_start(ap, fmt);
  89. (*_TIFFerrorHandler)(module, fmt, ap);
  90. va_end(ap);
  91. }
  92. if (_TIFFerrorHandlerExt)
  93. {
  94. va_start(ap, fmt);
  95. (*_TIFFerrorHandlerExt)(clientdata, module, fmt, ap);
  96. va_end(ap);
  97. }
  98. }
  99. void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt, ...)
  100. {
  101. va_list ap;
  102. if (tif && tif->tif_errorhandler)
  103. {
  104. va_start(ap, fmt);
  105. int stop = (*tif->tif_errorhandler)(
  106. tif, tif->tif_errorhandler_user_data, module, fmt, ap);
  107. va_end(ap);
  108. if (stop)
  109. return;
  110. }
  111. if (_TIFFerrorHandler)
  112. {
  113. va_start(ap, fmt);
  114. (*_TIFFerrorHandler)(module, fmt, ap);
  115. va_end(ap);
  116. }
  117. if (_TIFFerrorHandlerExt)
  118. {
  119. va_start(ap, fmt);
  120. (*_TIFFerrorHandlerExt)(tif ? tif->tif_clientdata : NULL, module, fmt,
  121. ap);
  122. va_end(ap);
  123. }
  124. }