Re: struct dirent in Linux 2.0

Swen Thuemmler (swen@uni-paderborn.de)
Tue, 18 Feb 1997 16:58:09 +0100 (MET)


On Tue, 18 Feb 1997, Ulrich Windl wrote:

> > The first is definitely not POSIX. *All* POSIX specifies about struct
> > dirent is that it contain d_name.
>
> At least they should specify the zero-termination property of
> d_name, too. Despite of that the HP-UX manual page on dirent(5)
> claims that the above structure conforms to AES, SVID2, SVID3, XPG2,
> XPG3, XPG4, FIPS 151-2, POSIX.1 -- Now what about Linux?

Well, my copy of POSIX.1 (1003.1 from 1988) says:

"The readdir() function returns a pointer to an object of type struct
dirent that includes the member:
Member Type Member Name Description
----------- ----------- -----------
char[] d_name Null-terminated filename
The character array d_name is of unspecified size, but the number of bytes
preceding the terminating null character shall not exceed {NAME_MAX}."

So it explicitely states, that d_name is zero-terminated. It mentions no
other members of the dirent structure, so any other member is nonstandard
(but not explicitly forbidden, you may use it, but then your program does
not conform to POSIX.1, I think).

Greetings, Swen