finding out if a directory is empty in C program (was Re: How do I tell when a directory is empty in a script?)

Dave Decot decot at hpcupt1.cup.hp.com
Tue May 14 04:09:22 AEST 1991


>   Second, stat()ing and checking the link count to find out the number of
> subdirectories is a hack that is not guaranteed to work on every system and
> that is not required to work according to POSIX (at least, I don't think it
> is, although I am interested in being corrected).   Operating Systems that
> don't really put entries for "." and ".." in a directory (e.g. HP-UX, I
> believe) will not have the link counts you're expecting.

This is a true characteristic of POSIX, but HP-UX is not an example
of systems that do not have actual entries for "." and "..".  Only
the HP 9000 Series 500 used a directory format (called SDF) in which
this was not true, and it was obsoleted several years ago.  Even the
s500 would fake the existence of these directories if they appeared in a
path name, but readdir() and ls(1) would never say that they existed.

All modern HP-UX systems have actual entries for "." and ".." .

I agree with the poster that portable code should not assume that
"." and ".." exist everywhere.

Dave Decot



More information about the Comp.unix.questions mailing list