Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The file NUL does not exist on Windows #15019

Open
HertzDevil opened this issue Sep 19, 2024 · 0 comments
Open

The file NUL does not exist on Windows #15019

HertzDevil opened this issue Sep 19, 2024 · 0 comments

Comments

@HertzDevil
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

1 participant