summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
Diffstat (limited to 'win32')
-rw-r--r--win32/include/dirent.h2
-rw-r--r--win32/win32.c19
2 files changed, 11 insertions, 10 deletions
diff --git a/win32/include/dirent.h b/win32/include/dirent.h
index d6eb7ea0d9..a66901234f 100644
--- a/win32/include/dirent.h
+++ b/win32/include/dirent.h
@@ -26,7 +26,7 @@ typedef struct direct
{
long d_ino; /* inode number (not used by MS-DOS) */
long d_namlen; /* name length */
- char *d_name; /* file name */
+ char d_name[257]; /* file name */
} _DIRECT;
/* structure for dir operations */
diff --git a/win32/win32.c b/win32/win32.c
index 71a959ae81..bbf85e6967 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -774,11 +774,11 @@ win32_readdir(DIR *dirp)
if (dirp->curr) {
/* first set up the structure to return */
len = strlen(dirp->curr);
- dirp->dirstr.d_name = dirp->curr;
+ strcpy(dirp->dirstr.d_name, dirp->curr);
dirp->dirstr.d_namlen = len;
/* Fake an inode */
- dirp->dirstr.d_ino = (long)dirp->curr;
+ dirp->dirstr.d_ino = dirp->curr - dirp->start;
/* Now set up for the next call to readdir */
dirp->curr += len + 1;
@@ -792,8 +792,6 @@ win32_readdir(DIR *dirp)
/* finding the next file that matches the wildcard
* (which should be all of them in this directory!).
- * the variable idx should point one past the null terminator
- * of the previous string found.
*/
if (USING_WIDE()) {
res = FindNextFileW(dirp->handle, &wFindData);
@@ -808,15 +806,18 @@ win32_readdir(DIR *dirp)
ptr = aFindData.cFileName;
}
if (res) {
- len = strlen(ptr)+1;
+ long endpos = dirp->end - dirp->start;
+ long newsize = endpos + strlen(ptr) + 1;
/* bump the string table size by enough for the
* new name and it's null terminator */
- while (dirp->end + len > dirp->start + dirp->size) {
+ while (newsize > dirp->size) {
+ long curpos = dirp->curr - dirp->start;
dirp->size *= 2;
Renew(dirp->start, dirp->size, char);
+ dirp->curr = dirp->start + curpos;
}
- strcpy(dirp->end, ptr);
- dirp->end += idx;
+ strcpy(dirp->start + endpos, ptr);
+ dirp->end = dirp->start + newsize;
dirp->nfiles++;
}
else
@@ -858,7 +859,7 @@ win32_closedir(DIR *dirp)
{
dTHXo;
if (dirp->handle != INVALID_HANDLE_VALUE)
- FindClose(p->handle);
+ FindClose(dirp->handle);
Safefree(dirp->start);
Safefree(dirp);
return 1;