From 44d489d3d2ee92b5dc49e744682cf5a97737146f Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Mon, 2 Oct 2023 23:03:30 -0400 Subject: [PATCH] Make -w0 behave the same as -wt instead of causing an infinite loop. --- src/init.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/init.c b/src/init.c index 0962ecc7..c39af556 100644 --- a/src/init.c +++ b/src/init.c @@ -543,7 +543,7 @@ void InitRemind(int argc, char const *argv[]) arg++; /* -wt means get width from /dev/tty */ ttyfd = open("/dev/tty", O_RDONLY); - if (!ttyfd) { + if (ttyfd < 0) { fprintf(stderr, "%s: `-wt': Cannot open /dev/tty: %s\n", argv[0], strerror(errno)); } else { @@ -554,7 +554,16 @@ void InitRemind(int argc, char const *argv[]) PARSENUM(CalWidth, arg); if (CalWidth != 0 && CalWidth < 71) CalWidth = 71; if (CalWidth == 0) { - CalWidth = -1; + /* Cal witdh of 0 is same as t */ + ttyfd = open("/dev/tty", O_RDONLY); + if (ttyfd < 0) { + fprintf(stderr, "%s: `-w0': Cannot open /dev/tty: %s\n", + argv[0], strerror(errno)); + CalWidth = 80; + } else { + InitCalWidthAndFormWidth(ttyfd); + close(ttyfd); + } } FormWidth = CalWidth - 8; if (FormWidth < 20) FormWidth = 20;