1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-23 04:30:10 +00:00

Adjusted according to the recently updated readdir() doc that now says:

"On several platforms, namely the CBMs and the Atari, the disk drives get confused when opening/closing files between directory reads. So for example a program that reads the list of files on a disk, and after each call to readdir, opens the file to process it, will fail.
Possible solutions are reading the directory into memory before processing the file list, or to reset the directory by seeking to the correct position after opening/closing a file:
        seekdir (DIR, telldir (DIR));
Platforms known to work without problems are: Apple."

git-svn-id: svn://svn.cc65.org/cc65/trunk@5832 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
ol.sc 2012-09-30 14:58:31 +00:00
parent 8a5430d138
commit 2ee45968c4

View File

@ -42,6 +42,11 @@ 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
* main program at any time without any precautions. The function log() is * main program at any time without any precautions. The function log() is
@ -96,8 +101,11 @@ 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;
unsigned char max = 0;
unsigned char num;
printf ("Dbg: Searching for emdrivers\n"); printf ("Dbg: Searching for emdrivers\n");
dir = opendir ("."); dir = opendir (".");
@ -119,17 +127,24 @@ unsigned char loademdriver (void)
continue; continue;
} }
printf ("Dbg: Trying emdriver %s\n", ent->d_name); printf ("Dbg: Memorizing file %s\n", ent->d_name);
if (em_load_driver (ent->d_name) == EM_ERR_OK) { strcpy (emd[max], ent->d_name);
printf ("Dbg: Loaded emdriver %s\n", ent->d_name); if (++max == MAX_EM_DRIVER) {
break; break;
} }
printf ("Dbg: Emdriver %s failed\n", ent->d_name);
} }
closedir (dir); closedir (dir);
return ent != NULL;
for (num = 0; num < max; ++num) {
printf ("Dbg: Trying emdriver %s\n", emd[num]);
if (em_load_driver (emd[num]) == EM_ERR_OK) {
printf ("Dbg: Loaded emdriver %s\n", emd[num]);
return 1;
}
printf ("Dbg: Emdriver %s failed\n", emd[num]);
}
return 0;
} }
void copyoverlays (void) void copyoverlays (void)