static volatile unsigned cached_lines = 0;
static volatile int cached_on_tty = -1;
+static volatile int cached_on_dev_null = -1;
static volatile int cached_color_mode = _COLOR_INVALID;
static volatile int cached_underline_enabled = -1;
cached_color_mode = _COLOR_INVALID;
cached_underline_enabled = -1;
cached_on_tty = -1;
+ cached_on_dev_null = -1;
}
bool on_tty(void) {
return receive_one_fd(pair[0], 0);
}
+static bool on_dev_null(void) {
+ struct stat dst, ost, est;
+
+ if (cached_on_dev_null >= 0)
+ return cached_on_dev_null;
+
+ if (stat("/dev/null", &dst) < 0 || fstat(STDOUT_FILENO, &ost) < 0 || fstat(STDERR_FILENO, &est) < 0)
+ cached_on_dev_null = false;
+ else
+ cached_on_dev_null = stat_inode_same(&dst, &ost) && stat_inode_same(&dst, &est);
+
+ return cached_on_dev_null;
+}
+
static bool getenv_terminal_is_dumb(void) {
const char *e;
}
bool terminal_is_dumb(void) {
- if (!on_tty())
+ if (!on_tty() && !on_dev_null())
return true;
return getenv_terminal_is_dumb();