From 12331d4939f431e84ed7ca26efc53d7dcf861cf0 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 27 Feb 2009 08:45:26 +0000 Subject: [PATCH] * file.c (file_load_ok): checks if regular file, except for the platform disallows to open directories, e.g. cygwin. [ruby-dev:38097], [Bug #1221] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++-- file.c | 16 +++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index bc001e1795..77ea2dfd7c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ -Fri Feb 27 15:49:41 2009 Nobuyoshi Nakada +Fri Feb 27 17:45:25 2009 Nobuyoshi Nakada - * file.c (file_load_ok): checks if regular file. [ruby-dev:38097] + * file.c (file_load_ok): checks if regular file, except for the + platform disallows to open directories, e.g. cygwin. + [ruby-dev:38097], [Bug #1221] Fri Feb 27 14:39:40 2009 NAKAMURA Usaku diff --git a/file.c b/file.c index 270a3ab4cb..213491bda6 100644 --- a/file.c +++ b/file.c @@ -4521,13 +4521,19 @@ rb_path_check(const char *path) static int file_load_ok(const char *path) { - struct stat st; - int ret, fd = open(path, O_RDONLY); + int ret = 1; + int fd = open(path, O_RDONLY); if (fd == -1) return 0; - ret = fstat(fd, &st); +#if !(defined DOSISH || defined __CYGWIN__) + { + struct stat st; + if (fstat(fd, &st) || !S_ISREG(st.st_mode)) { + ret = 0; + } + } +#endif (void)close(fd); - if (ret) return 0; - return S_ISREG(st.st_mode); + return ret; } static int