ruby.c: disable nonblock only if nonblocking mode

* ruby.c (open_load_file): disable O_NONBLOCK only when opened in
  non-blocking mode, to get rid of LoadError on Windows.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-10-18 04:22:44 +00:00
Родитель 3d61b259ff
Коммит 1d1ee07f3c
1 изменённых файлов: 6 добавлений и 4 удалений

10
ruby.c
Просмотреть файл

@ -1738,13 +1738,15 @@ open_load_file(VALUE fname_v, int *xflag)
int fd;
/* open(2) may block if fname is point to FIFO and it's empty. Let's
use O_NONBLOCK. */
int mode = O_RDONLY;
#if defined O_NONBLOCK && HAVE_FCNTL && !(O_NONBLOCK & O_ACCMODE)
/* TODO: fix conflicting O_NONBLOCK in ruby/win32.h */
mode |= O_NONBLOCK;
# define MODE_TO_LOAD (O_RDONLY | O_NONBLOCK)
#elif defined O_NDELAY && HAVE_FCNTL && !(O_NDELAY & O_ACCMODE)
mod |= O_NDELAY;
# define MODE_TO_LOAD (O_RDONLY | O_NDELAY)
#else
# define MODE_TO_LOAD (O_RDONLY)
#endif
int mode = MODE_TO_LOAD;
#if defined DOSISH || defined __CYGWIN__
{
const char *ext = strrchr(fname, '.');
@ -1760,7 +1762,7 @@ open_load_file(VALUE fname_v, int *xflag)
}
rb_update_max_fd(fd);
#ifdef HAVE_FCNTL
#if defined HAVE_FCNTL && MODE_TO_LOAD != O_RDONLY
/* disabling O_NONBLOCK */
if (fcntl(fd, F_SETFL, 0) < 0) {
e = errno;