Hacker News new | ask | show | jobs
by marcosdumay 290 days ago
> Of course, this is meaningless, as you can't actually do any common operation, except maybe Close*, on all of them.

You can write and read on anything on Unix that "is a file". You can't open or close all of them.

Annoyingly, files come in 2 flavors, and you are supposed to optimize your reads and writes differently.

2 comments

You can call write() and read() on any file descriptor, but it won't necessarily do something meaningful. For example, calling them on a socket in listen mode won't do anything meaningful. And many special files don't implement at least one of read or write - for example, reading or writing to many of the special files in /proc/fs doesn't do anything.
You can try to read/write the same on Windows: ReadFile (and friends) take a HANDLE.

It won't make sense to try to read from all things you can get a HANDLE to on Windows either, but it's up to what created the HANDLE/object as to what operations are valid.

https://learn.microsoft.com/en-us/windows/win32/sysinfo/kern...