From 740d2ea453d81cf720c459dfebd82e9a2d7bf970 Mon Sep 17 00:00:00 2001 From: "John Ankarstr\\xf6m" Date: Tue, 1 Jun 2021 01:09:26 +0200 Subject: Clean up code --- safetitle.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/safetitle.c b/safetitle.c index b1e49b4..03a1456 100644 --- a/safetitle.c +++ b/safetitle.c @@ -29,7 +29,6 @@ blacklisted(int fd) int i, r; struct timeval timeout; - /* setup */ if((buf = malloc(200*sizeof(char)))==NULL) err(1, "malloc"); @@ -47,12 +46,11 @@ blacklisted(int fd) buf[i] = '\0'; screen = strcmp(buf, SCREEN_DA)==0; + /* ignore strange trailing nul before reading response */ FD_ZERO(&fds); FD_SET(fd, &fds); timeout.tv_sec = 0; timeout.tv_usec = 0; - - /* ignore strange trailing nul */ while(select(fd+1, &fds, NULL, NULL, &timeout)>0) read(fd, &c, 1); @@ -82,14 +80,15 @@ check: FD_ZERO(&fds); FD_SET(fd, &fds); timeout.tv_sec = 0; - timeout.tv_usec = 1; + timeout.tv_usec = 1; /* it takes a millisecond sometimes */ if(screen && select(fd+1, &fds, NULL, NULL, &timeout)>0){ - i = 0; + /* ignore strange trailing nul before reading response */ if(read(fd, &c, 1)==-1){ warn("read"); return 1; } - if(c==0) goto check; /* ignore strange trailing nul */ + i = 0; + if(c==0) goto check; else goto loop; } -- cgit v1.2.3