summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/src/malloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/puzzles/src/malloc.c')
-rw-r--r--apps/plugins/puzzles/src/malloc.c64
1 files changed, 0 insertions, 64 deletions
diff --git a/apps/plugins/puzzles/src/malloc.c b/apps/plugins/puzzles/src/malloc.c
deleted file mode 100644
index 39bcfac25b..0000000000
--- a/apps/plugins/puzzles/src/malloc.c
+++ /dev/null
@@ -1,64 +0,0 @@
1/*
2 * malloc.c: safe wrappers around malloc, realloc, free, strdup
3 */
4
5#ifndef NO_STDINT_H
6#include <stdint.h>
7#endif
8#include <stdlib.h>
9#include <string.h>
10#include "puzzles.h"
11
12/*
13 * smalloc should guarantee to return a useful pointer - we
14 * can do nothing except die when it's out of memory anyway.
15 */
16void *smalloc(size_t size) {
17 void *p;
18#ifdef PTRDIFF_MAX
19 if (size > PTRDIFF_MAX)
20 fatal("allocation too large");
21#endif
22 p = malloc(size);
23 if (!p)
24 fatal("out of memory");
25 return p;
26}
27
28/*
29 * sfree should guaranteeably deal gracefully with freeing NULL
30 */
31void sfree(void *p) {
32 if (p) {
33 free(p);
34 }
35}
36
37/*
38 * srealloc should guaranteeably be able to realloc NULL
39 */
40void *srealloc(void *p, size_t size) {
41 void *q;
42#ifdef PTRDIFF_MAX
43 if (size > PTRDIFF_MAX)
44 fatal("allocation too large");
45#endif
46 if (p) {
47 q = realloc(p, size);
48 } else {
49 q = malloc(size);
50 }
51 if (!q)
52 fatal("out of memory");
53 return q;
54}
55
56/*
57 * dupstr is like strdup, but with the never-return-NULL property
58 * of smalloc (and also reliably defined in all environments :-)
59 */
60char *dupstr(const char *s) {
61 char *r = smalloc(1+strlen(s));
62 strcpy(r,s);
63 return r;
64}