diff options
| author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-05-29 03:30:14 +0000 |
|---|---|---|
| committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-05-29 03:30:14 +0000 |
| commit | 5090609cb5177ce384359d34a560195665595deb (patch) | |
| tree | fcc3f0c26b608f3fd9c416a762ab4fa0b71d9cb9 | |
| parent | c55e7d2abc2f94c2ebf6cf119d826ea7a3fe9048 (diff) | |
| download | ruby-5090609cb5177ce384359d34a560195665595deb.tar.gz ruby-5090609cb5177ce384359d34a560195665595deb.tar.xz ruby-5090609cb5177ce384359d34a560195665595deb.zip | |
* win32/win32.c (rb_w32_opendir): removed duplicated code.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@12402 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 4 | ||||
| -rw-r--r-- | win32/win32.c | 34 |
2 files changed, 15 insertions, 23 deletions
@@ -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. diff --git a/win32/win32.c b/win32/win32.c index 9cad0b23b..fef6e49d3 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; |
