Skip to content

Commit df6eed7

Browse files
committed
TerminalSize (Linux): enable fast path when stdout is redirected.
1 parent c9ac09f commit df6eed7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/detection/terminalsize/terminalsize_linux.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "common/io/io.h"
33

44
#include <sys/ioctl.h>
5+
#include <fcntl.h>
56
#include <unistd.h>
67

78
#ifdef __sun
@@ -11,7 +12,11 @@
1112
bool ffDetectTerminalSize(FFTerminalSizeResult* result)
1213
{
1314
struct winsize winsize = {};
14-
ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize);
15+
static int ttyfd = STDOUT_FILENO;
16+
if (!isatty(ttyfd))
17+
ttyfd = open("/dev/tty", O_RDWR | O_NOCTTY | O_CLOEXEC);
18+
19+
ioctl(ttyfd, TIOCGWINSZ, &winsize);
1520

1621
if (winsize.ws_row == 0 || winsize.ws_col == 0)
1722
ffGetTerminalResponse("\e[18t", 2, "\e[8;%hu;%hut", &winsize.ws_row, &winsize.ws_col);

0 commit comments

Comments
 (0)