X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=dmenu.c;h=afb5303cf420fb01623b8ac3123e4b80584326b4;hb=65d655b371cbe2472ee0dd905b427b30311d9355;hp=2afcc4873aab202743b0694b691235d73ac72000;hpb=d2305e4b136b3bdfccf7de897a9f14583a1ca35a;p=dmenu.git diff --git a/dmenu.c b/dmenu.c index 2afcc48..afb5303 100644 --- a/dmenu.c +++ b/dmenu.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#define _BSD_SOURCE #include #include #include @@ -52,7 +53,6 @@ static char *cistrstr(const char *s, const char *sub); static void cleanup(void); static void drawmenu(void); static void drawtext(const char *text, ulong col[ColLast]); -static void *emalloc(uint size); static void eprint(const char *errstr, ...); static ulong getcolor(const char *colstr); static Bool grabkeyboard(void); @@ -252,15 +252,6 @@ drawtext(const char *text, ulong col[ColLast]) { XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); } -void * -emalloc(uint size) { - void *res = malloc(size); - - if(!res) - eprint("fatal: could not malloc() %u bytes\n", size); - return res; -} - void eprint(const char *errstr, ...) { va_list ap; @@ -477,11 +468,11 @@ kpress(XKeyEvent * e) { calcoffsets(); break; case XK_Return: - if((e->state & ShiftMask) && text) + if((e->state & ShiftMask) && *text) fprintf(stdout, "%s", text); else if(sel) fprintf(stdout, "%s", sel->text); - else if(text) + else if(*text) fprintf(stdout, "%s", text); fflush(stdout); running = False; @@ -563,7 +554,8 @@ readstdin(void) { maxname = p; max = len; } - new = emalloc(sizeof(Item)); + if((new = (Item *)malloc(sizeof(Item))) == NULL) + eprint("fatal: could not malloc() %u bytes\n", sizeof(Item)); new->next = new->left = new->right = NULL; new->text = p; if(!i) @@ -718,7 +710,8 @@ main(int argc, char *argv[]) { else eprint("usage: dmenu [-i] [-b] [-fn ] [-nb ] [-nf ]\n" " [-p ] [-sb ] [-sf ] [-v]\n"); - setlocale(LC_CTYPE, ""); + if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) + fprintf(stderr, "warning: no locale support\n"); if(!(dpy = XOpenDisplay(0))) eprint("dmenu: cannot open display\n"); screen = DefaultScreen(dpy);