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