When Does Readdir Failure?

When Does Readdir Failure?

Since readdir() returns NULL when it detects an error and when the end of the directory is encountered, an application that needs to tell the difference must set errno to zero before the call and check it if NULL is returned.

Is Readdir multithread safe?

In the GNU C Library, it is safe to call readdir from multiple threads as long as each thread uses its own DIR object. POSIX. 1-2008 does not require this to be safe, but we are not aware of any operating systems where it does not work.

What does Readdir return?

The readdir() function returns a pointer to a structure representing the directory entry at the current position in the directory stream specified by the argument dirp, and positions the directory stream at the next entry. It returns a null pointer upon reaching the end of the directory stream.

Marcus Vance
Author

Marcus Vance

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.