mingw: work around stat-limitation
PATCH 1/1 mingw: work around stat-limitation
Our stat implementation for Windows always sets st_ino to 0. This means that checking if isatty(0) and comparing the reported inodes of stdout and stdin is not sufficient to detect that both are pointing to the same TTY.
Luckily, there's only one console on Windows, so adding a check for isatty(1) should do the trick. For platforms where inodes are reported correctly, this should still be correct.
---
Here's a proper patch for this glitch.
builtin/merge.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
builtin/merge.c +1 -0
@@ -1130,6 +1130,7 @@ static int default_edit_option(void)return (!fstat (0 , &st_stdin) && !fstat (1 , &st_stdout) &&isatty (0 ) && +isatty (1 ) && st_stdin.st_dev == st_stdout.st_dev && st_stdin.st_ino == st_stdout.st_ino && st_stdin.st_mode == st_stdout.st_mode);
Signature · 1 line
1.7.9
Hi,
Quoted 8 lines · Erik Faye-Lund
Our stat implementation for Windows always sets
st_inoto 0. This means that checking if isatty(0) and comparing the reported inodes of stdout and stdin is not sufficient to detect that both are pointing to the same TTY.Luckily, there's only one console on Windows, so adding a check for isatty(1) should do the trick. For platforms where inodes are reported correctly, this should still be correct.
Sorry to ask so stupidly, but why does isatty(1) work and isatty(0) does not? Should they not access the very same console object?
Thanks,
Dscho
Quoted 9 lines · Johannes Schindelin
Hi,
Quoted 5 lines · Erik Faye-Lund
Our stat implementation for Windows always sets
st_inoto 0. This means that checking if isatty(0) and comparing the reported inodes of stdout and stdin is not sufficient to detect that both are pointing to the same TTY.
Quoted 7 lines
Quoted 3 lines
Luckily, there's only one console on Windows, so adding a check for isatty(1) should do the trick. For platforms where inodes are reported correctly, this should still be correct.
Sorry to ask so stupidly, but why does isatty(1) work and isatty(0) does not? Should they not access the very same console object?
The point is that they might not. The old test would draw the wrong conclusion if isatty(0) was true, but isatty(1) was not because it used st_ino to verify that stdin and stdout pointed to the same terminal. The reason it did that was to catch cases where stdin and stdout pointed to different terminals, AFAICT. Not checking isatty(1) was simply an optimization, which works when st_ino is filled out correctly.
On Windows there is only one terminal, so it's sufficient to check if both are connected.
Hi kusma,
Quoted 26 lines · Erik Faye-Lund
Quoted 8 lines · Johannes Schindelin
Quoted 5 lines · Erik Faye-Lund
Our stat implementation for Windows always sets
st_inoto 0. This means that checking if isatty(0) and comparing the reported inodes of stdout and stdin is not sufficient to detect that both are pointing to the same TTY.Quoted 7 lines
Quoted 3 lines
Luckily, there's only one console on Windows, so adding a check for isatty(1) should do the trick. For platforms where inodes are reported correctly, this should still be correct.
Sorry to ask so stupidly, but why does isatty(1) work and isatty(0) does not? Should they not access the very same console object?
The point is that they might not. The old test would draw the wrong conclusion if isatty(0) was true, but isatty(1) was not because it used
st_inoto verify that stdin and stdout pointed to the same terminal. The reason it did that was to catch cases where stdin and stdout pointed to different terminals, AFAICT. Not checking isatty(1) was simply an optimization, which works whenst_inois filled out correctly.
Quoted 2 lines
On Windows there is only one terminal, so it's sufficient to check if both are connected.
Ah, okay. Thanks for answering so patiently!
ACK.
Ciao,
Dscho