Reduce stack size a bit using proper size for buffer; reorder code a bit to

have a simpler error checking.
This commit is contained in:
riccardom 2008-11-15 23:09:46 +00:00
parent b5cd79371b
commit 4a3c15d11a
1 changed files with 9 additions and 13 deletions

View File

@ -37,42 +37,38 @@ void * FsReadFirst(const char * path, FsEntry * entry) {
FsLinuxDir * dir;
struct dirent * e;
struct stat s;
char buffer[1024];
char buffer[512+1]; /* DirSpec[256] + '/' + dirent.d_name[256] */
DIR * tmp;
dir = (FsLinuxDir*)malloc(sizeof(FsLinuxDir));
if (!dir)
return NULL;
tmp = opendir(path);
if (!tmp)
return NULL;
dir->dir = tmp;
e = readdir(tmp);
if (!e) {
closedir(tmp);
return NULL;
}
dir = (FsLinuxDir*)malloc(sizeof(FsLinuxDir));
if (!dir) {
closedir(tmp);
return NULL;
}
dir->dir = tmp;
strcpy(entry->cFileName, e->d_name);
// there's no 8.3 file names support on linux :)
strcpy(entry->cAlternateFileName, "");
entry->flags = 0;
dir->path = strdup(path);
sprintf(buffer, "%s/%s", dir->path, e->d_name);
stat(buffer, &s);
if (S_ISDIR(s.st_mode)) {
entry->flags = FS_IS_DIR;
entry->fileSize = 0;
entry->fileSize = 0;
} else {
entry->fileSize = s.st_size;
}
entry->fileSize = s.st_size;
}
return dir;
}