2 * Ullrich von Bassewitz, 2012-05-30. Based on code by Groepaz.
16 struct dirent* __fastcall__ readdir (register DIR* dir)
18 register unsigned char* b;
19 register unsigned char i;
20 register unsigned char count;
23 unsigned char buffer[0x40];
24 static struct dirent entry;
27 /* Remember the directory offset for this entry */
28 entry.d_off = dir->off;
30 /* Skip the basic line-link */
31 if (!_dirread (dir, buffer, 2)) {
32 /* errno already set */
36 /* Read the number of blocks */
37 if (!_dirread (dir, &entry.d_blocks, sizeof (entry.d_blocks))) {
41 /* Adjust the directory offset */
44 /* Read the next file entry into the buffer */
45 for (count = 0, b = buffer; count < sizeof (buffer); ++b) {
46 if (!_dirread1 (dir, b)) {
55 /* Bump the directory offset */
58 /* End of directory is reached if the buffer contains "blocks free". It is
59 * sufficient here to check for the leading 'b'. buffer will contain at
60 * least one byte if we come here.
62 if (buffer[0] == 'b') {
66 /* Parse the buffer for the filename and file type */
75 /* Searching for start of file name */
82 /* Within file name */
84 entry.d_name[j] = '\0';
87 } else if (j < sizeof (entry.d_name) - 1) {
94 /* Searching for file type */
96 entry.d_type = _cbm_filetype (*b);
98 /* May be DEL or DIR, check next char */
108 /* Distinguish DEL or DIR file type entries */
111 case 'i': entry.d_type = CBM_T_DIR; break;
112 default: entry.d_type = CBM_T_OTHER; break;
120 /* Something went wrong when parsing the directory entry */