tesseract 3.04.01

cutil/emalloc.cpp

Go to the documentation of this file.
00001 /**************************************************************************
00002  * Filename:
00003               emalloc.c
00004 **       Purpose:
00005               Routines for trapping memory allocation errors.
00006 **       Author:
00007               Dan Johnson
00008               HP-UX 6.2
00009               HP-UX 6.2
00010 **       History:
00011               4/3/89, DSJ, Created.
00012 **
00013 **      (c) Copyright Hewlett-Packard Company, 1988.
00014 ** Licensed under the Apache License, Version 2.0 (the "License");
00015 ** you may not use this file except in compliance with the License.
00016 ** You may obtain a copy of the License at
00017 ** http://www.apache.org/licenses/LICENSE-2.0
00018 ** Unless required by applicable law or agreed to in writing, software
00019 ** distributed under the License is distributed on an "AS IS" BASIS,
00020 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00021 ** See the License for the specific language governing permissions and
00022 ** limitations under the License.
00023 ******************************************************************************/
00024 /*----------------------------------------------------------------------------
00025           Include Files and Type Defines
00026 ----------------------------------------------------------------------------*/
00027 #include "emalloc.h"
00028 #include "danerror.h"
00029 #include <stdlib.h>
00030 
00031 /*----------------------------------------------------------------------------
00032               Public Code
00033 ----------------------------------------------------------------------------*/
00047 void *Emalloc(int Size) {
00048   void *Buffer;
00049 
00050   if (Size <= 0)
00051     DoError (ILLEGALMALLOCREQUEST, "Illegal malloc request size");
00052   Buffer = (void *) malloc (Size);
00053   if (Buffer == NULL) {
00054     DoError (NOTENOUGHMEMORY, "Not enough memory");
00055     return (NULL);
00056   }
00057   else
00058     return (Buffer);
00059 
00060 }                                /* Emalloc */
00061 
00062 
00063 /*---------------------------------------------------------------------------*/
00064 void *Erealloc(void *ptr, int size) {
00065   void *Buffer;
00066 
00067   if (size < 0 || (size == 0 && ptr == NULL))
00068     DoError (ILLEGALMALLOCREQUEST, "Illegal realloc request size");
00069 
00070   Buffer = (void *) realloc (ptr, size);
00071   if (Buffer == NULL && size != 0)
00072     DoError (NOTENOUGHMEMORY, "Not enough memory");
00073   return (Buffer);
00074 
00075 }                                /* Erealloc */
00076 
00077 
00078 /*---------------------------------------------------------------------------*/
00079 void Efree(void *ptr) { 
00080   if (ptr == NULL)
00081     DoError (ILLEGALMALLOCREQUEST, "Attempted to free NULL ptr");
00082 
00083   free(ptr); 
00084 
00085 }                                /* Efree */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines