Odd scandir behaviour; libc.so.5.4.44

Odd scandir behaviour; libc.so.5.4.44

Post by Chris Ranki » Tue, 31 Mar 1998 04:00:00



Hi all,

This isn't amazingly serious, but it did surprise me.

I was using scandir() to browse a directory, and had implemented a
select() function to eliminate everything except regular files (by
calling stat() and then using S_ISREG). For test purposes, I put a
broken soft link in my scanned directory, and stat() correctly returned
an error. The odd part was that this caused scandir() to quit as well,
even though I had rejected this broken file from the selection.

Further study showed that returning from scandir() with errno set to
anything except 0 causes scandir() to fail immediately.

This strikes me as odd - is it intentional? I can't find any
documentation about it.

Cheers,
Chris

 
 
 

Odd scandir behaviour; libc.so.5.4.44

Post by Martin J. Man » Tue, 31 Mar 1998 04:00:00



Quote:> I was using scandir() to browse a directory, and had implemented a
> select() function to eliminate everything except regular files (by
> calling stat() and then using S_ISREG). For test purposes, I put a
> broken soft link in my scanned directory, and stat() correctly returned
> an error. The odd part was that this caused scandir() to quit as well,
> even though I had rejected this broken file from the selection.
> Further study showed that returning from scandir() with errno set to
> anything except 0 causes scandir() to fail immediately.
> This strikes me as odd - is it intentional? I can't find any
> documentation about it.

It looks like an implementation error to me.  From a quick glance, the
code seems to be using errno to save the exit cause for at least
allocation failure, but it just assumes that the selection screening
function doesn't ever set errno.  Looks to me like a bug in scandir.

I was looking at the 5.4.33 source, that being what I had ready to
hand.  There have been some bug-fix releases since that one came out.