crystal
crystal copied to clipboard
The file `NUL` does not exist on Windows
On Windows, it is possible to query the null device File::NULL = "NUL"'s info, or open it:
File.info(File::NULL).type # => File::Type::CharacterDevice
File.open("NUL", "r+") do |f|
f.puts "abc" # okay
f.gets # => nil
end
But File.exists?("NUL") returns false. This somewhat contradictory result occurs for all special DOS device names, like COM1, AUX, and CONOUT$. File::Info.readable? and .writable? also have this issue.
The difference between the two is that the former calls CreateFileW whereas the latter calls GetFileAttributesW. Ruby works since File.exist? there returns true if and only if a platform-specific stat call succeeded; on Windows, this stat ultimately calls CreateFileW first.
This affects File.realpath too, as it internally calls Crystal::System::File.exists?. Ideally that should return \\.\NUL, a special path under the Win32 device namespace.