replaced low-level stext reading with an fgets call b8985dc7
Anselm R. Garbe · 2007-11-02 16:57 1 file(s) · +5 −17
dwm.c +5 −17
1280 1280
1281 1281
void
1282 1282
run(void) {
1283 -
	char *p;
1284 -
	int r, xfd;
1285 1283
	fd_set rd;
1284 +
	int xfd;
1286 1285
	XEvent ev;
1287 1286
1288 1287
	/* main event loop, also reads status text from stdin */
1289 1288
	XSync(dpy, False);
1290 1289
	xfd = ConnectionNumber(dpy);
1291 1290
	readin = True;
1291 +
	stext[sizeof stext - 1] = '\0'; /* 0-terminator is never touched */
1292 1292
	while(running) {
1293 1293
		FD_ZERO(&rd);
1294 1294
		if(readin)
1300 1300
			eprint("select failed\n");
1301 1301
		}
1302 1302
		if(FD_ISSET(STDIN_FILENO, &rd)) {
1303 -
			switch(r = read(STDIN_FILENO, stext, sizeof stext - 1)) {
1304 -
			case -1:
1303 +
			if(stext == fgets(stext, sizeof stext - 1, stdin))
1304 +
				stext[strlen(stext) - 1] = '\0'; /* remove tailing '\n' */
1305 +
			else
1305 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 1307
			drawbar();
1320 1308
		}
1321 1309
		while(XPending(dpy)) {