blob: 0e286ae4e1d6d08b6c6a6597063dbdbccaccf011 [file] [log] [blame]
Guy Schalnat6d764711995-12-19 03:22:19 -06001
2/* pngerror.c - stub functions for i/o and memory allocation
3
Guy Schalnate5a37791996-06-05 15:50:50 -05004 libpng 1.0 beta 3 - version 0.89
Guy Schalnat6d764711995-12-19 03:22:19 -06005 For conditions of distribution and use, see copyright notice in png.h
Guy Schalnatb2e01bd1996-01-26 01:38:47 -06006 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
Guy Schalnate5a37791996-06-05 15:50:50 -05007 May 25, 1996
Guy Schalnat6d764711995-12-19 03:22:19 -06008
Guy Schalnatb2e01bd1996-01-26 01:38:47 -06009 This file provides a location for all error handling. Users which
Guy Schalnat69b14481996-01-10 02:56:49 -060010 need special error handling are expected to write replacement functions
Guy Schalnate5a37791996-06-05 15:50:50 -050011 and use png_set_error_fn() to use those functions. See the instructions
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060012 at each function. */
Guy Schalnat6d764711995-12-19 03:22:19 -060013
14#define PNG_INTERNAL
15#include "png.h"
16
Guy Schalnate5a37791996-06-05 15:50:50 -050017static void png_default_error PNGARG((png_structp png_ptr,
18 png_const_charp message));
19static void png_default_warning PNGARG((png_structp png_ptr,
20 png_const_charp message));
21
Guy Schalnat69b14481996-01-10 02:56:49 -060022/* This function is called whenever there is a fatal error. This function
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060023 should not be changed. If there is a need to handle errors differently,
Guy Schalnate5a37791996-06-05 15:50:50 -050024 you should supply a replacement error function and use png_set_error_fn()
Guy Schalnat69b14481996-01-10 02:56:49 -060025 to replace the error function at run-time. */
Guy Schalnat6d764711995-12-19 03:22:19 -060026void
27png_error(png_structp png_ptr, png_const_charp message)
28{
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060029 if (png_ptr->error_fn)
30 (*(png_ptr->error_fn))(png_ptr, message);
Guy Schalnat6d764711995-12-19 03:22:19 -060031
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060032 /* 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 Schalnat6d764711995-12-19 03:22:19 -060035}
36
Guy Schalnat69b14481996-01-10 02:56:49 -060037/* This function is called whenever there is a non-fatal error. This function
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060038 should not be changed. If there is a need to handle warnings differently,
39 you should supply a replacement warning function and use
Guy Schalnate5a37791996-06-05 15:50:50 -050040 png_set_error_fn() to replace the warning function at run-time. */
Guy Schalnat6d764711995-12-19 03:22:19 -060041void
42png_warning(png_structp png_ptr, png_const_charp message)
43{
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060044 if (png_ptr->warning_fn)
45 (*(png_ptr->warning_fn))(png_ptr, message);
46 else
47 png_default_warning(png_ptr, message);
Guy Schalnat6d764711995-12-19 03:22:19 -060048}
49
Guy Schalnat4ee97b01996-01-16 01:51:56 -060050/* This is the default error handling function. Note that replacements for
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060051 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 Schalnate5a37791996-06-05 15:50:50 -050053 error function pointer in png_set_error_fn(). */
54static void
Guy Schalnat6d764711995-12-19 03:22:19 -060055png_default_error(png_structp png_ptr, png_const_charp message)
56{
57#ifndef PNG_NO_STDIO
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060058 fprintf(stderr, "libpng error: %s\n", message);
Guy Schalnat6d764711995-12-19 03:22:19 -060059#endif
60
61#ifdef USE_FAR_KEYWORD
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060062 {
63 jmp_buf jmpbuf;
64 png_memcpy(jmpbuf,png_ptr->jmpbuf,sizeof(jmp_buf));
65 longjmp(jmpbuf, 1);
66 }
Guy Schalnat6d764711995-12-19 03:22:19 -060067#else
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060068 longjmp(png_ptr->jmpbuf, 1);
Guy Schalnat6d764711995-12-19 03:22:19 -060069#endif
70}
71
Guy Schalnat69b14481996-01-10 02:56:49 -060072/* This function is called when there is a warning, but the library thinks
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060073 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 Schalnat6d764711995-12-19 03:22:19 -060075 not used, but it is passed in case it may be useful. */
Guy Schalnate5a37791996-06-05 15:50:50 -050076static void
Guy Schalnat6d764711995-12-19 03:22:19 -060077png_default_warning(png_structp png_ptr, png_const_charp message)
78{
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060079 if (!png_ptr)
80 return;
Guy Schalnat6d764711995-12-19 03:22:19 -060081
82#ifndef PNG_NO_STDIO
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060083 fprintf(stderr, "libpng warning: %s\n", message);
Guy Schalnat6d764711995-12-19 03:22:19 -060084#endif
85}
86
Guy Schalnat69b14481996-01-10 02:56:49 -060087/* This function is called when the application wants to use another method
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060088 of handling errors and warnings. Note that the error function MUST NOT
Guy Schalnate5a37791996-06-05 15:50:50 -050089 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 Schalnat6d764711995-12-19 03:22:19 -060091void
Guy Schalnate5a37791996-06-05 15:50:50 -050092png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
93 png_error_ptr error_fn, png_error_ptr warning_fn)
Guy Schalnat6d764711995-12-19 03:22:19 -060094{
Guy Schalnate5a37791996-06-05 15:50:50 -050095 png_ptr->error_ptr = error_ptr;
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060096 png_ptr->error_fn = error_fn;
97 png_ptr->warning_fn = warning_fn;
Guy Schalnat6d764711995-12-19 03:22:19 -060098}
99
100
Guy Schalnate5a37791996-06-05 15:50:50 -0500101/* This function returns a pointer to the error_ptr associated with the user
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600102 functions. The application should free any memory associated with this
103 pointer before png_write_destroy and png_read_destroy are called. */
Guy Schalnat6d764711995-12-19 03:22:19 -0600104png_voidp
Guy Schalnate5a37791996-06-05 15:50:50 -0500105png_get_error_ptr(png_structp png_ptr)
Guy Schalnat6d764711995-12-19 03:22:19 -0600106{
Guy Schalnate5a37791996-06-05 15:50:50 -0500107 return png_ptr->error_ptr;
Guy Schalnat6d764711995-12-19 03:22:19 -0600108}
109
110
111