Re: struct dirent in Linux 2.0

Ulrich Windl (ulrich.windl@rz.uni-regensburg.de)
Tue, 18 Feb 1997 08:21:45 +0100


On 17 Feb 97 at 9:58, Snow Cat wrote:

> Ulrich Windl once wrote:
> >
> > Hello,
> >
> > I've found the following definition for struct dirent members:
> >
> > char d_name[MAXNAMLEN+1]; /* name of directory entry */
> > ino_t d_ino; /* file serial number */
> > short d_namlen; /* length of string in d_name */
> > short d_reclen; /* length of this record */
> >
> > Unfortunately Linux currently defines just
> >
> > long d_ino;
> > __kernel_off_t d_off;
> > unsigned short d_reclen;
> > char d_name[256]; /* We must not include limits.h! */
> >
> > I don't have the POSIX specs, but the first one claims to be POSIX. Can
> > Linux have a d_namlen, too?
> >
>
> I asked this before and it was pointed out to me that d_name is '\0'
> terminated so strlen(d->d_name) works on Linux and other platforms just as
> well.

Interestingly the HP-UX documentation I examined did not state
whether the d_name is specified to be zero-terminated, but one
example suggested that you could use strcmp(). I myself would have
used d_namlen and memcmp(). At least it's completely wrong to use
d_reclen as substitute for d_namlen.

Ulrich