I was looking at an example in K&R 2 (8.6 Example - Listing Directories). It is a stripped down version of Linux command ls
or Windows\' dir
. T
In fact Linux dosn't allow read
for directories. See man page and search for errno EISDIR. You will find
The read() and pread() functions shall fail if ...
The fildes argument refers to a directory and the implementation does not allow the directory to be read using read() or pread(). The readdir() function should be used instead.
. Other UNIXes allow it nevertheless.