t->display_info.tty->input = stdin;
#else /* !MSDOS */
fd = emacs_open (t->display_info.tty->name, O_RDWR | O_NOCTTY, 0);
+ t->display_info.tty->input = t->display_info.tty->output
+ = fd < 0 ? 0 : fdopen (fd, "w+");
- if (fd == -1)
- error ("Can not reopen tty device %s: %s", t->display_info.tty->name, strerror (errno));
+ if (! t->display_info.tty->input)
+ {
+ int open_errno = errno;
+ emacs_close (fd);
+ report_file_errno ("Cannot reopen tty device",
+ build_string (t->display_info.tty->name),
+ open_errno);
+ }
if (!O_IGNORE_CTTY && strcmp (t->display_info.tty->name, DEV_TTY) != 0)
dissociate_if_controlling_tty (fd);
-
- t->display_info.tty->output = fdopen (fd, "w+");
- t->display_info.tty->input = t->display_info.tty->output;
#endif
add_keyboard_wait_descriptor (fd);
{
/* Open the terminal device. */
- FILE *file;
/* If !ctty, don't recognize it as our controlling terminal, and
don't make it the controlling tty if we don't have one now.
open a frame on the same terminal. */
int flags = O_RDWR | O_NOCTTY | (ctty ? 0 : O_IGNORE_CTTY);
int fd = emacs_open (name, flags, 0);
+ tty->input = tty->output = fd < 0 || ! isatty (fd) ? 0 : fdopen (fd, "w+");
- tty->name = xstrdup (name);
- terminal->name = xstrdup (name);
-
- if (fd < 0)
- maybe_fatal (must_succeed, terminal,
- "Could not open file: %s",
- "Could not open file: %s",
- name);
- if (!isatty (fd))
+ if (! tty->input)
{
- emacs_close (fd);
- maybe_fatal (must_succeed, terminal,
- "Not a tty device: %s",
- "Not a tty device: %s",
- name);
+ char const *diagnostic
+ = tty->input ? "Not a tty device: %s" : "Could not open file: %s";
+ emacs_close (fd);
+ maybe_fatal (must_succeed, terminal, diagnostic, diagnostic, name);
}
+ tty->name = xstrdup (name);
+ terminal->name = xstrdup (name);
+
if (!O_IGNORE_CTTY && !ctty)
dissociate_if_controlling_tty (fd);
-
- file = fdopen (fd, "w+");
- tty->input = file;
- tty->output = file;
}
tty->type = xstrdup (terminal_type);