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