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_DESCRIPTION_LENGTH 512
|
||||||
#define MAX_FILENAME_LENGTH 1024
|
#define MAX_FILENAME_LENGTH 1024
|
||||||
|
|
||||||
#define MAX_LISTED_FILES 64
|
|
||||||
|
|
||||||
#define NUM_TEXTURE_BUCKETS 32
|
#define NUM_TEXTURE_BUCKETS 32
|
||||||
|
|
||||||
#define MAX_STARS 500
|
#define MAX_STARS 500
|
||||||
|
|
|
@ -95,17 +95,29 @@ char *getFileLocation(char *filename)
|
||||||
char **getFileList(char *dir, int *count)
|
char **getFileList(char *dir, int *count)
|
||||||
{
|
{
|
||||||
DIR *d;
|
DIR *d;
|
||||||
struct dirent *ent;
|
|
||||||
int i;
|
int i;
|
||||||
|
struct dirent *ent;
|
||||||
char **filenames;
|
char **filenames;
|
||||||
|
|
||||||
filenames = malloc(sizeof(char*) * MAX_LISTED_FILES);
|
|
||||||
memset(filenames, 0, sizeof(char*) * MAX_LISTED_FILES);
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
|
|
||||||
if ((d = opendir(dir)) != NULL)
|
if ((d = opendir(dir)) != NULL)
|
||||||
{
|
{
|
||||||
|
while ((ent = readdir(d)) != NULL)
|
||||||
|
{
|
||||||
|
if (ent->d_name[0] != '.')
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i > 0)
|
||||||
|
{
|
||||||
|
filenames = malloc(sizeof(char*) * i);
|
||||||
|
memset(filenames, 0, sizeof(char*) * i);
|
||||||
|
|
||||||
|
rewinddir(d);
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
|
||||||
while ((ent = readdir(d)) != NULL)
|
while ((ent = readdir(d)) != NULL)
|
||||||
{
|
{
|
||||||
if (ent->d_name[0] != '.')
|
if (ent->d_name[0] != '.')
|
||||||
|
@ -114,9 +126,7 @@ char **getFileList(char *dir, int *count)
|
||||||
|
|
||||||
STRNCPY(filenames[i], ent->d_name, MAX_FILENAME_LENGTH);
|
STRNCPY(filenames[i], ent->d_name, MAX_FILENAME_LENGTH);
|
||||||
|
|
||||||
if (++i >= MAX_LISTED_FILES)
|
i++;
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue