Dynamically allocate number of files in list.
This commit is contained in:
parent
fd56b75a6a
commit
4128868692
|
@ -48,8 +48,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#define MAX_DESCRIPTION_LENGTH 512
|
||||
#define MAX_FILENAME_LENGTH 1024
|
||||
|
||||
#define MAX_LISTED_FILES 64
|
||||
|
||||
#define NUM_TEXTURE_BUCKETS 32
|
||||
|
||||
#define MAX_STARS 500
|
||||
|
|
|
@ -95,28 +95,38 @@ char *getFileLocation(char *filename)
|
|||
char **getFileList(char *dir, int *count)
|
||||
{
|
||||
DIR *d;
|
||||
struct dirent *ent;
|
||||
int i;
|
||||
struct dirent *ent;
|
||||
char **filenames;
|
||||
|
||||
filenames = malloc(sizeof(char*) * MAX_LISTED_FILES);
|
||||
memset(filenames, 0, sizeof(char*) * MAX_LISTED_FILES);
|
||||
|
||||
i = 0;
|
||||
|
||||
if ((d = opendir(dir)) != NULL)
|
||||
{
|
||||
while ((ent = readdir(d)) != NULL)
|
||||
{
|
||||
if (ent->d_name[0] != '.')
|
||||
{
|
||||
filenames[i] = malloc(sizeof(char) * MAX_FILENAME_LENGTH);
|
||||
|
||||
STRNCPY(filenames[i], ent->d_name, MAX_FILENAME_LENGTH);
|
||||
|
||||
if (++i >= MAX_LISTED_FILES)
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
filenames = malloc(sizeof(char*) * i);
|
||||
memset(filenames, 0, sizeof(char*) * i);
|
||||
|
||||
rewinddir(d);
|
||||
|
||||
i = 0;
|
||||
|
||||
while ((ent = readdir(d)) != NULL)
|
||||
{
|
||||
if (ent->d_name[0] != '.')
|
||||
{
|
||||
break;
|
||||
filenames[i] = malloc(sizeof(char) * MAX_FILENAME_LENGTH);
|
||||
|
||||
STRNCPY(filenames[i], ent->d_name, MAX_FILENAME_LENGTH);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue