Skip to content

Conversation

@andrewbird
Copy link
Member

So this trims a trailing colon from file names that may be a device, BUT I don't like that if you pass it a name + : that isn't a device it has the potential to overwrite some other file.

e.g.

echo longstring > nul:  # does what we want
echo astring > c:      # same behaviour as now
echo anotherstring > cx:  # creates or overwrites a file called 'cx'

Short of doing 'is_device_name()' on the filename, I don't know how to make this safe?

@stsp
Copy link
Member

stsp commented Jan 18, 2026

Just a quick suggestion
to weight in: you can try
findfirst_f() on it, then
looking at ff.ff_attrib == _A_DEVICE -
see perform_dir() as
an example.

@andrewbird
Copy link
Member Author

I looked at find first as you suggested, but didn't see how I could 'find' a device without it existing on the filesystem. I admit I didn't actually try it so it might have worked just fine.

I ended up just trying to open it readonly and if successful I could use https://fd.lod.bz/rbil/interrup/dos_kernel/214400.html#2860 to determine if it was a device or not.

I'll need to test thoroughly...

@stsp
Copy link
Member

stsp commented Jan 19, 2026

But how perform_dir() works?
I was hoping that all devices
pretend to "exist" on mfs level.

@andrewbird
Copy link
Member Author

But how perform_dir() works?

Yes, I'll modify to use findfirst(). I think what put me off was the thought that it was scanning a directory looking for a match, but if the target is explicit perhaps it does something special.

Also I just checked what MS-DOS 6.22 (& OPENDOS 7.01) does with echo longstring > cx:, it creates a file called 'cx'. This is nasty, I'm torn now between what we have now (creating an LFN called cx:), what I'd like (throwing some error) or adopting that behaviour (create SFN called cx)?

FreeCOM does this

Can not redirect output to file 'cx:'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants