core: use the default font for the main splash message if not requested otherwise
[fbsplash.git] / core / libs / libpng-1.2.18 / pngerror.c
blobf50f6534427412a5ad006a5ae03630f3d4c90c6b
2 /* pngerror.c - stub functions for i/o and memory allocation
4 * Last changed in libpng 1.2.13 November 13, 2006
5 * For conditions of distribution and use, see copyright notice in png.h
6 * Copyright (c) 1998-2006 Glenn Randers-Pehrson
7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
10 * This file provides a location for all error handling. Users who
11 * 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.
16 #define PNG_INTERNAL
17 #include "png.h"
19 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
20 static void /* PRIVATE */
21 png_default_error PNGARG((png_structp png_ptr,
22 png_const_charp error_message));
23 static void /* PRIVATE */
24 png_default_warning PNGARG((png_structp png_ptr,
25 png_const_charp warning_message));
27 /* This function is called whenever there is a fatal error. This function
28 * should not be changed. If there is a need to handle errors differently,
29 * you should supply a replacement error function and use png_set_error_fn()
30 * to replace the error function at run-time.
32 void PNGAPI
33 png_error(png_structp png_ptr, png_const_charp error_message)
35 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
36 char msg[16];
37 if (png_ptr != NULL)
39 if (png_ptr->flags&
40 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
42 if (*error_message == '#')
44 int offset;
45 for (offset=1; offset<15; offset++)
46 if (*(error_message+offset) == ' ')
47 break;
48 if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
50 int i;
51 for (i=0; i<offset-1; i++)
52 msg[i]=error_message[i+1];
53 msg[i]='\0';
54 error_message=msg;
56 else
57 error_message+=offset;
59 else
61 if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
63 msg[0]='0';
64 msg[1]='\0';
65 error_message=msg;
70 #endif
71 if (png_ptr != NULL && png_ptr->error_fn != NULL)
72 (*(png_ptr->error_fn))(png_ptr, error_message);
74 /* If the custom handler doesn't exist, or if it returns,
75 use the default handler, which will not return. */
76 png_default_error(png_ptr, error_message);
79 /* This function is called whenever there is a non-fatal error. This function
80 * should not be changed. If there is a need to handle warnings differently,
81 * you should supply a replacement warning function and use
82 * png_set_error_fn() to replace the warning function at run-time.
84 void PNGAPI
85 png_warning(png_structp png_ptr, png_const_charp warning_message)
87 int offset = 0;
88 if (png_ptr != NULL)
90 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
91 if (png_ptr->flags&
92 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
93 #endif
95 if (*warning_message == '#')
97 for (offset=1; offset<15; offset++)
98 if (*(warning_message+offset) == ' ')
99 break;
102 if (png_ptr != NULL && png_ptr->warning_fn != NULL)
103 (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
105 else
106 png_default_warning(png_ptr, warning_message+offset);
109 /* These utilities are used internally to build an error message that relates
110 * to the current chunk. The chunk name comes from png_ptr->chunk_name,
111 * this is used to prefix the message. The message is limited in length
112 * to 63 bytes, the name characters are output as hex digits wrapped in []
113 * if the character is invalid.
115 #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
116 const static PNG_CONST char png_digit[16] = {
117 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
118 'A', 'B', 'C', 'D', 'E', 'F'
121 static void /* PRIVATE */
122 png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
123 error_message)
125 int iout = 0, iin = 0;
127 while (iin < 4)
129 int c = png_ptr->chunk_name[iin++];
130 if (isnonalpha(c))
132 buffer[iout++] = '[';
133 buffer[iout++] = png_digit[(c & 0xf0) >> 4];
134 buffer[iout++] = png_digit[c & 0x0f];
135 buffer[iout++] = ']';
137 else
139 buffer[iout++] = (png_byte)c;
143 if (error_message == NULL)
144 buffer[iout] = 0;
145 else
147 buffer[iout++] = ':';
148 buffer[iout++] = ' ';
149 png_strncpy(buffer+iout, error_message, 63);
150 buffer[iout+63] = 0;
154 void PNGAPI
155 png_chunk_error(png_structp png_ptr, png_const_charp error_message)
157 char msg[18+64];
158 if (png_ptr == NULL)
159 png_error(png_ptr, error_message);
160 else
162 png_format_buffer(png_ptr, msg, error_message);
163 png_error(png_ptr, msg);
167 void PNGAPI
168 png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
170 char msg[18+64];
171 if (png_ptr == NULL)
172 png_warning(png_ptr, warning_message);
173 else
175 png_format_buffer(png_ptr, msg, warning_message);
176 png_warning(png_ptr, msg);
180 /* This is the default error handling function. Note that replacements for
181 * this function MUST NOT RETURN, or the program will likely crash. This
182 * function is used by default, or if the program supplies NULL for the
183 * error function pointer in png_set_error_fn().
185 static void /* PRIVATE */
186 png_default_error(png_structp png_ptr, png_const_charp error_message)
188 #ifndef PNG_NO_CONSOLE_IO
189 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
190 if (*error_message == '#')
192 int offset;
193 char error_number[16];
194 for (offset=0; offset<15; offset++)
196 error_number[offset] = *(error_message+offset+1);
197 if (*(error_message+offset) == ' ')
198 break;
200 if((offset > 1) && (offset < 15))
202 error_number[offset-1]='\0';
203 fprintf(stderr, "libpng error no. %s: %s\n", error_number,
204 error_message+offset);
206 else
207 fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
209 else
210 #endif
211 fprintf(stderr, "libpng error: %s\n", error_message);
212 #endif
214 #ifdef PNG_SETJMP_SUPPORTED
215 if (png_ptr)
217 # ifdef USE_FAR_KEYWORD
219 jmp_buf jmpbuf;
220 png_memcpy(jmpbuf,png_ptr->jmpbuf,png_sizeof(jmp_buf));
221 longjmp(jmpbuf, 1);
223 # else
224 longjmp(png_ptr->jmpbuf, 1);
225 # endif
227 #else
228 PNG_ABORT();
229 #endif
230 #ifdef PNG_NO_CONSOLE_IO
231 /* make compiler happy */ ;
232 if (&error_message != NULL)
233 return;
234 #endif
237 /* This function is called when there is a warning, but the library thinks
238 * it can continue anyway. Replacement functions don't have to do anything
239 * here if you don't want them to. In the default configuration, png_ptr is
240 * not used, but it is passed in case it may be useful.
242 static void /* PRIVATE */
243 png_default_warning(png_structp png_ptr, png_const_charp warning_message)
245 #ifndef PNG_NO_CONSOLE_IO
246 # ifdef PNG_ERROR_NUMBERS_SUPPORTED
247 if (*warning_message == '#')
249 int offset;
250 char warning_number[16];
251 for (offset=0; offset<15; offset++)
253 warning_number[offset]=*(warning_message+offset+1);
254 if (*(warning_message+offset) == ' ')
255 break;
257 if((offset > 1) && (offset < 15))
259 warning_number[offset-1]='\0';
260 fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
261 warning_message+offset);
263 else
264 fprintf(stderr, "libpng warning: %s\n", warning_message);
266 else
267 # endif
268 fprintf(stderr, "libpng warning: %s\n", warning_message);
269 #else
270 /* make compiler happy */ ;
271 if (warning_message)
272 return;
273 #endif
274 /* make compiler happy */ ;
275 if (png_ptr)
276 return;
279 /* This function is called when the application wants to use another method
280 * of handling errors and warnings. Note that the error function MUST NOT
281 * return to the calling routine or serious problems will occur. The return
282 * method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)
284 void PNGAPI
285 png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
286 png_error_ptr error_fn, png_error_ptr warning_fn)
288 if (png_ptr == NULL)
289 return;
290 png_ptr->error_ptr = error_ptr;
291 png_ptr->error_fn = error_fn;
292 png_ptr->warning_fn = warning_fn;
296 /* This function returns a pointer to the error_ptr associated with the user
297 * functions. The application should free any memory associated with this
298 * pointer before png_write_destroy and png_read_destroy are called.
300 png_voidp PNGAPI
301 png_get_error_ptr(png_structp png_ptr)
303 if (png_ptr == NULL)
304 return NULL;
305 return ((png_voidp)png_ptr->error_ptr);
309 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
310 void PNGAPI
311 png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
313 if(png_ptr != NULL)
315 png_ptr->flags &=
316 ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
319 #endif
320 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */