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. --- include/mingw.h | 7 ++++--- win32/mingw.c | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/mingw.h b/include/mingw.h index efb17e137..04700963c 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -289,11 +289,9 @@ int mingw_chmod(const char *path, int mode); #define mkdir mingw_mkdir #define chmod mingw_chmod -#if ENABLE_LFS +#if ENABLE_LFS && !defined(__MINGW64_VERSION_MAJOR) # define off_t off64_t #endif -#undef lseek -#define lseek _lseeki64 typedef int nlink_t; typedef int blksize_t; @@ -388,6 +386,7 @@ NOIMPL(chroot,const char *root UNUSED_PARAM); NOIMPL(fchdir,int fd UNUSED_PARAM); int mingw_dup2 (int fd, int fdto); char *mingw_getcwd(char *pointer, int len); +off_t mingw_lseek(int fd, off_t offset, int whence); IMPL(getgid,int,DEFAULT_GID,void); @@ -428,6 +427,8 @@ int mingw_rmdir(const char *name); #define open mingw_open #define unlink mingw_unlink #define rmdir mingw_rmdir +#undef lseek +#define lseek mingw_lseek #undef access #define access mingw_access 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