Browse Source

Fix problem with copy/paste

git-svn-id: https://klish.googlecode.com/svn/trunk@495 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
73d05695c6
1 changed files with 18 additions and 9 deletions
  1. 18 9
      tinyrl/vt100/vt100.c

+ 18 - 9
tinyrl/vt100/vt100.c

@@ -126,31 +126,40 @@ tinyrl_vt100_vprintf(const tinyrl_vt100_t * this, const char *fmt, va_list args)
 /*-------------------------------------------------------- */
 int tinyrl_vt100_getchar(const tinyrl_vt100_t *this)
 {
-	int result = EOF;
+	unsigned char c;
 	int istream_fd;
 	fd_set rfds;
 	struct timeval tv;
 	int retval;
+	ssize_t res;
+
+	istream_fd = fileno(this->istream);
 
 	/* Just wait for the input if no timeout */
-	if (this->timeout <= 0)
-		return getc(this->istream);
+	if (this->timeout <= 0) {
+		res = read(istream_fd, &c, 1);
+		/* End of file */
+		if (!res)
+			return EOF;
+		return c;
+	}
 
 	/* Set timeout for the select() */
-	istream_fd = fileno(this->istream);
 	FD_ZERO(&rfds);
 	FD_SET(istream_fd, &rfds);
 	tv.tv_sec = this->timeout;
 	tv.tv_usec = 0;
-
 	retval = select(istream_fd + 1, &rfds, NULL, NULL, &tv);
+	/* Error or timeout */
+	if (retval <= 0)
+		return EOF;
 
-	if (retval < 0)
+	res = read(istream_fd, &c, 1);
+	/* End of file */
+	if (!res)
 		return EOF;
-	else if (retval)
-		result = getc(this->istream);
 
-	return result;
+	return c;
 }
 
 /*-------------------------------------------------------- */