diff options
author | Ron Yorston <rmy@pobox.com> | 2016-05-24 10:48:34 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2016-05-24 10:48:34 +0100 |
commit | 0d5f85b255e68385b4aa1b6b8c40ab4b7ad35125 (patch) | |
tree | 8c95da606bba2299f3b84dd266f931335fa5b64b /win32 | |
parent | 1f3a582db3ca7cd7f33d5ab6f2f6c46d68de689d (diff) | |
download | busybox-w32-0d5f85b255e68385b4aa1b6b8c40ab4b7ad35125.tar.gz busybox-w32-0d5f85b255e68385b4aa1b6b8c40ab4b7ad35125.tar.bz2 busybox-w32-0d5f85b255e68385b4aa1b6b8c40ab4b7ad35125.zip |
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.
Diffstat (limited to 'win32')
-rw-r--r-- | win32/mingw.c | 14 |
1 files changed, 14 insertions, 0 deletions
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) | |||
1030 | 1030 | ||
1031 | return opendir(path); | 1031 | return opendir(path); |
1032 | } | 1032 | } |
1033 | |||
1034 | off_t mingw_lseek(int fd, off_t offset, int whence) | ||
1035 | { | ||
1036 | HANDLE h = (HANDLE)_get_osfhandle(fd); | ||
1037 | if (h == INVALID_HANDLE_VALUE) { | ||
1038 | errno = EBADF; | ||
1039 | return -1; | ||
1040 | } | ||
1041 | if (GetFileType(h) != FILE_TYPE_DISK) { | ||
1042 | errno = ESPIPE; | ||
1043 | return -1; | ||
1044 | } | ||
1045 | return _lseeki64(fd, offset, whence); | ||
1046 | } | ||