aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarstr\xf6m <john@ankarstrom.se>2021-06-01 01:09:26 +0200
committerJohn Ankarstr\xf6m <john@ankarstrom.se>2021-06-01 01:09:26 +0200
commit740d2ea453d81cf720c459dfebd82e9a2d7bf970 (patch)
treea770d8648c395211d65ef357c208311a1b6aff0b
parent40abe9c9371c94d599a087802410de7c0a0c0ca3 (diff)
downloadsafetitle-740d2ea453d81cf720c459dfebd82e9a2d7bf970.tar.gz
Clean up code
-rw-r--r--safetitle.c11
1 files 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;
}