blob: 97dbd66dc1755ce54731040dab0d30cfd102d8be [file] [log] [blame]
Guy Schalnat6d764711995-12-19 03:22:19 -06001
2/* pngerror.c - stub functions for i/o and memory allocation
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06003 *
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05004 * Last changed in libpng 1.4.0 [July 10, 2008]
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06005 * For conditions of distribution and use, see copyright notice in png.h
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05006 * Copyright (c) 1998-2008 Glenn Randers-Pehrson
Glenn Randers-Pehrsond4366722000-06-04 14:29:29 -05007 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06009 *
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -050010 * This file provides a location for all error handling. Users who
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060011 * need special error handling are expected to write replacement functions
12 * and use png_set_error_fn() to use those functions. See the instructions
13 * at each function.
14 */
Guy Schalnat6d764711995-12-19 03:22:19 -060015
Guy Schalnat6d764711995-12-19 03:22:19 -060016#include "png.h"
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050017#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -050018#include "pngpriv.h"
Guy Schalnat6d764711995-12-19 03:22:19 -060019
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050020static void /* PRIVATE */
21png_default_error PNGARG((png_structp png_ptr,
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -050022 png_const_charp error_message));
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050023#ifndef PNG_NO_WARNINGS
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050024static void /* PRIVATE */
25png_default_warning PNGARG((png_structp png_ptr,
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -050026 png_const_charp warning_message));
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050027#endif /* PNG_NO_WARNINGS */
Guy Schalnate5a37791996-06-05 15:50:50 -050028
Guy Schalnat69b14481996-01-10 02:56:49 -060029/* This function is called whenever there is a fatal error. This function
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060030 * should not be changed. If there is a need to handle errors differently,
31 * you should supply a replacement error function and use png_set_error_fn()
32 * to replace the error function at run-time.
33 */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050034#ifndef PNG_NO_ERROR_TEXT
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050035void PNGAPI
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -050036png_error(png_structp png_ptr, png_const_charp error_message)
Guy Schalnat6d764711995-12-19 03:22:19 -060037{
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -050038#ifdef PNG_ERROR_NUMBERS_SUPPORTED
39 char msg[16];
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -060040 if (png_ptr != NULL)
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -050041 {
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -060042 if (png_ptr->flags&
43 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -050044 {
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -060045 if (*error_message == '#')
46 {
47 int offset;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050048 for (offset = 1; offset<15; offset++)
49 if (*(error_message + offset) == ' ')
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -060050 break;
51 if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
52 {
53 int i;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050054 for (i=0; i<offset - 1; i++)
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -060055 msg[i]=error_message[i+1];
56 msg[i]='\0';
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050057 error_message = msg;
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -060058 }
59 else
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050060 error_message += offset;
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -060061 }
62 else
63 {
64 if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
65 {
66 msg[0]='0';
67 msg[1]='\0';
68 error_message=msg;
69 }
70 }
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -050071 }
72 }
73#endif
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -050074 if (png_ptr != NULL && png_ptr->error_fn != NULL)
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -050075 (*(png_ptr->error_fn))(png_ptr, error_message);
Guy Schalnat6d764711995-12-19 03:22:19 -060076
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -050077 /* If the custom handler doesn't exist, or if it returns,
78 use the default handler, which will not return. */
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -050079 png_default_error(png_ptr, error_message);
Guy Schalnat6d764711995-12-19 03:22:19 -060080}
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050081#else
82void PNGAPI
83png_err(png_structp png_ptr)
84{
85 if (png_ptr != NULL && png_ptr->error_fn != NULL)
86 (*(png_ptr->error_fn))(png_ptr, '\0');
Guy Schalnat6d764711995-12-19 03:22:19 -060087
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050088 /* If the custom handler doesn't exist, or if it returns,
89 use the default handler, which will not return. */
90 png_default_error(png_ptr, '\0');
91}
92#endif /* PNG_NO_ERROR_TEXT */
93
94#ifndef PNG_NO_WARNINGS
Guy Schalnat69b14481996-01-10 02:56:49 -060095/* This function is called whenever there is a non-fatal error. This function
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060096 * should not be changed. If there is a need to handle warnings differently,
97 * you should supply a replacement warning function and use
98 * png_set_error_fn() to replace the warning function at run-time.
99 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500100void PNGAPI
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -0500101png_warning(png_structp png_ptr, png_const_charp warning_message)
Guy Schalnat6d764711995-12-19 03:22:19 -0600102{
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500103 int offset = 0;
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -0600104 if (png_ptr != NULL)
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500105 {
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -0600106#ifdef PNG_ERROR_NUMBERS_SUPPORTED
107 if (png_ptr->flags&
108 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
109#endif
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500110 {
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -0600111 if (*warning_message == '#')
112 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500113 for (offset = 1; offset<15; offset++)
114 if (*(warning_message + offset) == ' ')
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -0600115 break;
116 }
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500117 }
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -0600118 if (png_ptr != NULL && png_ptr->warning_fn != NULL)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500119 (*(png_ptr->warning_fn))(png_ptr, warning_message + offset);
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500120 }
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600121 else
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500122 png_default_warning(png_ptr, warning_message + offset);
Guy Schalnat6d764711995-12-19 03:22:19 -0600123}
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500124#endif /* PNG_NO_WARNINGS */
Guy Schalnat6d764711995-12-19 03:22:19 -0600125
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500126#ifdef PNG_BENIGN_ERRORS_SUPPORTED
127void PNGAPI
128png_benign_error(png_structp png_ptr, png_const_charp error_message)
129{
130 if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
131 png_warning(png_ptr, error_message);
132 else
133 png_error(png_ptr, error_message);
134}
135#endif
136
Glenn Randers-Pehrsoncfbed9b2002-05-21 18:06:08 -0500137/* These utilities are used internally to build an error message that relates
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600138 * to the current chunk. The chunk name comes from png_ptr->chunk_name,
139 * this is used to prefix the message. The message is limited in length
140 * to 63 bytes, the name characters are output as hex digits wrapped in []
141 * if the character is invalid.
142 */
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500143#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
Glenn Randers-Pehrson7cd899c1998-03-07 16:17:42 -0600144static PNG_CONST char png_digit[16] = {
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500145 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
146 'A', 'B', 'C', 'D', 'E', 'F'
147};
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600148
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500149#define PNG_MAX_ERROR_TEXT 64
150
151#if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500152static void /* PRIVATE */
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -0500153png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -0500154 error_message)
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600155{
156 int iout = 0, iin = 0;
157
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600158 while (iin < 4)
159 {
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600160 int c = png_ptr->chunk_name[iin++];
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600161 if (isnonalpha(c))
162 {
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600163 buffer[iout++] = '[';
164 buffer[iout++] = png_digit[(c & 0xf0) >> 4];
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600165 buffer[iout++] = png_digit[c & 0x0f];
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600166 buffer[iout++] = ']';
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600167 }
168 else
169 {
Glenn Randers-Pehrson860ab2b1999-10-14 07:43:10 -0500170 buffer[iout++] = (png_byte)c;
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600171 }
172 }
173
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -0500174 if (error_message == NULL)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500175 buffer[iout] = '\0';
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600176 else
177 {
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600178 buffer[iout++] = ':';
179 buffer[iout++] = ' ';
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500180 png_memcpy(buffer + iout, error_message, PNG_MAX_ERROR_TEXT);
181 buffer[iout + PNG_MAX_ERROR_TEXT - 1] = '\0';
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600182 }
183}
184
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500185#ifdef PNG_READ_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500186void PNGAPI
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -0500187png_chunk_error(png_structp png_ptr, png_const_charp error_message)
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600188{
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500189 char msg[18+PNG_MAX_ERROR_TEXT];
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -0600190 if (png_ptr == NULL)
191 png_error(png_ptr, error_message);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500192 else
193 {
194 png_format_buffer(png_ptr, msg, error_message);
195 png_error(png_ptr, msg);
196 }
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600197}
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500198#endif /* PNG_READ_SUPPORTED */
199#endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600200
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500201#ifndef PNG_NO_WARNINGS
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500202void PNGAPI
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -0500203png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600204{
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500205 char msg[18+PNG_MAX_ERROR_TEXT];
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -0600206 if (png_ptr == NULL)
207 png_warning(png_ptr, warning_message);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500208 else
209 {
210 png_format_buffer(png_ptr, msg, warning_message);
211 png_warning(png_ptr, msg);
212 }
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600213}
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500214#endif /* PNG_NO_WARNINGS */
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600215
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500216#ifdef PNG_READ_SUPPORTED
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500217#ifdef PNG_BENIGN_ERRORS_SUPPORTED
218void PNGAPI
219png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message)
220{
221 if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
222 png_chunk_warning(png_ptr, error_message);
223 else
224 png_chunk_error(png_ptr, error_message);
225}
226#endif
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500227#endif /* PNG_READ_SUPPORTED */
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500228
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600229/* This is the default error handling function. Note that replacements for
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600230 * this function MUST NOT RETURN, or the program will likely crash. This
231 * function is used by default, or if the program supplies NULL for the
232 * error function pointer in png_set_error_fn().
233 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500234static void /* PRIVATE */
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -0500235png_default_error(png_structp png_ptr, png_const_charp error_message)
Guy Schalnat6d764711995-12-19 03:22:19 -0600236{
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600237#ifndef PNG_NO_CONSOLE_IO
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500238#ifdef PNG_ERROR_NUMBERS_SUPPORTED
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -0500239 if (*error_message == '#')
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500240 {
241 int offset;
242 char error_number[16];
243 for (offset=0; offset<15; offset++)
244 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500245 error_number[offset] = *(error_message + offset + 1);
246 if (*(error_message + offset) == ' ')
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500247 break;
248 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500249 if ((offset > 1) && (offset < 15))
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500250 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500251 error_number[offset - 1]='\0';
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -0500252 fprintf(stderr, "libpng error no. %s: %s\n", error_number,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500253 error_message + offset);
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500254 }
255 else
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500256 fprintf(stderr, "libpng error: %s, offset=%d\n", error_message, offset);
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500257 }
258 else
259#endif
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -0500260 fprintf(stderr, "libpng error: %s\n", error_message);
Guy Schalnat6d764711995-12-19 03:22:19 -0600261#endif
262
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600263#ifdef PNG_SETJMP_SUPPORTED
Glenn Randers-Pehrson6b12c082006-11-14 10:53:30 -0600264 if (png_ptr)
265 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600266# ifdef USE_FAR_KEYWORD
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600267 {
268 jmp_buf jmpbuf;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500269 png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600270 longjmp(jmpbuf, 1);
271 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600272# else
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600273 longjmp(png_ptr->jmpbuf, 1);
Glenn Randers-Pehrson6b12c082006-11-14 10:53:30 -0600274# endif
275 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600276#else
277 PNG_ABORT();
Guy Schalnat6d764711995-12-19 03:22:19 -0600278#endif
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500279#ifdef PNG_NO_CONSOLE_IO
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500280 error_message = error_message; /* make compiler happy */
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500281#endif
Guy Schalnat6d764711995-12-19 03:22:19 -0600282}
283
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500284#ifndef PNG_NO_WARNINGS
Guy Schalnat69b14481996-01-10 02:56:49 -0600285/* This function is called when there is a warning, but the library thinks
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600286 * it can continue anyway. Replacement functions don't have to do anything
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -0500287 * here if you don't want them to. In the default configuration, png_ptr is
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600288 * not used, but it is passed in case it may be useful.
289 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500290static void /* PRIVATE */
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -0500291png_default_warning(png_structp png_ptr, png_const_charp warning_message)
Guy Schalnat6d764711995-12-19 03:22:19 -0600292{
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600293#ifndef PNG_NO_CONSOLE_IO
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500294# ifdef PNG_ERROR_NUMBERS_SUPPORTED
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -0500295 if (*warning_message == '#')
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500296 {
297 int offset;
298 char warning_number[16];
299 for (offset=0; offset<15; offset++)
300 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500301 warning_number[offset]=*(warning_message + offset + 1);
302 if (*(warning_message + offset) == ' ')
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500303 break;
304 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500305 if ((offset > 1) && (offset < 15))
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500306 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500307 warning_number[offset + 1]='\0';
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500308 fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500309 warning_message + offset);
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500310 }
311 else
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -0500312 fprintf(stderr, "libpng warning: %s\n", warning_message);
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500313 }
314 else
315# endif
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -0500316 fprintf(stderr, "libpng warning: %s\n", warning_message);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500317#else
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500318 warning_message = warning_message; /* make compiler happy */
Guy Schalnat6d764711995-12-19 03:22:19 -0600319#endif
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500320 png_ptr = png_ptr; /* make compiler happy */
Guy Schalnat6d764711995-12-19 03:22:19 -0600321}
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500322#endif /* PNG_NO_WARNINGS */
Guy Schalnat6d764711995-12-19 03:22:19 -0600323
Guy Schalnat69b14481996-01-10 02:56:49 -0600324/* This function is called when the application wants to use another method
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600325 * of handling errors and warnings. Note that the error function MUST NOT
326 * return to the calling routine or serious problems will occur. The return
327 * method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)
328 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500329void PNGAPI
Guy Schalnate5a37791996-06-05 15:50:50 -0500330png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
331 png_error_ptr error_fn, png_error_ptr warning_fn)
Guy Schalnat6d764711995-12-19 03:22:19 -0600332{
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -0600333 if (png_ptr == NULL)
334 return;
Guy Schalnate5a37791996-06-05 15:50:50 -0500335 png_ptr->error_ptr = error_ptr;
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600336 png_ptr->error_fn = error_fn;
337 png_ptr->warning_fn = warning_fn;
Guy Schalnat6d764711995-12-19 03:22:19 -0600338}
339
340
Guy Schalnate5a37791996-06-05 15:50:50 -0500341/* This function returns a pointer to the error_ptr associated with the user
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600342 * functions. The application should free any memory associated with this
343 * pointer before png_write_destroy and png_read_destroy are called.
344 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500345png_voidp PNGAPI
Guy Schalnate5a37791996-06-05 15:50:50 -0500346png_get_error_ptr(png_structp png_ptr)
Guy Schalnat6d764711995-12-19 03:22:19 -0600347{
Glenn Randers-Pehrson170b70c2006-03-10 10:19:04 -0600348 if (png_ptr == NULL)
349 return NULL;
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600350 return ((png_voidp)png_ptr->error_ptr);
Guy Schalnat6d764711995-12-19 03:22:19 -0600351}
352
353
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500354#ifdef PNG_ERROR_NUMBERS_SUPPORTED
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -0600355void PNGAPI
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500356png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
357{
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500358 if (png_ptr != NULL)
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -0500359 {
360 png_ptr->flags &=
361 ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
362 }
363}
364#endif
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600365#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */