From 470a4abcf25633d2efda0e2e6a40edf7e29746e0 Mon Sep 17 00:00:00 2001 From: uz Date: Mon, 30 Jul 2012 19:01:45 +0000 Subject: [PATCH] Include the CBM disk label in the returned directory entries. git-svn-id: svn://svn.cc65.org/cc65/trunk@5797 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/cbm/opendir.c | 4 ++-- libsrc/cbm/readdir.c | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/libsrc/cbm/opendir.c b/libsrc/cbm/opendir.c index c89b3893f..cee28791f 100644 --- a/libsrc/cbm/opendir.c +++ b/libsrc/cbm/opendir.c @@ -13,7 +13,7 @@ DIR* __fastcall__ opendir (register const char* name) { - unsigned char buf[32]; + unsigned char buf[2]; DIR* dir = 0; DIR d; @@ -39,7 +39,7 @@ DIR* __fastcall__ opendir (register const char* name) if (d.fd >= 0) { /* Skip the disk header */ - if (_dirread (&d, buf, 32)) { + if (_dirread (&d, buf, sizeof (buf))) { /* Allocate memory for the DIR structure returned */ dir = malloc (sizeof (*dir)); diff --git a/libsrc/cbm/readdir.c b/libsrc/cbm/readdir.c index e93c88137..8661b4e43 100644 --- a/libsrc/cbm/readdir.c +++ b/libsrc/cbm/readdir.c @@ -18,8 +18,8 @@ struct dirent* __fastcall__ readdir (register DIR* dir) register unsigned char* b; register unsigned char i; register unsigned char count; - unsigned char s; - unsigned char j; + static unsigned char s; + static unsigned char j; unsigned char buffer[0x40]; static struct dirent entry; @@ -78,9 +78,17 @@ struct dirent* __fastcall__ readdir (register DIR* dir) case 1: /* Within file name */ if (*b == '"') { + /* End of file name found. */ entry.d_name[j] = '\0'; entry.d_namlen = j; - s = 2; + if (entry.d_off != 0) { + /* Proceed with file type */ + s = 2; + } else { + /* This is a disk header, so we're done */ + entry.d_type = _CBM_T_HEADER; + return &entry; + } } else if (j < sizeof (entry.d_name) - 1) { entry.d_name[j] = *b; ++j; @@ -105,8 +113,8 @@ struct dirent* __fastcall__ readdir (register DIR* dir) /* Distinguish DEL or DIR file type entries */ switch (*b) { case 'e': break; - case 'i': entry.d_type = CBM_T_DIR; break; - default: entry.d_type = CBM_T_OTHER; break; + case 'i': entry.d_type = _CBM_T_DIR; break; + default: entry.d_type = _CBM_T_OTHER; break; } return &entry; } -- 2.39.5