Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame^] | 1 | |
| 2 | /* pngerror.c - stub functions for i/o and memory allocation |
| 3 | |
| 4 | libpng 1.0 beta 2 - version 0.85 |
| 5 | For conditions of distribution and use, see copyright notice in png.h |
| 6 | Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc. |
| 7 | December 19, 1995 |
| 8 | |
| 9 | This file provides a location for all error handling. Users which |
| 10 | need special error handling are expected to modify the code in this |
| 11 | file to meet their needs. See the instructions at each function. */ |
| 12 | |
| 13 | #define PNG_INTERNAL |
| 14 | #include "png.h" |
| 15 | |
| 16 | /* This function is called whenever there is an error. Replace with |
| 17 | however you wish to handle the error. Note that this function |
| 18 | MUST NOT return, or the program will crash */ |
| 19 | void |
| 20 | png_error(png_structp png_ptr, png_const_charp message) |
| 21 | { |
| 22 | if (png_ptr->error_fn) |
| 23 | (*(png_ptr->error_fn))(png_ptr, message); |
| 24 | |
| 25 | /* if the following returns or doesn't exist, use the default function, |
| 26 | which will not return */ |
| 27 | png_default_error(png_ptr, message); |
| 28 | } |
| 29 | |
| 30 | void |
| 31 | png_warning(png_structp png_ptr, png_const_charp message) |
| 32 | { |
| 33 | if (png_ptr->warning_fn) |
| 34 | (*(png_ptr->warning_fn))(png_ptr, message); |
| 35 | else |
| 36 | png_default_warning(png_ptr, message); |
| 37 | } |
| 38 | |
| 39 | void |
| 40 | png_default_error(png_structp png_ptr, png_const_charp message) |
| 41 | { |
| 42 | #ifndef PNG_NO_STDIO |
| 43 | fprintf(stderr, "libpng error: %s\n", message); |
| 44 | #endif |
| 45 | |
| 46 | #ifdef USE_FAR_KEYWORD |
| 47 | { |
| 48 | jmp_buf jmpbuf; |
| 49 | png_memcpy(jmpbuf,png_ptr->jmpbuf,sizeof(jmp_buf)); |
| 50 | longjmp(jmpbuf, 1); |
| 51 | } |
| 52 | #else |
| 53 | longjmp(png_ptr->jmpbuf, 1); |
| 54 | #endif |
| 55 | } |
| 56 | |
| 57 | /* This function is called when there is a warning, but the library |
| 58 | thinks it can continue anyway. You don't have to do anything here |
| 59 | if you don't want to. In the default configuration, png_ptr is |
| 60 | not used, but it is passed in case it may be useful. */ |
| 61 | |
| 62 | void |
| 63 | png_default_warning(png_structp png_ptr, png_const_charp message) |
| 64 | { |
| 65 | if (!png_ptr) |
| 66 | return; |
| 67 | |
| 68 | #ifndef PNG_NO_STDIO |
| 69 | fprintf(stderr, "libpng warning: %s\n", message); |
| 70 | #endif |
| 71 | } |
| 72 | |
| 73 | /* This function is called when the application wants to use another |
| 74 | method of handling errors and warnings. Note that the error function must |
| 75 | NOT return to the calling routine or serious problems will occur. The |
| 76 | error return method used in the default routine calls |
| 77 | longjmp(png_ptr->jmpbuf, 1) */ |
| 78 | void |
| 79 | png_set_message_fn(png_structp png_ptr, png_voidp msg_ptr, png_msg_ptr error_fn, |
| 80 | png_msg_ptr warning_fn) |
| 81 | { |
| 82 | png_ptr->msg_ptr = msg_ptr; |
| 83 | |
| 84 | png_ptr->error_fn = error_fn; |
| 85 | png_ptr->warning_fn = warning_fn; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | /* This function returns a pointer to the msg_ptr associated with the user |
| 90 | functions. The application should free any memory associated with this |
| 91 | pointer before png_write_destroy and png_read_destroy are called. */ |
| 92 | png_voidp |
| 93 | png_get_msg_ptr(png_structp png_ptr) |
| 94 | { |
| 95 | return png_ptr->msg_ptr; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | |