Skip to content

Commit bfb0fb7

Browse files
committed
Fix the error that occurs when PEG is read from the standard input (Windows only)
1 parent 844f8d8 commit bfb0fb7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/packcc.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,14 @@ static void file_pos__term(file_pos_t *pos) {
954954

955955
static void file_id__get(FILE *file, const char *path, file_id_t *id) {
956956
#ifdef _WIN32 /* Windows including MSVC and MinGW */
957-
if (GetFileInformationByHandle((HANDLE)_get_osfhandle(_fileno(file)), id) == 0) {
957+
const int f = _fileno(file);
958+
if (f <= 2) { /* standard input/output/error */
959+
id->dwVolumeSerialNumber = ~(DWORD)0;
960+
id->nFileIndexHigh = 0;
961+
id->nFileIndexLow = f;
962+
return;
963+
}
964+
if (GetFileInformationByHandle((HANDLE)_get_osfhandle(f), id) == 0) {
958965
print_error("Cannot get file information: %s\n", path);
959966
exit(2);
960967
}

0 commit comments

Comments
 (0)