Fix errno at seeking socket/pipe on Windows

[Bug #12230]
This commit is contained in:
Nobuyoshi Nakada 2019-07-25 06:39:40 +09:00
parent efa380b006
commit 0a63c4d5fb
No known key found for this signature in database
GPG Key ID: 4BC7D6DF58D8DF60
3 changed files with 16 additions and 1 deletions

View File

@ -146,7 +146,7 @@ typedef int clockid_t;
#define HAVE_UTIMENSAT 1 #define HAVE_UTIMENSAT 1
#define AT_FDCWD -100 #define AT_FDCWD -100
#define utimensat(_d, _p, _t, _f) rb_w32_utimensat(_d, _p, _t, _f) #define utimensat(_d, _p, _t, _f) rb_w32_utimensat(_d, _p, _t, _f)
#define lseek(_f, _o, _w) _lseeki64(_f, _o, _w) #define lseek(_f, _o, _w) rb_w32_lseek(_f, _o, _w)
#define pipe(p) rb_w32_pipe(p) #define pipe(p) rb_w32_pipe(p)
#define open rb_w32_open #define open rb_w32_open
@ -751,6 +751,7 @@ int rb_w32_fclose(FILE*);
int rb_w32_pipe(int[2]); int rb_w32_pipe(int[2]);
ssize_t rb_w32_read(int, void *, size_t); ssize_t rb_w32_read(int, void *, size_t);
ssize_t rb_w32_write(int, const void *, size_t); ssize_t rb_w32_write(int, const void *, size_t);
off_t rb_w32_lseek(int, off_t, int);
int rb_w32_utime(const char *, const struct utimbuf *); int rb_w32_utime(const char *, const struct utimbuf *);
int rb_w32_uutime(const char *, const struct utimbuf *); int rb_w32_uutime(const char *, const struct utimbuf *);
int rb_w32_utimes(const char *, const struct timeval *); int rb_w32_utimes(const char *, const struct timeval *);

View File

@ -2240,6 +2240,9 @@ class TestIO < Test::Unit::TestCase
assert_raise(Errno::ENOENT, Errno::EINVAL) do assert_raise(Errno::ENOENT, Errno::EINVAL) do
Class.new(IO).binread("|#{EnvUtil.rubybin} -e puts") Class.new(IO).binread("|#{EnvUtil.rubybin} -e puts")
end end
assert_raise(Errno::ESPIPE) do
IO.read("|echo foo", 1, 1)
end
end end
def test_reopen def test_reopen

View File

@ -5845,6 +5845,17 @@ rb_w32_lstati128(const char *path, struct stati128 *st)
return w32_stati128(path, st, filecp(), TRUE); return w32_stati128(path, st, filecp(), TRUE);
} }
off_t
rb_w32_lseek(int fd, off_t ofs, int whence)
{
SOCKET sock = TO_SOCKET(fd);
if (is_socket(sock) || is_pipe(sock)) {
errno = ESPIPE;
return -1;
}
return _lseeki64(fd, ofs, whence);
}
/* License: Ruby's */ /* License: Ruby's */
int int
rb_w32_access(const char *path, int mode) rb_w32_access(const char *path, int mode)