From 4fe8c4be8e8078a5a16643840a27e01d58a21c57 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 24 Jul 2019 11:37:42 -0700 Subject: [PATCH] Switch EINVAL to ESPIPE if io_seek sets EINVAL on Windows I'm not sure if this is the best place to do this, but I think it makes sense to return the same error. We've already added a workaround for the incorrect errno in scanf at d118c84b0b9110462e479487ffaf175a75e5718e. Fixes [Bug #12230] --- io.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/io.c b/io.c index f78c09ba40..5620195073 100644 --- a/io.c +++ b/io.c @@ -1920,7 +1920,15 @@ rb_io_seek(VALUE io, VALUE offset, int whence) pos = NUM2OFFT(offset); GetOpenFile(io, fptr); pos = io_seek(fptr, pos, whence); - if (pos < 0 && errno) rb_sys_fail_path(fptr->pathv); + if (pos < 0 && errno) { +#ifdef _WIN32 + if (errno == EINVAL && + (RTEST(rb_funcall(rb_cFile, rb_intern("pipe?"), 1, io)) || + RTEST(rb_funcall(rb_cFile, rb_intern("socket?"), 1, io)))) + errno = ESPIPE; +#endif + rb_sys_fail_path(fptr->pathv); + } return INT2FIX(0); } -- 2.21.0