aboutsummaryrefslogtreecommitdiffstats
path: root/ruby.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-14 07:03:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-14 07:03:01 +0000
commitd6ed4cad020162cc1acaefc1aab9ed520fa6eea8 (patch)
tree490c0990e164882da43fdb2c52461723d7ca47c6 /ruby.c
parent5b65c6fcc83afef2109a8e8579ebf7598ecca3a4 (diff)
downloadruby-d6ed4cad020162cc1acaefc1aab9ed520fa6eea8.tar.gz
ruby.c: reduce fstat
* file.c (ruby_is_fd_loadable): now return -1 if loadable but may block. * ruby.c (open_load_file): wait to read by the result of ruby_is_fd_loadable, without fstat. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/ruby.c b/ruby.c
index e8633275dc..f96202e217 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1871,15 +1871,14 @@ open_load_file(VALUE fname_v, int *xflag)
}
#endif
-#ifdef S_ISFIFO
- {
- struct stat st;
- if (fstat(fd, &st) != 0) {
+ e = ruby_is_fd_loadable(fd);
+ if (e <= 0) {
+ if (!e) {
e = errno;
(void)close(fd);
rb_load_fail(fname_v, strerror(e));
}
- if (S_ISFIFO(st.st_mode)) {
+ else {
/*
We need to wait if FIFO is empty. It's FIFO's semantics.
rb_thread_wait_fd() release GVL. So, it's safe.
@@ -1887,12 +1886,6 @@ open_load_file(VALUE fname_v, int *xflag)
rb_thread_wait_fd(fd);
}
}
-#endif
- if (!ruby_is_fd_loadable(fd)) {
- e = errno;
- (void)close(fd);
- rb_load_fail(fname_v, strerror(e));
- }
f = rb_io_fdopen(fd, mode, fname);
}