{
Drw *drw;
- if (!(drw = calloc(1, sizeof(Drw))))
- return NULL;
+ drw = ecalloc(1, sizeof(Drw));
drw->dpy = dpy;
drw->screen = screen;
drw->root = root;
drw_clr_create(Drw *drw, const char *clrname)
{
Clr *clr;
- Colormap cmap;
- Visual *vis;
-
if (!drw)
return NULL;
- if (!(clr = calloc(1, sizeof(Clr))))
- return NULL;
- cmap = DefaultColormap(drw->dpy, drw->screen);
- vis = DefaultVisual(drw->dpy, drw->screen);
- if (!XftColorAllocName(drw->dpy, vis, cmap, clrname, &clr->rgb))
+
+ clr = ecalloc(1, sizeof(Clr));
+ if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
+ DefaultColormap(drw->dpy, drw->screen),
+ clrname, &clr->rgb))
die("error, cannot allocate color '%s'\n", clrname);
clr->pix = clr->rgb.pixel;
if (!drw)
return NULL;
- if (!(cur = calloc(1, sizeof(Cur))))
- return NULL;
+ cur = ecalloc(1, sizeof(Cur));
cur->cursor = XCreateFontCursor(drw->dpy, shape);
return cur;
#include "util.h"
+void *
+ecalloc(size_t nmemb, size_t size)
+{
+ void *p;
+
+ if (!(p = calloc(nmemb, size)))
+ perror(NULL);
+ return p;
+}
+
void
die(const char *fmt, ...) {
va_list ap;
#define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B))
void die(const char *errstr, ...);
+void *ecalloc(size_t, size_t);