From 92de2ed517cea4524579092ce7962a879d33a7e9 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 8 Apr 2010 16:27:42 +0000 Subject: [PATCH] * io.c (internal_{read,write}_func, rb_{read,write}_internal): preserve errno. a patch from Takehiro Kubo in [ruby-core:29340]. [ruby-core:28924] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27265 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ io.c | 21 +++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index f7150d0a5c..3bde31c668 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Apr 9 01:26:54 2010 Nobuyoshi Nakada + + * io.c (internal_{read,write}_func, rb_{read,write}_internal): + preserve errno. a patch from Takehiro Kubo in [ruby-core:29340]. + [ruby-core:28924] + Fri Apr 9 01:12:07 2010 Yusuke Endoh * lib/irb/completion.rb (CompletionProc): calling the method "methods" diff --git a/io.c b/io.c index 362beb192b..31bdf7e0a3 100644 --- a/io.c +++ b/io.c @@ -530,6 +530,7 @@ wsplit_p(rb_io_t *fptr) struct io_internal_struct { int fd; + int saved_errno; void *buf; size_t capa; }; @@ -538,36 +539,48 @@ static VALUE internal_read_func(void *ptr) { struct io_internal_struct *iis = (struct io_internal_struct*)ptr; - return read(iis->fd, iis->buf, iis->capa); + ssize_t ret = read(iis->fd, iis->buf, iis->capa); + iis->saved_errno = errno; + return (VALUE)ret; } static VALUE internal_write_func(void *ptr) { struct io_internal_struct *iis = (struct io_internal_struct*)ptr; - return write(iis->fd, iis->buf, iis->capa); + ssize_t ret = write(iis->fd, iis->buf, iis->capa); + iis->saved_errno = errno; + return (VALUE)ret; } static ssize_t rb_read_internal(int fd, void *buf, size_t count) { struct io_internal_struct iis; + ssize_t ret; + iis.fd = fd; iis.buf = buf; iis.capa = count; - return (ssize_t)rb_thread_blocking_region(internal_read_func, &iis, RUBY_UBF_IO, 0); + ret = (ssize_t)rb_thread_blocking_region(internal_read_func, &iis, RUBY_UBF_IO, 0); + errno = iis.saved_errno; + return ret; } static ssize_t rb_write_internal(int fd, void *buf, size_t count) { struct io_internal_struct iis; + ssize_t ret; + iis.fd = fd; iis.buf = buf; iis.capa = count; - return (ssize_t)rb_thread_blocking_region(internal_write_func, &iis, RUBY_UBF_IO, 0); + ret = (ssize_t)rb_thread_blocking_region(internal_write_func, &iis, RUBY_UBF_IO, 0); + errno = iis.saved_errno; + return ret; } static long