Fix compatibility thinko for fstat() on standard streams in win32stat.c
authorMichael Paquier <michael@paquier.xyz>
Tue, 30 Nov 2021 00:55:56 +0000 (09:55 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 30 Nov 2021 00:55:56 +0000 (09:55 +0900)
commit5550a9c385198ac51d2f3b17be2f6ff9f886d76d
tree40d68ff3c1dbbfef4cf501c72bfa309fd5a92577
parentce43b3dc52c90082981f2f1de5351a95fc21c405
Fix compatibility thinko for fstat() on standard streams in win32stat.c

GetFinalPathNameByHandleA() cannot be used in compilation environments
where _WIN32_WINNT < 0x0600, meaning at least Windows XP used by some
buildfarm members under MinGW that Postgres still needs to support.
This was reported as a compilation warning by the buildfarm, but this is
actually worse than the report as the code would have not worked.

Instead, this switches to GetFileInformationByHandle() that is able to
fail for standard streams and succeed for redirected ones, which is what
we are looking for herein the code emulating fstat().  We also know that
it is able to work in all the environments still supported, thanks to
the existing logic of win32stat.c.

Issue introduced by 10260c7, so backpatch down to 14.

Reported-by: Justin Pryzby, via buildfarm member jacana
Author: Michael Paquier
Reviewed-by: Juan José Santamaría Flecha
Discussion: https://postgr.es/m/20211129050122.GK17618@telsasoft.com
Backpatch-through: 14
src/port/win32stat.c