From f11c6dd047a46567231cf98bfb504203dbaaa50b Mon Sep 17 00:00:00 2001 From: christos Date: Sat, 8 Aug 2020 16:01:35 +0000 Subject: PR/55551 Soumendra Ganguly: Simplify tcgetattr error handling. --- usr.bin/script/script.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'usr.bin/script/script.c') diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c index 6c59ad28261..d93c490db8d 100644 --- a/usr.bin/script/script.c +++ b/usr.bin/script/script.c @@ -1,4 +1,4 @@ -/* $NetBSD: script.c,v 1.25 2020/08/07 13:36:28 christos Exp $ */ +/* $NetBSD: script.c,v 1.26 2020/08/08 16:01:35 christos Exp $ */ /* * Copyright (c) 1980, 1992, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1992, 1993\ #if 0 static char sccsid[] = "@(#)script.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: script.c,v 1.25 2020/08/07 13:36:28 christos Exp $"); +__RCSID("$NetBSD: script.c,v 1.26 2020/08/08 16:01:35 christos Exp $"); #endif /* not lint */ #include @@ -158,16 +158,10 @@ main(int argc, char *argv[]) if (tcgetattr(STDIN_FILENO, &tt) == -1 || ioctl(STDIN_FILENO, TIOCGWINSZ, &win) == -1) { - switch (errno) { - case ENOTTY: - if (openpty(&master, &slave, NULL, NULL, NULL) == -1) - err(EXIT_FAILURE, "openpty"); - break; - case EBADF: - err(EXIT_FAILURE, "%d not valid fd", STDIN_FILENO); - default: /* errno == EFAULT or EINVAL for ioctl. Not reached in practice. */ - err(EXIT_FAILURE, "ioctl"); - } + if (errno != ENOTTY) /* For debugger. */ + err(EXIT_FAILURE, "tcgetattr/ioctl"); + if (openpty(&master, &slave, NULL, NULL, NULL) == -1) + err(EXIT_FAILURE, "openpty"); } else { if (openpty(&master, &slave, NULL, &tt, &win) == -1) err(EXIT_FAILURE, "openpty"); @@ -383,9 +377,8 @@ termset(void) struct termios traw; if (tcgetattr(STDOUT_FILENO, &tt) == -1) { - if (errno == EBADF) - err(EXIT_FAILURE, "%d not valid fd", STDOUT_FILENO); - /* errno == ENOTTY */ + if (errno != ENOTTY) /* For debugger. */ + err(EXIT_FAILURE, "tcgetattr"); return; } isterm = 1; -- cgit