ruby-changes:27768
From: nobu <ko1@a...>
Date: Tue, 19 Mar 2013 17:09:06 +0900 (JST)
Subject: [ruby-changes:27768] nobu:r39820 (trunk): * dir.c (join_path): move length of path to an argument.
nobu 2013-03-19 17:04:26 +0900 (Tue, 19 Mar 2013) New Revision: 39820 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39820 Log: * dir.c (join_path): move length of path to an argument. Modified files: trunk/dir.c Index: dir.c =================================================================== --- dir.c (revision 39819) +++ dir.c (revision 39820) @@ -1246,9 +1246,8 @@ glob_free_pattern(struct glob_pattern *l https://github.com/ruby/ruby/blob/trunk/dir.c#L1246 } 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( https://github.com/ruby/ruby/blob/trunk/dir.c#L1310 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( https://github.com/ruby/ruby/blob/trunk/dir.c#L1336 } } + pathlen = strlen(path); if (*path) { if (match_all && exist == UNKNOWN) { if (do_lstat(path, &st, flags) == 0) { @@ -1362,7 +1363,7 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/dir.c#L1363 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( https://github.com/ruby/ruby/blob/trunk/dir.c#L1393 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( https://github.com/ruby/ruby/blob/trunk/dir.c#L1474 } } - buf = join_path(path, dirsep, name, len); + buf = join_path(path, pathlen, dirsep, name, len); GLOB_FREE(name); if (!buf) { GLOB_FREE(new_beg); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/