summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@gmail.com>2007-11-02 16:57:52 +0100
committerAnselm R. Garbe <garbeam@gmail.com>2007-11-02 16:57:52 +0100
commitb8985dc7bb8ef309a66edea541f8e4b8bc5d6381 (patch)
tree9715d3049f0bed9d3992771da71cbee0e76fe916
parentrevival of RESIZEHINTS (diff)
downloaddwm-b8985dc7bb8ef309a66edea541f8e4b8bc5d6381.tar.gz
dwm-b8985dc7bb8ef309a66edea541f8e4b8bc5d6381.zip
replaced low-level stext reading with an fgets call
-rw-r--r--dwm.c22
1 files changed, 5 insertions, 17 deletions
diff --git a/dwm.c b/dwm.c
index 257edcc..77727a8 100644
--- a/dwm.c
+++ b/dwm.c
@@ -1280,15 +1280,15 @@ restack(void) {
1280 1280
1281void 1281void
1282run(void) { 1282run(void) {
1283 char *p;
1284 int r, xfd;
1285 fd_set rd; 1283 fd_set rd;
1284 int xfd;
1286 XEvent ev; 1285 XEvent ev;
1287 1286
1288 /* main event loop, also reads status text from stdin */ 1287 /* main event loop, also reads status text from stdin */
1289 XSync(dpy, False); 1288 XSync(dpy, False);
1290 xfd = ConnectionNumber(dpy); 1289 xfd = ConnectionNumber(dpy);
1291 readin = True; 1290 readin = True;
1291 stext[sizeof stext - 1] = '\0'; /* 0-terminator is never touched */
1292 while(running) { 1292 while(running) {
1293 FD_ZERO(&rd); 1293 FD_ZERO(&rd);
1294 if(readin) 1294 if(readin)
@@ -1300,22 +1300,10 @@ run(void) {
1300 eprint("select failed\n"); 1300 eprint("select failed\n");
1301 } 1301 }
1302 if(FD_ISSET(STDIN_FILENO, &rd)) { 1302 if(FD_ISSET(STDIN_FILENO, &rd)) {
1303 switch(r = read(STDIN_FILENO, stext, sizeof stext - 1)) { 1303 if(stext == fgets(stext, sizeof stext - 1, stdin))
1304 case -1: 1304 stext[strlen(stext) - 1] = '\0'; /* remove tailing '\n' */
1305 else
1305 strncpy(stext, strerror(errno), sizeof stext - 1); 1306 strncpy(stext, strerror(errno), sizeof stext - 1);
1306 stext[sizeof stext - 1] = '\0';
1307 readin = False;
1308 break;
1309 case 0:
1310 strncpy(stext, "EOF", 4);
1311 readin = False;
1312 break;
1313 default:
1314 for(stext[r] = '\0', p = stext + strlen(stext) - 1; p >= stext && *p == '\n'; *p-- = '\0');
1315 for(; p >= stext && *p != '\n'; --p);
1316 if(p > stext)
1317 strncpy(stext, p + 1, sizeof stext);
1318 }
1319 drawbar(); 1307 drawbar();
1320 } 1308 }
1321 while(XPending(dpy)) { 1309 while(XPending(dpy)) {