- r = select(xfd + 1, &rd, NULL, NULL, NULL);
- if((r == -1) && (errno == EINTR))
- continue;
- if(r > 0) {
- if(readin && FD_ISSET(STDIN_FILENO, &rd)) {
- readin = NULL != fgets(stext, sizeof(stext), stdin);
- if(readin)
- stext[strlen(stext) - 1] = 0;
- else
- strcpy(stext, "broken pipe");
- drawstatus();
+ if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) {
+ if(errno == EINTR)
+ continue;
+ else
+ 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';
+ readin = False;
+ break;
+ case 0:
+ strncpy(stext, "EOF", sizeof(stext));
+ readin = False;
+ break;
+ default:
+ stext[r - (stext[r - 1] == '\n' ? 1 : 0)] = '\0';