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;
/* errno already set */
goto exitpoint;
}
- dir->off += 2;
/* Read the number of blocks */
if (!_dirread (dir, &entry.d_blocks, sizeof (entry.d_blocks))) {
}
/* Read the next file entry into the buffer */
- for (count = 0, b = buffer; count < sizeof (buffer); ++count, ++b) {
+ for (count = 0, b = buffer; count < sizeof (buffer); ++b) {
if (!_dirread1 (dir, b)) {
goto exitpoint;
}
+ ++count;
if (*b == '\0') {
break;
}
}
+ /* Bump the directory offset and include the bytes for line-link and size */
+ dir->off += count + 4;
+
/* End of directory is reached if the buffer contains "blocks free". It is
- * sufficient here to check for the leading 'b'. To avoid problems if we're
- * called again, read until end of directory.
+ * sufficient here to check for the leading 'b'. buffer will contain at
+ * least one byte if we come here.
*/
- if (count > 0 && buffer[0] == 'b') {
- while (_dirread1 (dir, buffer)) ;
- return 0;
+ if (buffer[0] == 'b') {
+ goto exitpoint;
}
- /* Bump the directory offset */
- dir->off += count;
-
/* Parse the buffer for the filename and file type */
i = 0;
j = 0;
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 > 2) {
+ /* 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;
/* 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;
}