Eric Blake wrote: > I just noticed that lseek on mingw returns 0 instead of -1 on pipes. > Which means that gnulib's fflush module thinks the pipe is seekable, and > loses data in the pipe instead of behaving as a no-op as it should in > trying to reposition the pipe's location.
Indeed, lseek on pipes in mingw appears to work if you go past the end (see attached test) but not for backing up data that has already been sucked into the process. Maybe you can swap the lseek and fpurge calls in fflush.c? Or, if that doesn't work, try lseek, then do fpurge, then do fseek again just to be sure? Bruno ================================ lseek-test.c ============================== #include <windows.h> #include <sys/types.h> #include <stdio.h> #include <fcntl.h> static const char *typestring (int type) { if (type == FILE_TYPE_DISK) return "FILE_TYPE_DISK"; if (type == FILE_TYPE_CHAR) return "FILE_TYPE_CHAR"; if (type == FILE_TYPE_PIPE) return "FILE_TYPE_PIPE"; if (type == FILE_TYPE_UNKNOWN) return "FILE_TYPE_UNKNOWN"; return "UNKNOWN"; } int main () { { int fd = 0; int type = GetFileType ((HANDLE) _get_osfhandle (fd)); off_t lseek0 = lseek (fd, 0, SEEK_CUR); off_t lseek1 = lseek (fd, 1, SEEK_CUR); off_t lseek2 = lseek (fd, -2, SEEK_CUR); printf("stdin: %s %ld %ld %ld\n", typestring (type), lseek0, lseek1, lseek2); } { int fd = 1; int type = GetFileType ((HANDLE) _get_osfhandle (fd)); off_t lseek0 = lseek (fd, 0, SEEK_CUR); off_t lseek1 = lseek (fd, 1, SEEK_CUR); off_t lseek2 = lseek (fd, -2, SEEK_CUR); printf("stdout: %s %ld %ld %ld\n", typestring (type), lseek0, lseek1, lseek2); } return 0; } /* Console window: stdin: FILE_TYPE_CHAR -1 -1 -1 stdout: FILE_TYPE_CHAR -1 -1 -1 Console window, pipes: stdin: FILE_TYPE_PIPE 0 1 -1 stdout: FILE_TYPE_PIPE 0 1 -1 rxvt window: stdin: FILE_TYPE_PIPE 0 1 -1 stdout: FILE_TYPE_PIPE 0 1 -1 rxvt window, pipes: stdin: FILE_TYPE_PIPE 0 1 -1 stdout: FILE_TYPE_PIPE 0 1 -1 stdin, stdout redirected to files: stdin: FILE_TYPE_DISK 0 1 -1 stdout: FILE_TYPE_PIPE 0 1 -1 */