--- a/src/gromacs/fileio/groio.cpp +++ b/src/gromacs/fileio/groio.cpp @@ -341,7 +341,15 @@ if (!beof) { - gmx_fseek(fp, -1, SEEK_CUR); + /* Push the peeked byte back with ungetc instead of seeking backwards. + * The original gmx_fseek(fp, -1, SEEK_CUR) fails with EINVAL on + * text-mode streams with the Windows CRT (relative seeks are not + * supported there), which broke reading of all multi-frame .gro + * trajectories on Windows. ungetc is standard and mode-independent. */ + if (ungetc(data[0], fp) == EOF) + { + gmx_fseek(fp, -1, SEEK_CUR); + } } return beof; }