aboutsummaryrefslogtreecommitdiffstats
path: root/win32
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-01-02 16:21:26 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-01-02 16:21:26 +0000
commit59dbfa3e4cc8d4705ef5a4abd9904fa523f26bfa (patch)
treedceea3234a395183be7e17858fbbf80ef291e984 /win32
parent88c127c19be3d12bc5edcb6ceb416985258396c6 (diff)
downloadruby-59dbfa3e4cc8d4705ef5a4abd9904fa523f26bfa.tar.gz
* dir.c: merge tuning from H.Yamamoto <ocean@m2.ccsnet.ne.jp>.
[ruby-dev:22476] * io.c (argf_eof): ARGF.eof? should not have any side effect. [ruby-dev:22469] * io.c (argf_each_byte): should return self. [ruby-dev:22465] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5365 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/dir.h3
-rw-r--r--win32/win32.c22
2 files changed, 25 insertions, 0 deletions
diff --git a/win32/dir.h b/win32/dir.h
index 3dd670bef0..fdea6393c8 100644
--- a/win32/dir.h
+++ b/win32/dir.h
@@ -10,6 +10,7 @@ struct direct
long d_namlen;
ino_t d_ino;
char d_name[256];
+ char d_isdir;
};
typedef struct {
char *start;
@@ -17,6 +18,8 @@ typedef struct {
long size;
long nfiles;
struct direct dirstr;
+ char *bits;
+ long bitpos;
} DIR;
diff --git a/win32/win32.c b/win32/win32.c
index 966c326466..5ea7eccb1a 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -1384,6 +1384,8 @@ rb_w32_opendir(const char *filename)
idx = strlen(fd.name)+1;
p->start = ALLOC_N(char, idx);
strcpy(p->start, fd.name);
+ p->bits = ALLOC_N(char, 1);
+ p->bits[0] = fd.attrib & _A_SUBDIR ? 1 : 0;
p->nfiles++;
//
@@ -1407,6 +1409,18 @@ rb_w32_opendir(const char *filename)
rb_fatal ("opendir: malloc failed!\n");
}
strcpy(&p->start[idx], fd.name);
+
+ if (p->nfiles % 8 == 0) {
+ Renew (p->bits, p->nfiles / 8 + 1, char);
+ if (p->bits == NULL) {
+ rb_fatal ("opendir: malloc failed!\n");
+ }
+ p->bits[p->nfiles / 8] = 0;
+ }
+ if (fd.attrib & _A_SUBDIR) {
+ p->bits[p->nfiles / 8] |= (1 << p->nfiles % 8);
+ }
+
p->nfiles++;
idx += len+1;
}
@@ -1444,6 +1458,12 @@ rb_w32_readdir(DIR *dirp)
dirp->dirstr.d_ino = dummy++;
//
+ // Directory flag
+ //
+ dirp->dirstr.d_isdir = dirp->bits[dirp->bitpos / 8] & (1 << dirp->bitpos % 8);
+ dirp->bitpos++;
+
+ //
// Now set up for the next call to readdir
//
@@ -1486,6 +1506,7 @@ void
rb_w32_rewinddir(DIR *dirp)
{
dirp->curr = dirp->start;
+ dirp->bitpos = 0;
}
//
@@ -1496,6 +1517,7 @@ void
rb_w32_closedir(DIR *dirp)
{
free(dirp->start);
+ free(dirp->bits);
free(dirp);
}