aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drw.c19
-rw-r--r--util.c10
-rw-r--r--util.h1
3 files changed, 18 insertions, 12 deletions
diff --git a/drw.c b/drw.c
index 6aeb59d..a98083e 100644
--- a/drw.c
+++ b/drw.c
@@ -65,8 +65,7 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h
65{ 65{
66 Drw *drw; 66 Drw *drw;
67 67
68 if (!(drw = calloc(1, sizeof(Drw)))) 68 drw = ecalloc(1, sizeof(Drw));
69 return NULL;
70 drw->dpy = dpy; 69 drw->dpy = dpy;
71 drw->screen = screen; 70 drw->screen = screen;
72 drw->root = root; 71 drw->root = root;
@@ -189,16 +188,13 @@ Clr *
189drw_clr_create(Drw *drw, const char *clrname) 188drw_clr_create(Drw *drw, const char *clrname)
190{ 189{
191 Clr *clr; 190 Clr *clr;
192 Colormap cmap;
193 Visual *vis;
194
195 if (!drw) 191 if (!drw)
196 return NULL; 192 return NULL;
197 if (!(clr = calloc(1, sizeof(Clr)))) 193
198 return NULL; 194 clr = ecalloc(1, sizeof(Clr));
199 cmap = DefaultColormap(drw->dpy, drw->screen); 195 if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
200 vis = DefaultVisual(drw->dpy, drw->screen); 196 DefaultColormap(drw->dpy, drw->screen),
201 if (!XftColorAllocName(drw->dpy, vis, cmap, clrname, &clr->rgb)) 197 clrname, &clr->rgb))
202 die("error, cannot allocate color '%s'\n", clrname); 198 die("error, cannot allocate color '%s'\n", clrname);
203 clr->pix = clr->rgb.pixel; 199 clr->pix = clr->rgb.pixel;
204 200
@@ -409,8 +405,7 @@ drw_cur_create(Drw *drw, int shape)
409 405
410 if (!drw) 406 if (!drw)
411 return NULL; 407 return NULL;
412 if (!(cur = calloc(1, sizeof(Cur)))) 408 cur = ecalloc(1, sizeof(Cur));
413 return NULL;
414 cur->cursor = XCreateFontCursor(drw->dpy, shape); 409 cur->cursor = XCreateFontCursor(drw->dpy, shape);
415 410
416 return cur; 411 return cur;
diff --git a/util.c b/util.c
index 9b27512..6b703e9 100644
--- a/util.c
+++ b/util.c
@@ -6,6 +6,16 @@
6 6
7#include "util.h" 7#include "util.h"
8 8
9void *
10ecalloc(size_t nmemb, size_t size)
11{
12 void *p;
13
14 if (!(p = calloc(nmemb, size)))
15 perror(NULL);
16 return p;
17}
18
9void 19void
10die(const char *fmt, ...) { 20die(const char *fmt, ...) {
11 va_list ap; 21 va_list ap;
diff --git a/util.h b/util.h
index f7ce721..cded043 100644
--- a/util.h
+++ b/util.h
@@ -5,3 +5,4 @@
5#define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B)) 5#define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B))
6 6
7void die(const char *errstr, ...); 7void die(const char *errstr, ...);
8void *ecalloc(size_t, size_t);