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 */
37 /* Read the number of blocks */
38 if (!_dirread (dir, &entry.d_blocks, sizeof (entry.d_blocks))) {
42 /* Read the next file entry into the buffer */
43 for (count = 0, b = buffer; count < sizeof (buffer); ++count, ++b) {
44 if (!_dirread1 (dir, b)) {
52 /* End of directory is reached if the buffer contains "blocks free". It is
53 * sufficient here to check for the leading 'b'. To avoid problems if we're
54 * called again, read until end of directory.
56 if (count > 0 && buffer[0] == 'b') {
57 while (_dirread1 (dir, buffer)) ;
61 /* Bump the directory offset */
64 /* Parse the buffer for the filename and file type */
73 /* Searching for start of file name */
80 /* Within file name */
82 entry.d_name[j] = '\0';
85 } else if (j < sizeof (entry.d_name) - 1) {
92 /* Searching for file type */
94 entry.d_type = _cbm_filetype (*b);
96 /* May be DEL or DIR, check next char */
106 /* Distinguish DEL or DIR file type entries */
109 case 'i': entry.d_type = CBM_T_DIR; break;
110 default: entry.d_type = CBM_T_OTHER; break;
118 /* Something went wrong when parsing the directory entry */