mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 13:53:10 +00:00
Bravely replace ttyname with ttyname_r
This is more thread safe. We'll see if any platforms don't have this.
This commit is contained in:
parent
e98b7d1a56
commit
e2e340823a
1 changed files with 4 additions and 4 deletions
|
@ -1939,14 +1939,14 @@ std::string get_path_to_tmp_dir() {
|
||||||
// bullet-proof and that's OK.
|
// bullet-proof and that's OK.
|
||||||
bool is_console_session() {
|
bool is_console_session() {
|
||||||
static const bool console_session = [] {
|
static const bool console_session = [] {
|
||||||
ASSERT_IS_MAIN_THREAD();
|
char tty_name[PATH_MAX];
|
||||||
|
if (ttyname_r(STDIN_FILENO, tty_name, sizeof tty_name) != 0) {
|
||||||
const char *tty_name = ttyname(0);
|
return false;
|
||||||
|
}
|
||||||
constexpr auto len = const_strlen("/dev/tty");
|
constexpr auto len = const_strlen("/dev/tty");
|
||||||
const char *TERM = getenv("TERM");
|
const char *TERM = getenv("TERM");
|
||||||
return
|
return
|
||||||
// Test that the tty matches /dev/(console|dcons|tty[uv\d])
|
// Test that the tty matches /dev/(console|dcons|tty[uv\d])
|
||||||
tty_name &&
|
|
||||||
((strncmp(tty_name, "/dev/tty", len) == 0 &&
|
((strncmp(tty_name, "/dev/tty", len) == 0 &&
|
||||||
(tty_name[len] == 'u' || tty_name[len] == 'v' || isdigit(tty_name[len]))) ||
|
(tty_name[len] == 'u' || tty_name[len] == 'v' || isdigit(tty_name[len]))) ||
|
||||||
strcmp(tty_name, "/dev/dcons") == 0 || strcmp(tty_name, "/dev/console") == 0)
|
strcmp(tty_name, "/dev/dcons") == 0 || strcmp(tty_name, "/dev/console") == 0)
|
||||||
|
|
Loading…
Reference in a new issue