summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-19 08:04:26 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-19 08:04:26 +0000
commit353cd01e2f926d4290784adced100d850f862d77 (patch)
tree60a82f3e78a4c1fa047aae91d59c9dbfef80e920 /dir.c
parent4ea96ece8400f1c6caa8a2429f6d93f15434238f (diff)
* dir.c (join_path): move length of path to an argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39820 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/dir.c b/dir.c
index 5af16ea39a..4859ee90ef 100644
--- a/dir.c
+++ b/dir.c
@@ -1246,9 +1246,8 @@ glob_free_pattern(struct glob_pattern *list)
}
static char *
-join_path(const char *path, int dirsep, const char *name, size_t namlen)
+join_path(const char *path, long len, int dirsep, const char *name, size_t namlen)
{
- long len = strlen(path);
char *buf = GLOB_ALLOC_N(char, len+namlen+(dirsep?1:0)+1);
if (!buf) return 0;
@@ -1311,6 +1310,7 @@ glob_helper(
struct glob_pattern **cur, **new_beg, **new_end;
int plain = 0, magical = 0, recursive = 0, match_all = 0, match_dir = 0;
int escape = !(flags & FNM_NOESCAPE);
+ long pathlen;
for (cur = beg; cur < end; ++cur) {
struct glob_pattern *p = *cur;
@@ -1336,6 +1336,7 @@ glob_helper(
}
}
+ pathlen = strlen(path);
if (*path) {
if (match_all && exist == UNKNOWN) {
if (do_lstat(path, &st, flags) == 0) {
@@ -1362,7 +1363,7 @@ glob_helper(
if (status) return status;
}
if (match_dir && isdir == YES) {
- char *tmp = join_path(path, dirsep, "", 0);
+ char *tmp = join_path(path, pathlen, dirsep, "", 0);
if (!tmp) return -1;
status = glob_call_func(func, tmp, arg, enc);
GLOB_FREE(tmp);
@@ -1392,7 +1393,7 @@ glob_helper(
if (dp->d_name[1] == '.' && !dp->d_name[2]) continue;
}
- buf = join_path(path, dirsep, dp->d_name, NAMLEN(dp));
+ buf = join_path(path, pathlen, dirsep, dp->d_name, NAMLEN(dp));
if (!buf) {
status = -1;
break;
@@ -1473,7 +1474,7 @@ glob_helper(
}
}
- buf = join_path(path, dirsep, name, len);
+ buf = join_path(path, pathlen, dirsep, name, len);
GLOB_FREE(name);
if (!buf) {
GLOB_FREE(new_beg);