Skip to content

Commit cdb1fdf

Browse files
committed
Don't use Fattrib() for listing files and folders
file_exists() could return true in case of a folder on TOS4/FreeMiNT and path_exists() would fail on finding a folder on TOS 1.x-3.x and EmuTOS. Hopefully this fixes freemint/qed#8 for good.
1 parent 2ac3e85 commit cdb1fdf

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

fexists.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@ int file_exists(char *filename)
3232
{
3333
if (filename[0] == '\0')
3434
return FALSE;
35-
return Fattrib(filename, 0, 0) >= 0;
35+
/* include read-only, hidden, system and files with archive-bit
36+
* (exclude volume labels and directories)
37+
*/
38+
return Fsfirst(filename, FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_CHANGED) == 0;
3639
}

fsexists.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
int path_exists(char *pathname)
3535
{
3636
int r = FALSE;
37-
short attr;
3837

3938
if (pathname[0] != '\0')
4039
{
@@ -44,7 +43,8 @@ int path_exists(char *pathname)
4443
if (trailing_backslash)
4544
pathname[len-1] = '\0';
4645

47-
if ((attr = Fattrib(pathname, 0, 0)) >= 0 && (attr & FA_DIR) != 0)
46+
if (Fsfirst(pathname, FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_DIR|FA_CHANGED) == 0
47+
&& ((Fgetdta())->dta_attribute & FA_DIR) != 0)
4848
r = TRUE;
4949

5050
if (trailing_backslash)

0 commit comments

Comments
 (0)