File: safemalloc.h

package info (click to toggle)
afterstep 2.2.12-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 33,168 kB
  • sloc: ansic: 201,695; sh: 5,894; xml: 3,721; makefile: 2,095; perl: 1,558; cpp: 811
file content (45 lines) | stat: -rw-r--r-- 946 bytes parent folder | download | duplicates (8)
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
44
45
#ifndef SAFEMALLOC_H_HEADER_INCLUDED
#define SAFEMALLOC_H_HEADER_INCLUDED

#ifdef HAVE_MALLOC_H
#include <malloc.h>
#else
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#endif

#ifdef __cplusplus
extern "C" {
#endif

#ifndef safemalloc
void         *safemalloc (size_t length);
#endif
#ifndef safecalloc
void         *safecalloc (size_t num, size_t blength);
#endif
#ifndef safefree
void		  safefree (void *ptr);
#endif
#ifndef saferealloc
void         *saferealloc (void *orig_ptr, size_t length);
#endif

void        *guarded_malloc (size_t length);
void        *guarded_realloc (void *orig_ptr, size_t length);
void        *guarded_calloc (size_t num, size_t blength);
void		guarded_free (void *ptr);

void		  dump_memory();

#define	NEW(a)              	((a *)malloc(sizeof(a)))
#define	NEW_ARRAY_ZEROED(a, b)  ((a *)safecalloc(b, sizeof(a)))
#define	NEW_ARRAY(a, b)     	((a *)safemalloc(b*sizeof(a)))

#ifdef __cplusplus
}
#endif


#endif