tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

glob(3) GLOB_ERR and ENOTDIR

What's the point of glob(3), when called with GLOB_ERR, to fail with ENOTDIR 
in case it stumbles over an entry that's not a directory?  E.g., glob(3)'ing 
/etc/*/network will try /etc/passwd/network and fail.  I would expect 
/etc/passwd/net* to fail, but not /etc/*/network.

It looks like glibc behaves more than I would have expected, so there may be 
many programs out there (I hit this when porting Icinga2) that expect a 
different behaviour.

Of course, it's relatively easy to circumvent the problem by passing an 
error handler to glob() that ignores ENOTDIR.

While NetBSD's behaviour is explicitly documented in glob(3), POSIX says
``If, during the search, a directory is encountered that cannot be opened or
read''. /etc/passwd is not a directory, so there's no directory encountered 
that cannot be opened or read.

Also, NetBSD's implentations looks highly inefficient to me. If you ktrace 
the glob(3)'ing of /etc/*/network you see lstat()'s on /etc/foo/network for
every regular file /etc/foo, which strikes me as nonsense.

But perhaps there's some point in the behaviour I don't see.

Home | Main Index | Thread Index | Old Index