* win32/win32.c (rb_w32_opendir): removed duplicated code.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12402 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-05-29 03:30:14 +00:00
Родитель d64609463f
Коммит 82159c813b
2 изменённых файлов: 15 добавлений и 23 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Tue May 29 12:31:33 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/win32.c (rb_w32_opendir): removed duplicated code.
Tue May 29 10:55:24 2007 Koichi Sasada <ko1@atdot.net>
* cont.c: fix bug around Continuation and Fiber.

Просмотреть файл

@ -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;