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 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame^] | 4 | libpng 1.0 beta 3 - version 0.89 |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 5 | For conditions of distribution and use, see copyright notice in png.h |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 6 | Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame^] | 7 | May 25, 1996 |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 8 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 9 | This file provides a location for all error handling. Users which |
Guy Schalnat | 69b1448 | 1996-01-10 02:56:49 -0600 | [diff] [blame] | 10 | need special error handling are expected to write replacement functions |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame^] | 11 | and use png_set_error_fn() to use those functions. See the instructions |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 12 | at each function. */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 13 | |
| 14 | #define PNG_INTERNAL |
| 15 | #include "png.h" |
| 16 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame^] | 17 | static void png_default_error PNGARG((png_structp png_ptr, |
| 18 | png_const_charp message)); |
| 19 | static void png_default_warning PNGARG((png_structp png_ptr, |
| 20 | png_const_charp message)); |
| 21 | |
Guy Schalnat | 69b1448 | 1996-01-10 02:56:49 -0600 | [diff] [blame] | 22 | /* This function is called whenever there is a fatal error. This function |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 23 | should not be changed. If there is a need to handle errors differently, |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame^] | 24 | you should supply a replacement error function and use png_set_error_fn() |
Guy Schalnat | 69b1448 | 1996-01-10 02:56:49 -0600 | [diff] [blame] | 25 | to replace the error function at run-time. */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 26 | void |
| 27 | png_error(png_structp png_ptr, png_const_charp message) |
| 28 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 29 | if (png_ptr->error_fn) |
| 30 | (*(png_ptr->error_fn))(png_ptr, message); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 31 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 32 | /* if the following returns or doesn't exist, use the default function, |
| 33 | which will not return */ |
| 34 | png_default_error(png_ptr, message); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 35 | } |
| 36 | |
Guy Schalnat | 69b1448 | 1996-01-10 02:56:49 -0600 | [diff] [blame] | 37 | /* This function is called whenever there is a non-fatal error. This function |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 38 | should not be changed. If there is a need to handle warnings differently, |
| 39 | you should supply a replacement warning function and use |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame^] | 40 | png_set_error_fn() to replace the warning function at run-time. */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 41 | void |
| 42 | png_warning(png_structp png_ptr, png_const_charp message) |
| 43 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 44 | if (png_ptr->warning_fn) |
| 45 | (*(png_ptr->warning_fn))(png_ptr, message); |
| 46 | else |
| 47 | png_default_warning(png_ptr, message); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 48 | } |
| 49 | |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 50 | /* This is the default error handling function. Note that replacements for |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 51 | this function MUST NOT RETURN, or the program will likely crash. This |
| 52 | function is used by default, or if the program supplies NULL for the |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame^] | 53 | error function pointer in png_set_error_fn(). */ |
| 54 | static void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 55 | png_default_error(png_structp png_ptr, png_const_charp message) |
| 56 | { |
| 57 | #ifndef PNG_NO_STDIO |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 58 | fprintf(stderr, "libpng error: %s\n", message); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 59 | #endif |
| 60 | |
| 61 | #ifdef USE_FAR_KEYWORD |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 62 | { |
| 63 | jmp_buf jmpbuf; |
| 64 | png_memcpy(jmpbuf,png_ptr->jmpbuf,sizeof(jmp_buf)); |
| 65 | longjmp(jmpbuf, 1); |
| 66 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 67 | #else |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 68 | longjmp(png_ptr->jmpbuf, 1); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 69 | #endif |
| 70 | } |
| 71 | |
Guy Schalnat | 69b1448 | 1996-01-10 02:56:49 -0600 | [diff] [blame] | 72 | /* This function is called when there is a warning, but the library thinks |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 73 | it can continue anyway. Replacement functions don't have to do anything |
| 74 | here if you don't want to. In the default configuration, png_ptr is |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 75 | not used, but it is passed in case it may be useful. */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame^] | 76 | static void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 77 | png_default_warning(png_structp png_ptr, png_const_charp message) |
| 78 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 79 | if (!png_ptr) |
| 80 | return; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 81 | |
| 82 | #ifndef PNG_NO_STDIO |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 83 | fprintf(stderr, "libpng warning: %s\n", message); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 84 | #endif |
| 85 | } |
| 86 | |
Guy Schalnat | 69b1448 | 1996-01-10 02:56:49 -0600 | [diff] [blame] | 87 | /* This function is called when the application wants to use another method |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 88 | of handling errors and warnings. Note that the error function MUST NOT |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame^] | 89 | return to the calling routine or serious problems will occur. The return |
| 90 | method used in the default routine calls longjmp(png_ptr->jmpbuf, 1) */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 91 | void |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame^] | 92 | png_set_error_fn(png_structp png_ptr, png_voidp error_ptr, |
| 93 | png_error_ptr error_fn, png_error_ptr warning_fn) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 94 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame^] | 95 | png_ptr->error_ptr = error_ptr; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 96 | png_ptr->error_fn = error_fn; |
| 97 | png_ptr->warning_fn = warning_fn; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame^] | 101 | /* This function returns a pointer to the error_ptr associated with the user |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 102 | functions. The application should free any memory associated with this |
| 103 | pointer before png_write_destroy and png_read_destroy are called. */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 104 | png_voidp |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame^] | 105 | png_get_error_ptr(png_structp png_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 106 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame^] | 107 | return png_ptr->error_ptr; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | |
| 111 | |