From 0d5f85b255e68385b4aa1b6b8c40ab4b7ad35125 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 24 May 2016 10:48:34 +0100 Subject: win32: return an error when lseek is applied to a pipe tail failed to process input from a pipe correctly: $ echo -n 54321 | tail -c 3 543 It was trying to use lseek as an optimisation but WIN32 lseek doesn't return an error whan applied to a pipe. Fix this by providing a wrapper for lseek. --- win32/mingw.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'win32') diff --git a/win32/mingw.c b/win32/mingw.c index ebdcdee26..23ca5d3dd 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -1030,3 +1030,17 @@ DIR *mingw_opendir(const char *path) return opendir(path); } + +off_t mingw_lseek(int fd, off_t offset, int whence) +{ + HANDLE h = (HANDLE)_get_osfhandle(fd); + if (h == INVALID_HANDLE_VALUE) { + errno = EBADF; + return -1; + } + if (GetFileType(h) != FILE_TYPE_DISK) { + errno = ESPIPE; + return -1; + } + return _lseeki64(fd, offset, whence); +} -- cgit v1.2.3-55-g6feb