summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-05-29 03:30:14 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-05-29 03:30:14 +0000
commit82159c813bcf74b117ca37801a3fa527f1909a6b (patch)
treefcc3f0c26b608f3fd9c416a762ab4fa0b71d9cb9 /win32
parentd64609463fb755d94922e0d205283416542d9ea2 (diff)
* 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
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c34
1 files changed, 11 insertions, 23 deletions
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;