Fix error checking on input file

This commit is contained in:
Přemysl Eric Janouch 2017-01-18 16:28:15 +01:00
parent 29c03495e6
commit 5d78d1a316
Signed by: p
GPG Key ID: B715679E3A361BE6
1 changed files with 2 additions and 2 deletions

4
hex.c
View File

@ -1937,13 +1937,13 @@ main (int argc, char *argv[])
if ((input_fd = dup (STDIN_FILENO)) < 0) if ((input_fd = dup (STDIN_FILENO)) < 0)
exit_fatal ("cannot read input: %s", strerror (errno)); exit_fatal ("cannot read input: %s", strerror (errno));
close (STDIN_FILENO); close (STDIN_FILENO);
if (open ("/dev/tty", O_RDWR)) if (open ("/dev/tty", O_RDWR) != STDIN_FILENO)
exit_fatal ("cannot open the terminal: %s", strerror (errno)); exit_fatal ("cannot open the terminal: %s", strerror (errno));
} }
else if (argc == 1) else if (argc == 1)
{ {
g_ctx.filename = xstrdup (argv[0]); g_ctx.filename = xstrdup (argv[0]);
if (!(input_fd = open (argv[0], O_RDONLY))) if ((input_fd = open (argv[0], O_RDONLY)) < 0)
exit_fatal ("cannot open `%s': %s", argv[0], strerror (errno)); exit_fatal ("cannot open `%s': %s", argv[0], strerror (errno));
} }
else else