diff --git a/src/port/win32stat.c b/src/port/win32stat.c index 2ad8ee1..95c891c 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) { @@ -301,6 +302,18 @@ _pgfstat64(int fileno, struct stat *buf) * ERROR_DELETE_PENDING. */ + if ((fileno == _fileno(stdin) || + fileno == _fileno(stdout) || + fileno == _fileno(stderr)) && + !GetFinalPathNameByHandleA(hFile, path, MAX_PATH, VOLUME_NAME_NT)) + { + memset(buf, 0, sizeof(*buf)); + buf->st_mode = _S_IFCHR; + buf->st_dev = fileno; + buf->st_rdev = fileno; + buf->st_nlink = 1; + return 0; + } return fileinfo_to_stat(hFile, buf); }