]> git.sur5r.net Git - cc65/commitdiff
Include the CBM disk label in the returned directory entries.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 30 Jul 2012 19:01:45 +0000 (19:01 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 30 Jul 2012 19:01:45 +0000 (19:01 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@5797 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/cbm/opendir.c
libsrc/cbm/readdir.c

index c89b3893f22b3ef8aa1f4ded96829cdd85426037..cee28791f8206405e42d32c53b5512d239c80604 100644 (file)
@@ -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));
index e93c88137bd4633406201a8c55a6c88b1f23380c..8661b4e431c819a2760a7037a951dfa6b26cc05e 100644 (file)
@@ -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;
         }