Ciao Jukka
Jukka Salmi wrote:
aka `dwm <>dwm_pipe', BTW...
This definitely looks better and doesn't block on open. Though AFAIK
POSIX doesn't specify the behavior of a FIFO opened O_RDWR and may
result differently across operating systems. Anyway this works fine.
Thanks for the cleanup. But now that dwm's reading from stdin isn't
line buffered anymore the read string shouldn't be required to have a
trailing newline. See attached patch.
Must have been blind. Because \n looks really bad, I propose the
following patch (also removes 2 useless lines).
Regards, Manuel
--- jukka/main.c 2006-11-26 14:06:32.000000000 +0100
+++ my_dwm-2.3/main.c 2006-11-26 14:04:30.000000000 +0100
@@ -228,6 +228,7 @@
int
main(int argc, char *argv[]) {
int r, xfd;
+ char *p;
fd_set rd;
if(argc == 2 && !strncmp("-v", argv[1], 3)) {
@@ -270,14 +271,12 @@
if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) {
if(errno == EINTR)
continue;
- else
- eprint("select failed\n");
+ eprint("select failed\n");
}
if(FD_ISSET(STDIN_FILENO, &rd)) {
switch(r = read(STDIN_FILENO, stext, sizeof(stext)-1)) {
case -1:
- strncpy(stext, strerror(errno),
sizeof(stext));
- stext[sizeof(stext)-1] = '\0';
+ strncpy(stext, strerror(errno),
sizeof(stext)-1);
readin = False;
break;
case 0:
@@ -286,6 +285,9 @@
break;
default:
stext[r-(stext[r-1]=='\n'?1:0)] = '\0';
+ for(p=stext+strlen(stext)-1;p>stext &&
*p!='\n';--p);
+ if(p>stext)
+ strncpy(stext, p+1,
sizeof(stext));
}
drawstatus();
}