+#if defined(CONFIG_ASH_TIMEOUT) && JOBS
+ if (timeout > 0) {
+ tcgetattr(0, &tty);
+ old_tty = tty;
+
+ /* cfmakeraw(...) disables too much; we just do this instead. */
+ tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
+ tcsetattr(0, TCSANOW, &tty);
+
+ FD_ZERO (&set);
+ FD_SET (0, &set);
+
+ timeout_struct.tv_sec = timeout;
+ timeout_struct.tv_usec = 0;
+
+ i = select (FD_SETSIZE, &set, NULL, NULL, &timeout_struct);
+ if(i == 1)
+ {
+ read(0, &c, 1);
+ if(c == '\n' || c == 4) /* Handle newlines and EOF */
+ i = 0; /* Don't read further... */
+ else
+ STPUTC(c, p); /* Keep reading... */
+ }
+ tcsetattr(0, TCSANOW, &old_tty);
+
+ /* Echo the character so the user knows it was read...
+ Yes, this can be done by setting the ECHO flag, but that
+ echoes ^D and other control characters at this state */
+ if(c != 0)
+ write(1, &c, 1);
+
+ } else
+ i = 1;
+
+ for (;i == 1;)
+#else
+ for (;;)
+#endif
+ {