File: malloc.c

package info (click to toggle)
gr-framework 0.73.14%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 11,600 kB
  • sloc: ansic: 87,413; cpp: 45,348; objc: 3,057; javascript: 2,647; makefile: 1,129; python: 1,000; sh: 991; yacc: 855; pascal: 554; fortran: 228
file content (43 lines) | stat: -rw-r--r-- 838 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* malloc.c -- safe versions of malloc and realloc */

/* Return a pointer to free()able block of memory large enough
   to hold BYTES number of bytes.  If the memory can't be allocated,
   print an error message and abort. */

#include <stdlib.h>

#include "gkscore.h"

char *gks_malloc(int size)
{
  char *temp;

  temp = (char *)calloc(1, size);
  if (temp == 0)
    {
      gks_fatal_error("can't allocate memory");
    }

  return (temp);
}

char *gks_realloc(void *ptr, int size)
{
  char *temp;

  temp = ptr ? (char *)realloc(ptr, size) : (char *)malloc(size);
  if (temp == 0)
    {
      gks_fatal_error("can't re-allocate memory");
    }

  return (temp);
}

/* Use this as the function to call when adding unwind protects so we
   don't need to know what free() returns. */

void gks_free(void *ptr)
{
  if (ptr) free(ptr);
}