1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-14 00:32:08 +00:00

Replaced static array with realloc'ed memory block - like done in enumdevdir.c.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5870 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
ol.sc 2012-10-23 19:24:27 +00:00
parent 6e829979d4
commit 658b765bfe

View File

@ -12,6 +12,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <dirent.h> #include <dirent.h>
#include <stdlib.h>
#include <em.h> #include <em.h>
#include <conio.h> #include <conio.h>
@ -42,10 +43,6 @@ struct {
*/ */
#define MAX_EM_OVERLAY 3 #define MAX_EM_OVERLAY 3
/* Search for up to 10 extended memory drivers.
*/
#define MAX_EM_DRIVER 10
/* Functions resident in an overlay can call back functions resident in the /* Functions resident in an overlay can call back functions resident in the
@ -101,9 +98,9 @@ void foobar (void)
unsigned char loademdriver (void) unsigned char loademdriver (void)
{ {
static char emd[MAX_EM_DRIVER][FILENAME_MAX];
DIR *dir; DIR *dir;
struct dirent *ent; struct dirent *ent;
char *emd = NULL;
unsigned char max = 0; unsigned char max = 0;
unsigned char num; unsigned char num;
@ -128,22 +125,26 @@ unsigned char loademdriver (void)
} }
printf ("Dbg: Memorizing file %s\n", ent->d_name); printf ("Dbg: Memorizing file %s\n", ent->d_name);
strcpy (emd[max], ent->d_name); emd = realloc (emd, FILENAME_MAX * (max + 1));
if (++max == MAX_EM_DRIVER) { strcpy (emd + FILENAME_MAX * max++, ent->d_name);
break;
}
} }
closedir (dir); closedir (dir);
for (num = 0; num < max; ++num) { for (num = 0; num < max; ++num) {
printf ("Dbg: Trying emdriver %s\n", emd[num]); char *drv;
if (em_load_driver (emd[num]) == EM_ERR_OK) {
printf ("Dbg: Loaded emdriver %s\n", emd[num]); drv = emd + FILENAME_MAX * num;
printf ("Dbg: Trying emdriver %s\n", drv);
if (em_load_driver (drv) == EM_ERR_OK) {
printf ("Dbg: Loaded emdriver %s\n", drv);
free (emd);
return 1; return 1;
} }
printf ("Dbg: Emdriver %s failed\n", emd[num]); printf ("Dbg: Emdriver %s failed\n", drv);
} }
free (emd);
return 0; return 0;
} }