Skip to content

Commit ec6c63f

Browse files
andrewbirdPerditionC
authored andcommitted
DIR: don't display invalid data with devices
When doing `DIR NUL` findfirst will actually return success with an attribute indicating a device exists with that name. MS-DOS shows 'File not found' in this case, but FreeCOM (and also Comcom64) can display invalid data, so let's correct that. Since the required constant FA_DEVICE isn't always present in `dos.h`, let's define it when necessary. [#181] Before (C: is MFS, D: is FAT16): ~~~ C:\>dir nul Volume in drive C is IR DXXXXS C Directory of C:\ NUL 0 10-30-25 6:55p 1 file(s) 0 bytes 0 dir(s) 49,839 Mega bytes free C:\>d: D:\>dir nul Volume in drive D has no label Volume Serial Number is 4A09-DBB4 Directory of D:\ NUL 0 10-30-25 6:55p 1 file(s) 0 bytes 0 dir(s) 42,698,752 bytes free ~~~ With patch (C: is MFS, D: is FAT16): ~~~ C:\>dir nul Volume in drive C is IR DXXXXS C Directory of C:\ File not found. C:\>d: D:\>dir nul Volume in drive D has no label Volume Serial Number is 4A09-DBB4 Directory of D:\ File not found. ~~~
1 parent 29b197f commit ec6c63f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cmd/dir.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@
156156
#include <conio.h>
157157
#include <ctype.h>
158158
#include <dos.h>
159+
#ifndef FA_DEVICE
160+
#define FA_DEVICE 0x0040u
161+
#endif
159162
#include <io.h>
160163
#include <fcntl.h>
161164
#include <stdio.h>
@@ -1106,7 +1109,7 @@ static int dir_list(int pathlen
11061109

11071110
if (cbreak)
11081111
rv = E_CBreak;
1109-
else if(rv == E_None) {
1112+
else if (rv == E_None && file.ff_attrib != FA_DEVICE) {
11101113
if(file.ff_attrib & FA_DIREC) {
11111114
dircount++;
11121115
} else {

0 commit comments

Comments
 (0)