From 734cc61489e01e2161f39c7ef8863b778ee41292 Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Mon, 2 Oct 2023 23:07:34 -0400 Subject: [PATCH] Better logic for checking if we should close TTY fd. --- src/funcs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/funcs.c b/src/funcs.c index 5ced952e..ff963ee0 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -3574,6 +3574,8 @@ rows_or_cols(func_info *info, int want_rows) struct winsize w; int fd = STDOUT_FILENO; + int opened = 0; + RetVal.type = INT_TYPE; if (!isatty(fd)) { fd = open("/dev/tty", O_RDONLY); @@ -3581,6 +3583,7 @@ rows_or_cols(func_info *info, int want_rows) RETVAL = -1; return OK; } + opened = 1; } if (ioctl(fd, TIOCGWINSZ, &w) == 0) { if (want_rows) RETVAL = w.ws_row; @@ -3588,7 +3591,7 @@ rows_or_cols(func_info *info, int want_rows) } else { RETVAL = -1; } - if (fd != STDOUT_FILENO) { + if (opened) { close(fd); } return OK;