reading directory under SYSTEM V

Guy Harris guy at sun.uucp
Fri Sep 5 02:17:57 AEST 1986

> Cound anybody suggest a method of reading directory information from a C
> program under SYSTEM V UNIX? I need something equivalent to the opendir and 
> readdir functionality supplied under BSD.

This is a UNIX question, not a C question (adding the phrase "from a C
program" does not magically transform a question about UNIX into a question
about C), so I'm moving discussion to "net.unix".

The opendir/readdir/etc. code was originally written for the V7 file system,
as used by 4.1BSD (for which it was originally written) and S5.  The V7 file
system version was posted to the net by Kirk McKusick a while ago (I mailed
a copy to the person who asked the question originally).

Unfortunately, the file that is included by most 4.2 programs that defines
the data structures used by the directory library is <sys/dir.h>, which is
aready used to define the native directory structure on systems with the V7
file system.  This means you can't conveniently drop the new "dir.h" include
file into such a system and avoid the need for #ifdefs when building a
program for systems with the V7 and with the 4.2BSD file system.

The IEEE 1003.1 standard has a slightly modified version of the directory
library routines.  They include <dirent.h>, which is not part of V7, 4BSD,
S3, or S5 prior to S5R3, so it can be dropped into such a system (I hope
nobody else has added a different include file with the same name).  S5R3
provides a 1003.1-compatible version of the directory library.  The only
other difference between the two versions of the directory library is that
the original one calls the directory entry structure "struct direct", which
collides with the "struct direct" specifying the format of directories on
disk, as specified in <sys/dir.h>, while the new one calls it "struct
dirent" to avoid this collision.  Systems using the 4.2BSD file system need
merely provide a <dirent.h> that specifies a "struct dirent" identical to a
"struct direct" in order to provide a 1003.1-compatible version of the
directory library routines.
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at (or guy at

More information about the Comp.lang.c mailing list