diff --git a/ChangeLog b/ChangeLog index eb839ae344..c264ec98a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Tue May 29 12:31:33 2007 Nobuyoshi Nakada + + * win32/win32.c (rb_w32_opendir): removed duplicated code. + Tue May 29 10:55:24 2007 Koichi Sasada * cont.c: fix bug around Continuation and Fiber. diff --git a/win32/win32.c b/win32/win32.c index 9cad0b23b1..fef6e49d37 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1447,25 +1447,7 @@ rb_w32_opendir(const char *filename) return NULL; } - // - // now allocate the first part of the string table for the - // filenames that we find. - // - idx = strlen(fd.cFileName)+1; - if (!(p->start = (char *)malloc(idx)) || !(p->bits = (char *)malloc(1))) { - error: - rb_w32_closedir(p); - FindClose(fh); - errno = ENOMEM; - return NULL; - } - strlcpy(p->start, fd.cFileName, idx); - p->bits[0] = 0; - if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - SetBit(p->bits, BitOfIsDir(0)); - if (fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) - SetBit(p->bits, BitOfIsRep(0)); - p->nfiles++; + idx = 0; // // loop finding all the files that match the wildcard @@ -1473,7 +1455,7 @@ rb_w32_opendir(const char *filename) // the variable idx should point one past the null terminator // of the previous string found. // - while (FindNextFile(fh, &fd)) { + do { len = strlen(fd.cFileName) + 1; // @@ -1481,8 +1463,14 @@ rb_w32_opendir(const char *filename) // new name and it's null terminator // tmp = realloc(p->start, idx + len); - if (!tmp) - goto error; + if (!tmp) { + error: + rb_w32_closedir(p); + FindClose(fh); + errno = ENOMEM; + return NULL; + } + p->start = tmp; strlcpy(&p->start[idx], fd.cFileName, len); @@ -1500,7 +1488,7 @@ rb_w32_opendir(const char *filename) p->nfiles++; idx += len; - } + } while (FindNextFile(fh, &fd)); FindClose(fh); p->size = idx; p->curr = p->start;