- if((ttystring = (char *)ttyname(fileno(stdin))) == NULL) {
- fout = stderr;
- fin = stdin;
- }
- else /* Reading directly from terminal here */
- {
- fout = fin = fopen(ttystring, "w+");
- (void)tcgetattr(fileno(fin), &oterm);
- term = oterm; /* Save original info */
- term.c_lflag &= ~ECHO;
- (void)fputs(prompt, fout);
- rewind(fout); /* implied flush */
- (void)tcsetattr(fileno(fin), TCSANOW, &term);
- }
+ if (!istty || !(fout = fin = fopen("/dev/tty", "w+"))) {
+ fout = stderr;
+ fin = stdin;
+ } else { /* Reading directly from terminal here */
+ (void)tcgetattr(fileno(fin), &oterm);
+ term = oterm; /* Save original info */
+ term.c_lflag &= ~ECHO;
+ (void)fputs(prompt, fout);
+ rewind(fout); /* implied flush */
+ (void)tcsetattr(fileno(fin), TCSANOW, &term);
+ }