summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@wmii.de>2006-07-10 19:46:24 +0200
committerAnselm R. Garbe <garbeam@wmii.de>2006-07-10 19:46:24 +0200
commit39677ec76616fe4165ef92afb14db2bef2488e30 (patch)
tree7ea1c021042b7d7da53660aa127af37847273a91 /util.c
parentadded new stuff (diff)
downloaddwm-39677ec76616fe4165ef92afb14db2bef2488e30.tar.gz
dwm-39677ec76616fe4165ef92afb14db2bef2488e30.zip
several new changes, made gridmenu working
Diffstat (limited to '')
-rw-r--r--util.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/util.c b/util.c
index 3553f5d..99842e9 100644
--- a/util.c
+++ b/util.c
@@ -6,6 +6,7 @@
6#include <stdarg.h> 6#include <stdarg.h>
7#include <stdio.h> 7#include <stdio.h>
8#include <stdlib.h> 8#include <stdlib.h>
9#include <string.h>
9 10
10void 11void
11error(char *errstr, ...) { 12error(char *errstr, ...) {
@@ -16,3 +17,61 @@ error(char *errstr, ...) {
16 exit(1); 17 exit(1);
17} 18}
18 19
20static void
21bad_malloc(unsigned int size)
22{
23 fprintf(stderr, "fatal: could not malloc() %d bytes\n",
24 (int) size);
25 exit(1);
26}
27
28void *
29emallocz(unsigned int size)
30{
31 void *res = calloc(1, size);
32 if(!res)
33 bad_malloc(size);
34 return res;
35}
36
37void *
38emalloc(unsigned int size)
39{
40 void *res = malloc(size);
41 if(!res)
42 bad_malloc(size);
43 return res;
44}
45
46void *
47erealloc(void *ptr, unsigned int size)
48{
49 void *res = realloc(ptr, size);
50 if(!res)
51 bad_malloc(size);
52 return res;
53}
54
55char *
56estrdup(const char *str)
57{
58 void *res = strdup(str);
59 if(!res)
60 bad_malloc(strlen(str));
61 return res;
62}
63
64void
65failed_assert(char *a, char *file, int line)
66{
67 fprintf(stderr, "Assertion \"%s\" failed at %s:%d\n", a, file, line);
68 abort();
69}
70
71void
72swap(void **p1, void **p2)
73{
74 void *tmp = *p1;
75 *p1 = *p2;
76 *p2 = tmp;
77}