From: "H.Yamamoto" Date: 2003-12-28T19:03:35+09:00 Subject: [ruby-dev:22446] Re: Dir.glob とShjift_JIS について 山本です。 すみません、バグがありました。新しく文字列を確保すべきところで、 していませんでした。 # 自分で言うのも何ですけど、処理の流れがわかりにくいかも。 [ruby-dev:22444]に対するパッチです。 後半のは見栄えの修正で、動作に違いはありません。 --- dir,c-22444 Sun Dec 28 11:28:56 2003 +++ dir.c Sun Dec 28 18:43:14 2003 @@ -1048,3 +1048,6 @@ glob_helper(path, sub, separator, flags, if (!magical) { - status = glob_helper(path, p, separator, flags, func, arg); + buf = ALLOC_N(char, strlen(path)+1); + strcpy(buf, path); + status = glob_helper(buf, buf+(p-path), separator, flags, func, arg); + free(buf); if (status) return status; @@ -1066,6 +1069,5 @@ glob_helper(path, sub, separator, flags, for (dp = readdir(dirp); dp != NULL && status == 0; dp = readdir(dirp)) { - const int uncheck = 0; - const int dir = 1; - const int notdir = 2; - int type = uncheck; + const int ok = 0; + const int no = 1; + int dir = -1; if (recursive && strcmp(".", dp->d_name) != 0 && strcmp("..", dp->d_name) != 0) { @@ -1075,3 +1077,3 @@ glob_helper(path, sub, separator, flags, strcpy(buf+n, dp->d_name); - type = notdir; + dir = no; if (do_lstat(buf, &st) == 0) { @@ -1083,6 +1085,6 @@ glob_helper(path, sub, separator, flags, tail = &tmp->next; - type = dir; + dir = ok; } else if (S_ISLNK(st.st_mode) && do_stat(buf, &st) == 0 && S_ISDIR(st.st_mode)) { - type = dir; + dir = ok; } @@ -1091,3 +1093,3 @@ glob_helper(path, sub, separator, flags, } - if (type == notdir && *m == '/') + if (dir == no && *m == '/') continue; @@ -1102,3 +1104,3 @@ glob_helper(path, sub, separator, flags, } - else if (m[1] == '\0' && type == dir) { + else if (m[1] == '\0' && dir == ok) { strcpy(buf+n1+n2, m);