Fixed bug #11214 (patch by Steph Fox)

This commit is contained in:
Edin Kadribasic 2002-07-29 13:12:57 +00:00
parent 8f94a8a744
commit 0737394d80
2 changed files with 14 additions and 12 deletions

View file

@ -113,29 +113,31 @@ int closedir(DIR *dp)
return 0; return 0;
} }
void rewinddir(DIR *dir_Info) int rewinddir(DIR *dp)
{ {
/* Re-set to the beginning */ /* Re-set to the beginning */
char *filespec; char *filespec;
long handle; long handle;
int index; int index;
dir_Info->handle = 0; _findclose(dp->handle);
dir_Info->offset = 0;
dir_Info->finished = 0;
filespec = malloc(strlen(dir_Info->dir) + 2 + 1); dp->offset = 0;
strcpy(filespec, dir_Info->dir); dp->finished = 0;
filespec = malloc(strlen(dp->dir) + 2 + 1);
strcpy(filespec, dp->dir);
index = strlen(filespec) - 1; index = strlen(filespec) - 1;
if (index >= 0 && (filespec[index] == '/' || filespec[index] == '\\')) if (index >= 0 && (filespec[index] == '/' || filespec[index] == '\\'))
filespec[index] = '\0'; filespec[index] = '\0';
strcat(filespec, "/*"); strcat(filespec, "/*");
if ((handle = _findfirst(filespec, &(dir_Info->fileinfo))) < 0) { if ((handle = _findfirst(filespec, &(dp->fileinfo))) < 0) {
if (errno == ENOENT) { if (errno == ENOENT)
dir_Info->finished = 1; dp->finished = 1;
} }
} dp->handle = handle;
dir_Info->handle = handle;
free(filespec); free(filespec);
return 0;
} }

View file

@ -38,7 +38,7 @@ DIR *opendir(const char *);
struct dirent *readdir(DIR *); struct dirent *readdir(DIR *);
int readdir_r(DIR *, struct dirent *, struct dirent **); int readdir_r(DIR *, struct dirent *, struct dirent **);
int closedir(DIR *); int closedir(DIR *);
void rewinddir(DIR *); int rewinddir(DIR *);
#endif /* READDIR_H */ #endif /* READDIR_H */