According to the control page (OS X) read (2), read (2) generates an error if "[a] n an attempt was made to read the directory". Therefore, you can open the (2) directory (make sure prot does not allow writing, otherwise it will cause an error), and then try to read it. This is similar to the only error listed there that could occur in βnormalβ circumstances (i.e., not to do something like intentionally violating the FILE * structure).
I assume you are talking about reading errors (2) in C or something like that, but even in a higher level language, you can open the directory and try to read it (although I just tried it with Python and it is too smart so you can open the directory ...)
source share