summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-04-24 00:33:09 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-04-24 00:33:09 +0000
commit787c3ead188aa95b2248601b60819fc4d5f968f7 (patch)
tree9a3b5b1a962805ecfedc81734e95deaca7be111c /dir.c
parent42b3d60056f9ff4009f2398b5697e21a9b48986d (diff)
* dir.c (do_stat, do_lstat, do_opendir): should not warn ENOTDIR.
[ruby-talk:248288] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12210 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/dir.c b/dir.c
index f6ff142b99..c51250ab11 100644
--- a/dir.c
+++ b/dir.c
@@ -928,13 +928,19 @@ sys_warning_1(const char* mesg)
#define GLOB_ALLOC_N(type, n) (type *)malloc(sizeof(type) * (n))
#define GLOB_JUMP_TAG(status) ((status == -1) ? rb_memerror() : rb_jump_tag(status))
+/*
+ * ENOTDIR can be returned by stat(2) if a non-leaf element of the path
+ * is not a directory.
+ */
+#define to_be_ignored(e) ((e) == ENOENT || (e) == ENOTDIR)
+
/* System call with warning */
static int
do_stat(const char *path, struct stat *pst, int flags)
{
int ret = stat(path, pst);
- if (ret < 0 && errno != ENOENT)
+ if (ret < 0 && !to_be_ignored(errno))
sys_warning(path);
return ret;
@@ -944,7 +950,7 @@ static int
do_lstat(const char *path, struct stat *pst, int flags)
{
int ret = lstat(path, pst);
- if (ret < 0 && errno != ENOENT)
+ if (ret < 0 && !to_be_ignored(errno))
sys_warning(path);
return ret;
@@ -954,7 +960,7 @@ static DIR *
do_opendir(const char *path, int flags)
{
DIR *dirp = opendir(path);
- if (dirp == NULL && errno != ENOENT && errno != ENOTDIR)
+ if (dirp == NULL && !to_be_ignored(errno))
sys_warning(path);
return dirp;