]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - contrib/cygtermd/malloc.c
Make kh2reg.py compatible with modern Python.
[PuTTY.git] / contrib / cygtermd / malloc.c
1 /*
2  * malloc.c: implementation of malloc.h
3  */
4
5 #include <stdlib.h>
6 #include <string.h>
7
8 #include "malloc.h"
9
10 extern void fatal(const char *, ...);
11
12 void *smalloc(size_t size) {
13     void *p;
14     p = malloc(size);
15     if (!p) {
16         fatal("out of memory");
17     }
18     return p;
19 }
20
21 void sfree(void *p) {
22     if (p) {
23         free(p);
24     }
25 }
26
27 void *srealloc(void *p, size_t size) {
28     void *q;
29     if (p) {
30         q = realloc(p, size);
31     } else {
32         q = malloc(size);
33     }
34     if (!q)
35         fatal("out of memory");
36     return q;
37 }
38
39 char *dupstr(const char *s) {
40     char *r = smalloc(1+strlen(s));
41     strcpy(r,s);
42     return r;
43 }