From: Gurusamy Sarathy Date: Fri, 15 Oct 1999 05:45:36 +0000 (+0000) Subject: various little goofs in change#4385 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0f38926bbb8f61974f71662cfb90af18d05c1f1b;p=p5sagit%2Fp5-mst-13.2.git various little goofs in change#4385 p4raw-link: @4385 on //depot/perl: 95136addeff6f7c87c13a96a62f5eaafb9bafdcf p4raw-id: //depot/perl@4386 --- diff --git a/win32/include/dirent.h b/win32/include/dirent.h index d6eb7ea..a669012 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 71a959a..bbf85e6 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;