pngerror.c revision 0
0N/A/*
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation. Sun designates this
0N/A * particular file as subject to the "Classpath" exception as provided
0N/A * by Sun in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A *
0N/A * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
0N/A */
0N/A
0N/A/* pngerror.c - stub functions for i/o and memory allocation
0N/A *
0N/A * This file is available under and governed by the GNU General Public
0N/A * License version 2 only, as published by the Free Software Foundation.
0N/A * However, the following notice accompanied the original version of this
0N/A * file and, per its terms, should not be removed:
0N/A *
0N/A * Last changed in libpng 1.2.13 November 13, 2006
0N/A * For conditions of distribution and use, see copyright notice in png.h
0N/A * Copyright (c) 1998-2006 Glenn Randers-Pehrson
0N/A * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
0N/A * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
0N/A *
0N/A * This file provides a location for all error handling. Users who
0N/A * need special error handling are expected to write replacement functions
0N/A * and use png_set_error_fn() to use those functions. See the instructions
0N/A * at each function.
0N/A */
0N/A
0N/A#define PNG_INTERNAL
0N/A#include "png.h"
0N/A
0N/A#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
0N/Astatic void /* PRIVATE */
0N/Apng_default_error PNGARG((png_structp png_ptr,
0N/A png_const_charp error_message));
0N/Astatic void /* PRIVATE */
0N/Apng_default_warning PNGARG((png_structp png_ptr,
0N/A png_const_charp warning_message));
0N/A
0N/A/* This function is called whenever there is a fatal error. This function
0N/A * should not be changed. If there is a need to handle errors differently,
0N/A * you should supply a replacement error function and use png_set_error_fn()
0N/A * to replace the error function at run-time.
0N/A */
0N/Avoid PNGAPI
0N/Apng_error(png_structp png_ptr, png_const_charp error_message)
0N/A{
0N/A#ifdef PNG_ERROR_NUMBERS_SUPPORTED
0N/A char msg[16];
0N/A if (png_ptr != NULL)
0N/A {
0N/A if (png_ptr->flags&
0N/A (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
0N/A {
0N/A if (*error_message == '#')
0N/A {
0N/A int offset;
0N/A for (offset=1; offset<15; offset++)
0N/A if (*(error_message+offset) == ' ')
0N/A break;
0N/A if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
0N/A {
0N/A int i;
0N/A for (i=0; i<offset-1; i++)
0N/A msg[i]=error_message[i+1];
0N/A msg[i]='\0';
0N/A error_message=msg;
0N/A }
0N/A else
0N/A error_message+=offset;
0N/A }
0N/A else
0N/A {
0N/A if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
0N/A {
0N/A msg[0]='0';
0N/A msg[1]='\0';
0N/A error_message=msg;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A#endif
0N/A if (png_ptr != NULL && png_ptr->error_fn != NULL)
0N/A (*(png_ptr->error_fn))(png_ptr, error_message);
0N/A
0N/A /* If the custom handler doesn't exist, or if it returns,
0N/A use the default handler, which will not return. */
0N/A png_default_error(png_ptr, error_message);
0N/A}
0N/A
0N/A/* This function is called whenever there is a non-fatal error. This function
0N/A * should not be changed. If there is a need to handle warnings differently,
0N/A * you should supply a replacement warning function and use
0N/A * png_set_error_fn() to replace the warning function at run-time.
0N/A */
0N/Avoid PNGAPI
0N/Apng_warning(png_structp png_ptr, png_const_charp warning_message)
0N/A{
0N/A int offset = 0;
0N/A if (png_ptr != NULL)
0N/A {
0N/A#ifdef PNG_ERROR_NUMBERS_SUPPORTED
0N/A if (png_ptr->flags&
0N/A (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
0N/A#endif
0N/A {
0N/A if (*warning_message == '#')
0N/A {
0N/A for (offset=1; offset<15; offset++)
0N/A if (*(warning_message+offset) == ' ')
0N/A break;
0N/A }
0N/A }
0N/A if (png_ptr != NULL && png_ptr->warning_fn != NULL)
0N/A (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
0N/A }
0N/A else
0N/A png_default_warning(png_ptr, warning_message+offset);
0N/A}
0N/A
0N/A/* These utilities are used internally to build an error message that relates
0N/A * to the current chunk. The chunk name comes from png_ptr->chunk_name,
0N/A * this is used to prefix the message. The message is limited in length
0N/A * to 63 bytes, the name characters are output as hex digits wrapped in []
0N/A * if the character is invalid.
0N/A */
0N/A#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
0N/Astatic PNG_CONST char png_digit[16] = {
0N/A '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
0N/A 'A', 'B', 'C', 'D', 'E', 'F'
0N/A};
0N/A
0N/Astatic void /* PRIVATE */
0N/Apng_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
0N/A error_message)
0N/A{
0N/A int iout = 0, iin = 0;
0N/A
0N/A while (iin < 4)
0N/A {
0N/A int c = png_ptr->chunk_name[iin++];
0N/A if (isnonalpha(c))
0N/A {
0N/A buffer[iout++] = '[';
0N/A buffer[iout++] = png_digit[(c & 0xf0) >> 4];
0N/A buffer[iout++] = png_digit[c & 0x0f];
0N/A buffer[iout++] = ']';
0N/A }
0N/A else
0N/A {
0N/A buffer[iout++] = (png_byte)c;
0N/A }
0N/A }
0N/A
0N/A if (error_message == NULL)
0N/A buffer[iout] = 0;
0N/A else
0N/A {
0N/A buffer[iout++] = ':';
0N/A buffer[iout++] = ' ';
0N/A png_strncpy(buffer+iout, error_message, 63);
0N/A buffer[iout+63] = 0;
0N/A }
0N/A}
0N/A
0N/Avoid PNGAPI
0N/Apng_chunk_error(png_structp png_ptr, png_const_charp error_message)
0N/A{
0N/A char msg[18+64];
0N/A if (png_ptr == NULL)
0N/A png_error(png_ptr, error_message);
0N/A else
0N/A {
0N/A png_format_buffer(png_ptr, msg, error_message);
0N/A png_error(png_ptr, msg);
0N/A }
0N/A}
0N/A
0N/Avoid PNGAPI
0N/Apng_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
0N/A{
0N/A char msg[18+64];
0N/A if (png_ptr == NULL)
0N/A png_warning(png_ptr, warning_message);
0N/A else
0N/A {
0N/A png_format_buffer(png_ptr, msg, warning_message);
0N/A png_warning(png_ptr, msg);
0N/A }
0N/A}
0N/A
0N/A/* This is the default error handling function. Note that replacements for
0N/A * this function MUST NOT RETURN, or the program will likely crash. This
0N/A * function is used by default, or if the program supplies NULL for the
0N/A * error function pointer in png_set_error_fn().
0N/A */
0N/Astatic void /* PRIVATE */
0N/Apng_default_error(png_structp png_ptr, png_const_charp error_message)
0N/A{
0N/A#ifndef PNG_NO_CONSOLE_IO
0N/A#ifdef PNG_ERROR_NUMBERS_SUPPORTED
0N/A if (*error_message == '#')
0N/A {
0N/A int offset;
0N/A char error_number[16];
0N/A for (offset=0; offset<15; offset++)
0N/A {
0N/A error_number[offset] = *(error_message+offset+1);
0N/A if (*(error_message+offset) == ' ')
0N/A break;
0N/A }
0N/A if((offset > 1) && (offset < 15))
0N/A {
0N/A error_number[offset-1]='\0';
0N/A fprintf(stderr, "libpng error no. %s: %s\n", error_number,
0N/A error_message+offset);
0N/A }
0N/A else
0N/A fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
0N/A }
0N/A else
0N/A#endif
0N/A fprintf(stderr, "libpng error: %s\n", error_message);
0N/A#endif
0N/A
0N/A#ifdef PNG_SETJMP_SUPPORTED
0N/A if (png_ptr)
0N/A {
0N/A# ifdef USE_FAR_KEYWORD
0N/A {
0N/A jmp_buf jmpbuf;
0N/A png_memcpy(jmpbuf,png_ptr->jmpbuf,png_sizeof(jmp_buf));
0N/A longjmp(jmpbuf, 1);
0N/A }
0N/A# else
0N/A longjmp(png_ptr->jmpbuf, 1);
0N/A# endif
0N/A }
0N/A#else
0N/A PNG_ABORT();
0N/A#endif
0N/A#ifdef PNG_NO_CONSOLE_IO
0N/A /* make compiler happy */ ;
0N/A if (&error_message != NULL)
0N/A return;
0N/A#endif
0N/A}
0N/A
0N/A/* This function is called when there is a warning, but the library thinks
0N/A * it can continue anyway. Replacement functions don't have to do anything
0N/A * here if you don't want them to. In the default configuration, png_ptr is
0N/A * not used, but it is passed in case it may be useful.
0N/A */
0N/Astatic void /* PRIVATE */
0N/Apng_default_warning(png_structp png_ptr, png_const_charp warning_message)
0N/A{
0N/A#ifndef PNG_NO_CONSOLE_IO
0N/A# ifdef PNG_ERROR_NUMBERS_SUPPORTED
0N/A if (*warning_message == '#')
0N/A {
0N/A int offset;
0N/A char warning_number[16];
0N/A for (offset=0; offset<15; offset++)
0N/A {
0N/A warning_number[offset]=*(warning_message+offset+1);
0N/A if (*(warning_message+offset) == ' ')
0N/A break;
0N/A }
0N/A if((offset > 1) && (offset < 15))
0N/A {
0N/A warning_number[offset-1]='\0';
0N/A fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
0N/A warning_message+offset);
0N/A }
0N/A else
0N/A fprintf(stderr, "libpng warning: %s\n", warning_message);
0N/A }
0N/A else
0N/A# endif
0N/A fprintf(stderr, "libpng warning: %s\n", warning_message);
0N/A#else
0N/A /* make compiler happy */ ;
0N/A if (warning_message)
0N/A return;
0N/A#endif
0N/A /* make compiler happy */ ;
0N/A if (png_ptr)
0N/A return;
0N/A}
0N/A
0N/A/* This function is called when the application wants to use another method
0N/A * of handling errors and warnings. Note that the error function MUST NOT
0N/A * return to the calling routine or serious problems will occur. The return
0N/A * method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)
0N/A */
0N/Avoid PNGAPI
0N/Apng_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
0N/A png_error_ptr error_fn, png_error_ptr warning_fn)
0N/A{
0N/A if (png_ptr == NULL)
0N/A return;
0N/A png_ptr->error_ptr = error_ptr;
0N/A png_ptr->error_fn = error_fn;
0N/A png_ptr->warning_fn = warning_fn;
0N/A}
0N/A
0N/A
0N/A/* This function returns a pointer to the error_ptr associated with the user
0N/A * functions. The application should free any memory associated with this
0N/A * pointer before png_write_destroy and png_read_destroy are called.
0N/A */
0N/Apng_voidp PNGAPI
0N/Apng_get_error_ptr(png_structp png_ptr)
0N/A{
0N/A if (png_ptr == NULL)
0N/A return NULL;
0N/A return ((png_voidp)png_ptr->error_ptr);
0N/A}
0N/A
0N/A
0N/A#ifdef PNG_ERROR_NUMBERS_SUPPORTED
0N/Avoid PNGAPI
0N/Apng_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
0N/A{
0N/A if(png_ptr != NULL)
0N/A {
0N/A png_ptr->flags &=
0N/A ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
0N/A }
0N/A}
0N/A#endif
0N/A#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */