aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarstr\xf6m <john@ankarstrom.se>2021-05-31 19:30:21 +0200
committerJohn Ankarstr\xf6m <john@ankarstrom.se>2021-05-31 19:30:21 +0200
commitf0ad01ff4526cb43bf701cb1cbe3bdc5291b23a3 (patch)
tree1825c0d435cc201626ac87a4fac7aab2fa1203b4
parente7dc31fe7b83abe5f4253ab0d6ca4edfb92b4b72 (diff)
downloadsafetitle-f0ad01ff4526cb43bf701cb1cbe3bdc5291b23a3.tar.gz
Now it works
-rw-r--r--termsettitle.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/termsettitle.c b/termsettitle.c
index 8ed1b9f..2ff9883 100644
--- a/termsettitle.c
+++ b/termsettitle.c
@@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/select.h>
#include <termios.h>
#include <unistd.h>
@@ -27,22 +28,38 @@ int
da(int fd, char *buf, int real)
{
char c;
- int i, r;
+ fd_set fds;
+ int i, r, responses;
+ struct timeval timeout;
+
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 0;
+ responses = 0;
+
i = 0;
if(real) write(fd, "\033P\033[>c\033\\", 8);
else write(fd, "\033[>c", 4);
+
+read:
while(r = read(fd, &c, 1)){
if(!r){
fprintf(stderr, "bad terminal\n");
return -1;
}
- buf[i] = c;
- if(c==99){
- buf[++i] = '\0';
- return i;
- }
- i++;
+ buf[i++] = c;
+ if(c==99) break;
}
+ buf[i] = '\0';
+ responses++;
+
+ /* ensure there is only one real terminal */
+ if(real && select(fd+1, &fds, NULL, NULL, &timeout)>0)
+ goto read;
+ if(responses>1)
+ buf[0] = '\0';
+
return i;
}