Skip to content

Commit 1e8bdea

Browse files
committed
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 Comcom (and also FreeCOM) can display invalid data, so let's correct that. Since the required constant _A_DEVICE isn't always present in `dos.h`, let's define it when necessary. Before: ~~~ C:\>dir nul Volume in drive c is IR DXXXXS C Directory of c:\ 2025-10-30 16:41 0 NUL 1 file(s) 0 bytes 0 dir(s) 48.7 GB free ~~~ With patch: ~~~ C:\>dir nul Volume in drive c is IR DXXXXS C Directory of c:\ File not found ~~~
1 parent ba4c1b1 commit 1e8bdea

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/command.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
*/
5151

5252
#include <dos.h>
53+
#ifndef _A_DEVICE
54+
#define _A_DEVICE 0x40u
55+
#endif
5356
#include <libc/dosio.h>
5457
#include <io.h>
5558
#include <libc/getdinfo.h>
@@ -2693,7 +2696,8 @@ static void perform_dir(const char *arg)
26932696
}
26942697
if (first)
26952698
{
2696-
if ((ffrc = findfirst_f(full_filespec, &ff, attrib, &ffhandle)) != 0)
2699+
if (((ffrc = findfirst_f(full_filespec, &ff, attrib, &ffhandle)) != 0) ||
2700+
ff.ff_attrib == _A_DEVICE )
26972701
{
26982702
puts("File not found"); // informational message -- not an error
26992703
return;

0 commit comments

Comments
 (0)