aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/port/win32stat.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/port/win32stat.c b/src/port/win32stat.c
index 2ad8ee13595..3956fac0603 100644
--- a/src/port/win32stat.c
+++ b/src/port/win32stat.c
@@ -289,6 +289,7 @@ int
_pgfstat64(int fileno, struct stat *buf)
{
HANDLE hFile = (HANDLE) _get_osfhandle(fileno);
+ char path[MAX_PATH];
if (hFile == INVALID_HANDLE_VALUE || buf == NULL)
{
@@ -297,6 +298,25 @@ _pgfstat64(int fileno, struct stat *buf)
}
/*
+ * Check if the fileno is a data stream. If so, unless it has been
+ * redirected to a file, getting information through its HANDLE will fail,
+ * so emulate its stat information in the most appropriate way and return
+ * it instead.
+ */
+ if ((fileno == _fileno(stdin) ||
+ fileno == _fileno(stdout) ||
+ fileno == _fileno(stderr)) &&
+ GetFinalPathNameByHandleA(hFile, path, MAX_PATH, VOLUME_NAME_NT) == 0)
+ {
+ memset(buf, 0, sizeof(*buf));
+ buf->st_mode = _S_IFCHR;
+ buf->st_dev = fileno;
+ buf->st_rdev = fileno;
+ buf->st_nlink = 1;
+ return 0;
+ }
+
+ /*
* Since we already have a file handle there is no need to check for
* ERROR_DELETE_PENDING.
*/