tesseract  3.04.00
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
emalloc.cpp File Reference
#include "emalloc.h"
#include "danerror.h"
#include <stdlib.h>

Go to the source code of this file.

Functions

void * Emalloc (int Size)
 
void * Erealloc (void *ptr, int size)
 
void Efree (void *ptr)
 

Function Documentation

void Efree ( void *  ptr)

Definition at line 85 of file emalloc.cpp.

85  {
86  if (ptr == NULL)
87  DoError (ILLEGALMALLOCREQUEST, "Attempted to free NULL ptr");
88 
89  free(ptr);
90 
91 } /* Efree */
void DoError(int Error, const char *Message)
Definition: danerror.cpp:32
#define ILLEGALMALLOCREQUEST
Definition: emalloc.h:28
#define NULL
Definition: host.h:144
void* Emalloc ( int  Size)

Include Files and Type Defines

Public Code

Definition at line 35 of file emalloc.cpp.

35  {
36 /*
37  ** Parameters:
38  ** Size
39  number of bytes of memory to be allocated
40 ** Globals: none
41 ** Operation:
42 ** This routine attempts to allocate the specified number of
43 ** bytes. If the memory can be allocated, a pointer to the
44 ** memory is returned. If the memory cannot be allocated, or
45 ** if the allocation request is negative or zero,
46 ** an error is trapped.
47 ** Return: Pointer to allocated memory.
48 ** Exceptions: NOTENOUGHMEMORY
49  unable to allocate Size bytes
50 ** ILLEGALMALLOCREQUEST
51  negative or zero request size
52 ** History: 4/3/89, DSJ, Created.
53 */
54  void *Buffer;
55 
56  if (Size <= 0)
57  DoError (ILLEGALMALLOCREQUEST, "Illegal malloc request size");
58  Buffer = (void *) malloc (Size);
59  if (Buffer == NULL) {
60  DoError (NOTENOUGHMEMORY, "Not enough memory");
61  return (NULL);
62  }
63  else
64  return (Buffer);
65 
66 } /* Emalloc */
#define NOTENOUGHMEMORY
Definition: emalloc.h:27
void DoError(int Error, const char *Message)
Definition: danerror.cpp:32
#define ILLEGALMALLOCREQUEST
Definition: emalloc.h:28
#define NULL
Definition: host.h:144
void* Erealloc ( void *  ptr,
int  size 
)

Definition at line 70 of file emalloc.cpp.

70  {
71  void *Buffer;
72 
73  if (size < 0 || (size == 0 && ptr == NULL))
74  DoError (ILLEGALMALLOCREQUEST, "Illegal realloc request size");
75 
76  Buffer = (void *) realloc (ptr, size);
77  if (Buffer == NULL && size != 0)
78  DoError (NOTENOUGHMEMORY, "Not enough memory");
79  return (Buffer);
80 
81 } /* Erealloc */
#define NOTENOUGHMEMORY
Definition: emalloc.h:27
void DoError(int Error, const char *Message)
Definition: danerror.cpp:32
#define ILLEGALMALLOCREQUEST
Definition: emalloc.h:28
#define NULL
Definition: host.h:144