[前][次][番号順一覧][スレッド一覧]

ruby-changes:56648

From: Nobuyoshi <ko1@a...>
Date: Thu, 25 Jul 2019 06:41:46 +0900 (JST)
Subject: [ruby-changes:56648] Nobuyoshi Nakada: 0a63c4d5fb (master): Fix errno at seeking socket/pipe on Windows

https://git.ruby-lang.org/ruby.git/commit/?id=0a63c4d5fb

From 0a63c4d5fbbbfae9aba92c78e39b1521b90f1b06 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 25 Jul 2019 06:39:40 +0900
Subject: Fix errno at seeking socket/pipe on Windows

[Bug #12230]

diff --git a/include/ruby/win32.h b/include/ruby/win32.h
index fe1978f..b29470b 100644
--- a/include/ruby/win32.h
+++ b/include/ruby/win32.h
@@ -146,7 +146,7 @@ typedef int clockid_t; https://github.com/ruby/ruby/blob/trunk/include/ruby/win32.h#L146
 #define HAVE_UTIMENSAT 1
 #define AT_FDCWD		-100
 #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 open			rb_w32_open
@@ -751,6 +751,7 @@ int  rb_w32_fclose(FILE*); https://github.com/ruby/ruby/blob/trunk/include/ruby/win32.h#L751
 int  rb_w32_pipe(int[2]);
 ssize_t rb_w32_read(int, 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_uutime(const char *, const struct utimbuf *);
 int  rb_w32_utimes(const char *, const struct timeval *);
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 3c5dc76..0c81f4c 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -2240,6 +2240,9 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2240
     assert_raise(Errno::ENOENT, Errno::EINVAL) do
       Class.new(IO).binread("|#{EnvUtil.rubybin} -e puts")
     end
+    assert_raise(Errno::ESPIPE) do
+      IO.read("|echo foo", 1, 1)
+    end
   end
 
   def test_reopen
diff --git a/win32/win32.c b/win32/win32.c
index d28bd56..825b423 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -5845,6 +5845,17 @@ rb_w32_lstati128(const char *path, struct stati128 *st) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5845
     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 */
 int
 rb_w32_access(const char *path, int mode)
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]