tesseract  4.00.00dev
emalloc.h File Reference
#include "host.h"
#include "callcpp.h"

Go to the source code of this file.

Macros

#define NOTENOUGHMEMORY   2000
 
#define ILLEGALMALLOCREQUEST   2001
 

Functions

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

Macro Definition Documentation

◆ ILLEGALMALLOCREQUEST

#define ILLEGALMALLOCREQUEST   2001

Definition at line 28 of file emalloc.h.

◆ NOTENOUGHMEMORY

#define NOTENOUGHMEMORY   2000

Include Files and Type Defines

Definition at line 27 of file emalloc.h.

Function Documentation

◆ Efree()

void Efree ( void *  ptr)

Definition at line 79 of file emalloc.cpp.

79  {
80  if (ptr == NULL)
81  DoError (ILLEGALMALLOCREQUEST, "Attempted to free NULL ptr");
82 
83  free(ptr);
84 
85 } /* Efree */
#define ILLEGALMALLOCREQUEST
Definition: emalloc.h:28
void DoError(int Error, const char *Message)
Definition: danerror.cpp:42

◆ Emalloc()

void* Emalloc ( int  Size)

Public Function Prototypes

This routine attempts to allocate the specified number of bytes. If the memory can be allocated, a pointer to the memory is returned. If the memory cannot be allocated, or if the allocation request is negative or zero, an error is trapped.

Parameters
Sizenumber of bytes of memory to be allocated
Returns
Pointer to allocated memory.
Note
Exceptions:
History: 4/3/89, DSJ, Created.

Definition at line 47 of file emalloc.cpp.

47  {
48  void *Buffer;
49 
50  if (Size <= 0)
51  DoError (ILLEGALMALLOCREQUEST, "Illegal malloc request size");
52  Buffer = (void *) malloc (Size);
53  if (Buffer == NULL) {
54  DoError (NOTENOUGHMEMORY, "Not enough memory");
55  return (NULL);
56  }
57  else
58  return (Buffer);
59 
60 } /* Emalloc */
#define ILLEGALMALLOCREQUEST
Definition: emalloc.h:28
#define NOTENOUGHMEMORY
Definition: emalloc.h:27
void DoError(int Error, const char *Message)
Definition: danerror.cpp:42

◆ Erealloc()

void* Erealloc ( void *  ptr,
int  size 
)

Definition at line 64 of file emalloc.cpp.

64  {
65  void *Buffer;
66 
67  if (size < 0 || (size == 0 && ptr == NULL))
68  DoError (ILLEGALMALLOCREQUEST, "Illegal realloc request size");
69 
70  Buffer = (void *) realloc (ptr, size);
71  if (Buffer == NULL && size != 0)
72  DoError (NOTENOUGHMEMORY, "Not enough memory");
73  return (Buffer);
74 
75 } /* Erealloc */
#define ILLEGALMALLOCREQUEST
Definition: emalloc.h:28
voidpf void uLong size
Definition: ioapi.h:39
#define NOTENOUGHMEMORY
Definition: emalloc.h:27
void DoError(int Error, const char *Message)
Definition: danerror.cpp:42