/* pngmem.c - stub functions for memory allocation
*
* libpng version 1.2.8 - December 3, 2004
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
* This file provides a location for all memory allocation. Users who
* need special memory handling are expected to supply replacement
* functions for png_malloc() and png_free(), and to use
* png_create_read_struct_2() and png_create_write_struct_2() to
* identify the replacement functions.
*/
#define PNG_INTERNAL
#include "png.h"
/* Borland DOS special memory handler */
/* if you change this, be sure to change the one in png.h also */
/* Allocate memory for a png_struct. The malloc and memset can be replaced
by a single call to calloc() if this is thought to improve performance. */
png_voidp /* PRIVATE */
{
#ifdef PNG_USER_MEM_SUPPORTED
}
/* Alternate version of png_create_struct, for use with user-defined malloc. */
png_voidp /* PRIVATE */
{
#endif /* PNG_USER_MEM_SUPPORTED */
if (type == PNG_STRUCT_INFO)
else if (type == PNG_STRUCT_PNG)
else
return (png_get_copyright(NULL));
#ifdef PNG_USER_MEM_SUPPORTED
{
}
else
#endif /* PNG_USER_MEM_SUPPORTED */
if (struct_ptr != NULL)
return (struct_ptr);
}
/* Free memory allocated by a png_create_struct() call */
void /* PRIVATE */
{
#ifdef PNG_USER_MEM_SUPPORTED
}
/* Free memory allocated by a png_create_struct() call */
void /* PRIVATE */
{
#endif
if (struct_ptr != NULL)
{
#ifdef PNG_USER_MEM_SUPPORTED
{
return;
}
#endif /* PNG_USER_MEM_SUPPORTED */
}
}
/* Allocate memory. For reasonable files, size should never exceed
* 64K. However, zlib may allocate more then 64K if you don't tell
* need to allocate exactly 64K, so whatever you call here must
* have the ability to do that.
*
* Borland seems to have a problem in DOS mode for exactly 64K.
* It gives you a segment with an offset of 8 (perhaps to store its
* memory stuff). zlib doesn't like this at all, so we have to
* detect and deal with it. This code should not be needed in
* Windows or OS/2 modes, and only in 16 bit mode. This code has
* been updated by Alexander Lehmann for version 0.89 to waste less
* memory.
*
* Note that we can't use png_size_t for the "size" declaration,
* since on some systems a png_size_t is a 16-bit quantity, and as a
* result, we would be truncating potentially larger memory requests
* (which should cause a fatal error) and introducing major problems.
*/
{
return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED
else
return (ret);
}
{
#endif /* PNG_USER_MEM_SUPPORTED */
#ifdef PNG_MAX_MALLOC_64K
{
}
else
#endif
{
{
/* try to see if we need to do any of this fancy stuff */
{
int num_blocks;
int i;
{
}
else
num_blocks = 1;
else
num_blocks++;
{
#ifndef PNG_USER_MEM_SUPPORTED
else
#endif
return (NULL);
}
{
#ifndef PNG_USER_MEM_SUPPORTED
"Farmalloc didn't return normalized pointer");
else
"Farmalloc didn't return normalized pointer");
#endif
return (NULL);
}
png_sizeof (png_bytep));
{
#ifndef PNG_USER_MEM_SUPPORTED
else
#endif
return (NULL);
}
{
}
for (i = 0; i < num_blocks; i++)
{
}
png_ptr->offset_table_count = 0;
}
}
{
#ifndef PNG_USER_MEM_SUPPORTED
else
#endif
return (NULL);
}
}
else
#ifndef PNG_USER_MEM_SUPPORTED
{
else
}
#endif
return (ret);
}
/* free a pointer allocated by png_malloc(). In the default
configuration, png_ptr is not used, but is passed in case it
is needed. If ptr is NULL, return without taking any action. */
void PNGAPI
{
return;
#ifdef PNG_USER_MEM_SUPPORTED
{
return;
}
}
void PNGAPI
{
#endif /* PNG_USER_MEM_SUPPORTED */
{
int i;
for (i = 0; i < png_ptr->offset_table_count; i++)
{
{
break;
}
}
{
}
}
{
}
}
#else /* Not the Borland DOS special memory handler */
/* Allocate memory for a png_struct or a png_info. The malloc and
memset can be replaced by a single call to calloc() if this is thought
to improve performance noticably. */
png_voidp /* PRIVATE */
{
#ifdef PNG_USER_MEM_SUPPORTED
}
/* Allocate memory for a png_struct or a png_info. The malloc and
memset can be replaced by a single call to calloc() if this is thought
to improve performance noticably. */
png_voidp /* PRIVATE */
{
#endif /* PNG_USER_MEM_SUPPORTED */
if (type == PNG_STRUCT_INFO)
else if (type == PNG_STRUCT_PNG)
else
return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED
{
if (struct_ptr != NULL)
return (struct_ptr);
}
#endif /* PNG_USER_MEM_SUPPORTED */
#if defined(__TURBOC__) && !defined(__FLAT__)
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
# else
# endif
#endif
if (struct_ptr != NULL)
return (struct_ptr);
}
/* Free memory allocated by a png_create_struct() call */
void /* PRIVATE */
{
#ifdef PNG_USER_MEM_SUPPORTED
}
/* Free memory allocated by a png_create_struct() call */
void /* PRIVATE */
{
#endif /* PNG_USER_MEM_SUPPORTED */
if (struct_ptr != NULL)
{
#ifdef PNG_USER_MEM_SUPPORTED
{
return;
}
#endif /* PNG_USER_MEM_SUPPORTED */
#if defined(__TURBOC__) && !defined(__FLAT__)
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
# else
# endif
#endif
}
}
/* Allocate memory. For reasonable files, size should never exceed
64K. However, zlib may allocate more then 64K if you don't tell
need to allocate exactly 64K, so whatever you call here must
have the ability to do that. */
{
#ifdef PNG_USER_MEM_SUPPORTED
return (NULL);
else
return (ret);
}
{
#endif /* PNG_USER_MEM_SUPPORTED */
return (NULL);
#ifdef PNG_MAX_MALLOC_64K
{
#ifndef PNG_USER_MEM_SUPPORTED
else
#endif
return NULL;
}
#endif
/* Check for overflow */
#if defined(__TURBOC__) && !defined(__FLAT__)
else
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
else
# else
else
# endif
#endif
#ifndef PNG_USER_MEM_SUPPORTED
#endif
return (ret);
}
/* Free a pointer allocated by png_malloc(). If ptr is NULL, return
without taking any action. */
void PNGAPI
{
return;
#ifdef PNG_USER_MEM_SUPPORTED
{
return;
}
}
void PNGAPI
{
return;
#endif /* PNG_USER_MEM_SUPPORTED */
#if defined(__TURBOC__) && !defined(__FLAT__)
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
# else
# endif
#endif
}
#endif /* Not Borland DOS special memory handler */
#if defined(PNG_1_0_X)
#else
/* This function was added at libpng version 1.2.3. The png_malloc_warn()
* function will set up png_malloc() to issue a png_warning and return NULL
* instead of issuing a png_error, if it fails to allocate the requested
* memory.
*/
{
return(ptr);
}
#endif
{
}
{
}
#ifdef PNG_USER_MEM_SUPPORTED
/* This function is called when the application wants to use another method
* of allocating and freeing memory.
*/
void PNGAPI
{
}
/* This function returns a pointer to the mem_ptr associated with the user
* functions. The application should free any memory associated with this
* pointer before png_write_destroy and png_read_destroy are called.
*/
{
}
#endif /* PNG_USER_MEM_SUPPORTED */