>_fstat64() and _stat64() have proved to be tricky to work with and
>rather unworkable across all the build systems we support
I agree, it is better not use them.
>I think that we had better never call GetFileInformationByHandle() if
>we use a fileno that maps to stdin, stdout or stderr.
Probably we should call GetFileInformationByHandle() for case standard
streams stdin/stdout/stderr are redirected to files.
See file src\backend\utils\error\elog.c, for example. It contains
lines:
if (!freopen(OutputFileName, "a", stderr))
if (!freopen(OutputFileName, "a", stdout))
And this command with "stderr" works in PSQL without crash (in
contrast to "stdout"):
\copy (SELECT 1) TO stderr
(it put resullt into file with name "stderr").
We can emulate stats for stdin/stdout/stderr after call
GetFileInformationByHandle().
>Just to be sure, this is the code path in psql's copy.c where we check
>that a specified copystream is not a directory, right?
Yes, fstat() called from file src/bin/psql/copy.c:
/* make sure the specified file is not a directory */
if ((result = fstat(fileno(copystream), &st)) < 0)
I attached new patch version.
With best regards,
Dmitry Koval.