Jspice3
alloc.c File Reference
#include "spice.h"
#include "misc.h"
Include dependency graph for alloc.c:

Go to the source code of this file.

Functions

char * tmalloc (int num)
 
char * trealloc (char *str, int num)
 
void txfree (char *ptr)
 

Function Documentation

char* tmalloc ( int  num)

Definition at line 17 of file alloc.c.

23 {
24  char *s;
25 #ifdef MALLOCTRACE
26  int i;
27  static char *mem_alloc();
28 #endif
29 
30  if (!num)
31  return NULL;
32 
33 #ifdef MALLOCTRACE
34  s = mem_alloc((unsigned) num, 1, &i);
35 #else
36  s = malloc((unsigned) num);
37 #endif
38  if (!s) {
39  fprintf(stderr,
40  "malloc: Internal Error: can't allocate %d bytes.\n", num);
41  exit(EXIT_BAD);
42  }
43  bzero(s, num);
44  return (s);
45 }
Definition: cddefs.h:119
char * malloc()
int bzero(char *ptr, int num)
Definition: string.c:357
#define NULL
Definition: spdefs.h:121
#define EXIT_BAD
Definition: misc.h:26
char* trealloc ( char *  str,
int  num 
)

Definition at line 49 of file alloc.c.

53 {
54  char *s;
55 #ifdef MALLOCTRACE
56  int i;
57  static char *mem_alloc();
58 #endif
59 
60  if (!num) {
61  if (str)
62  free(str);
63  return (NULL);
64  }
65 
66 #ifdef MALLOCTRACE
67  s = mem_alloc((unsigned) num, 1, &i);
68  if (s) {
69  bcopy(str, s, num); /* Hope this won't cause a mem fault. */
70  free(str);
71  }
72 #else
73  if (!str)
74  s = tmalloc(num);
75  else
76  s = realloc(str, (unsigned) num);
77 #endif
78 
79  if (!s) {
80  fprintf(stderr,
81  "realloc: Internal Error: can't allocate %d bytes.\n", num);
82  exit(EXIT_BAD);
83  }
84  return (s);
85 }
Definition: cddefs.h:119
#define NULL
Definition: spdefs.h:121
char * realloc()
void bcopy(char *from, char *to, int num)
Definition: string.c:339
#define EXIT_BAD
Definition: misc.h:26
char * tmalloc(int num)
Definition: alloc.c:17
void free()
void txfree ( char *  ptr)

Definition at line 89 of file alloc.c.

92 {
93  if (ptr)
94  free(ptr);
95 }
char * ptr
Definition: output.c:153
void free()