blob: 858accb69ac352f609d0686e2c9004b72074d71b (
plain)
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
46
47
48
49
50
51
52
53
54
55
|
#include <stdlib.h>
#include "sc.h"
#include "xmalloc.h"
#include "macros.h"
#include "color.h"
#include "conf.h"
#define MAGIC ((double) 1234567890.12344)
extern void free();
extern int shall_quit;
char * scxmalloc(unsigned n) {
//register char *ptr;
//if ((ptr = malloc(n + sizeof(double))) == NULL) fatal("scxmalloc: no memory");
//*((double *) ptr) = MAGIC;
//return(ptr + sizeof(double));
register char *ptr;
ptr = (char *) malloc(n);
if (ptr == NULL) fatal("scxmalloc: no memory");
return (ptr);
}
/* we make sure realloc will do a malloc if needed */
char * scxrealloc(char *ptr, unsigned n) {
//if (ptr == NULL) return(scxmalloc(n));
//ptr -= sizeof(double);
//if (*((double *) ptr) != MAGIC) fatal("scxrealloc: storage not scxmalloc'ed");
//if ((ptr = realloc(ptr, n + sizeof(double))) == NULL) fatal("scxmalloc: no memory");
//*((double *) ptr) = MAGIC;
//return(ptr + sizeof(double));
if (ptr == NULL) return(scxmalloc(n));
ptr = (char *) realloc(ptr, n);
if (ptr == NULL) fatal("scxmalloc: no memory");
return(ptr);
}
void scxfree(char *p) {
//if (p == NULL) fatal("scxfree: NULL");
//p -= sizeof(double);
//if (*((double *) p) != MAGIC) fatal("scxfree: storage not malloc'ed");
//free(p);
if (p == NULL) fatal("scxfree: NULL");
free(p);
}
void fatal(char * str) {
//fprintf(stderr,"%s\n", str);
sc_error("%s", str);
shall_quit = 2;
}
|