diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-01-05 10:01:54 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-01-05 10:01:54 +0000 |
commit | caaac4db27bcd33f7865faaf60d6a848c5204d03 (patch) | |
tree | 9e89a3575c3a1a279d8477c6582c2fd8d4b8402f /win32/win32.c | |
parent | 7336cf5424cd9adb91fb56005cf55b39410d9305 (diff) | |
download | ruby-caaac4db27bcd33f7865faaf60d6a848c5204d03.tar.gz |
* dir.c: merge tuning from H.Yamamoto <ocean@m2.ccsnet.ne.jp>.
[ruby-dev:22486]
* pack.c (pack_unpack): unpack requires big endian offet (OFF16B
and OFF32B). The patch is from Minero Aoki in [ruby-dev:22489]
* pack.c (OFF16B): add big-endian offset again.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32/win32.c')
-rw-r--r-- | win32/win32.c | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/win32/win32.c b/win32/win32.c index 5ea7eccb1a..d592ba6b8b 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1323,6 +1323,9 @@ make_cmdvector(const char *cmd, char ***vec) // return the pointer to the current file name. // +#define GetBit(bits, i) ((bits)[(i) / 8] & (1 << (i) % 8)) +#define SetBit(bits, i) ((bits)[(i) / 8] |= (1 << (i) % 8)) + DIR * rb_w32_opendir(const char *filename) { @@ -1332,8 +1335,8 @@ rb_w32_opendir(const char *filename) char scannamespc[PATHLEN]; char *scanname = scannamespc; struct stat sbuf; - struct _finddata_t fd; - long fh; + WIN32_FIND_DATA fd; + HANDLE fh; // // check to see if we've got a directory @@ -1371,8 +1374,8 @@ rb_w32_opendir(const char *filename) // do the FindFirstFile call // - fh = _findfirst(scanname, &fd); - if (fh == -1) { + fh = FindFirstFile(scanname, &fd); + if (fh == INVALID_HANDLE_VALUE) { return NULL; } @@ -1381,9 +1384,15 @@ rb_w32_opendir(const char *filename) // filenames that we find. // - idx = strlen(fd.name)+1; + idx = strlen(fd.cFileName)+1; p->start = ALLOC_N(char, idx); - strcpy(p->start, fd.name); + strcpy(p->start, fd.cFileName); + p->bits = ALLOC_N(char, 1); + p->bits[0] = 0; + if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + SetBit(p->bits, 0); + if (fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) + SetBit(p->bits, 1); p->bits = ALLOC_N(char, 1); p->bits[0] = fd.attrib & _A_SUBDIR ? 1 : 0; p->nfiles++; @@ -1394,8 +1403,8 @@ rb_w32_opendir(const char *filename) // the variable idx should point one past the null terminator // of the previous string found. // - while (_findnext(fh, &fd) == 0) { - len = strlen(fd.name); + while (FindNextFile(fh, &fd)) { + len = strlen(fd.cFileName); // // bump the string table size by enough for the @@ -1408,7 +1417,20 @@ rb_w32_opendir(const char *filename) if (p->start == NULL) { rb_fatal ("opendir: malloc failed!\n"); } - strcpy(&p->start[idx], fd.name); + strcpy(&p->start[idx], fd.cFileName); + + if (p->nfiles % 4 == 0) { + Renew (p->bits, p->nfiles / 4 + 1, char); + if (p->bits == NULL) { + rb_fatal ("opendir: malloc failed!\n"); + } + p->bits[p->nfiles / 4] = 0; + } + if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + SetBit(p->bits, p->nfiles * 2); + if (fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) + SetBit(p->bits, p->nfiles * 2 + 1); + if (p->nfiles % 8 == 0) { Renew (p->bits, p->nfiles / 8 + 1, char); @@ -1424,7 +1446,7 @@ rb_w32_opendir(const char *filename) p->nfiles++; idx += len+1; } - _findclose(fh); + FindClose(fh); p->size = idx; p->curr = p->start; return p; @@ -1464,6 +1486,14 @@ rb_w32_readdir(DIR *dirp) dirp->bitpos++; // + // Attributes + // + dirp->dirstr.d_isdir = GetBit(dirp->bits, dirp->bitpos); + dirp->bitpos++; + dirp->dirstr.d_isrep = GetBit(dirp->bits, dirp->bitpos); + dirp->bitpos++; + + // // Now set up for the next call to readdir // @@ -1507,6 +1537,7 @@ rb_w32_rewinddir(DIR *dirp) { dirp->curr = dirp->start; dirp->bitpos = 0; + dirp->bitpos = 0; } // @@ -1516,6 +1547,7 @@ rb_w32_rewinddir(DIR *dirp) void rb_w32_closedir(DIR *dirp) { + free(dirp->bits); free(dirp->start); free(dirp->bits); free(dirp); |