question on opendir, readdir, etc.
Doug Gwyn
gwyn at smoke.brl.mil
Fri Nov 30 07:38:43 AEST 1990
In article <4767 at rossignol.Princeton.EDU> tr at samadams.princeton.edu (Tom Reingold) writes:
>To use opendir, readdir, etc. on BSD, you include <sys/dir.h>. This
>lets you use a struct defined as direct. The member d_name is a
>character array of size MAXNAMLEN+1 (256).
That is obsolete.
>To use these functions on System V, you include <dirent.h>. This lets
>you use a struct defined as dirent. Confusingly close. The member
>d_name is a character array of size 1! Is this for real? I have a
>sample program which works, but I think I'm lucky that trashing the
>area after my structure doesn't kill anything vital.
UNIX System (as of release 3.0) included IEEE Std 1003.1 (POSIX)-
compatible directory access functions and the corresponding header.
The code actually originated with my independent implementation;
Kirk McKusick of UCB had earlier provided an implementation of the
BSD "struct direct" flavor of these functions, which inspired the
POSIX specification. There were good reasons for the slight changes
made by IEEE P1003, which I won't go into here.
>Am I not supposed to use these functions in System V? If I am, do they
>normally work?
Yes, they had BETTER work. The [1] kludge is deliberate, and from
time to time argument rages about whether the C standard requires that
an implementation make it work or whether it could ever fail. I have
yet to hear of any commercial UNIX implementation where it doesn't
work.
You can also obtain my current implementation simply by requesting it
in an e-mail message to me <Gwyn at BRL.MIL>.
More information about the Comp.lang.c
mailing list