This is the mail archive of the
mailing list for the Cygwin project.
Re: struct dirent.d_reclen
-----BEGIN PGP SIGNED MESSAGE-----
According to Eric Blake on 9/1/2009 7:10 PM:
> According to Christopher Faylor on 9/1/2009 5:37 PM:
>> Maybe you mean d_namlen?
> Yes; serves me right for confusing readdir(2) and readdir(3) man pages.
Actually, it looks like Linux has only d_reclen (and that d_namlen is a
and that Linus prefers d_reclen over d_namlen from the kernel side of
things (where, in the Linux kernel, d_reclen is always aligned, such that
adjusting d_reclen by offsetof(struct dirent,d_name) can be larger than
So Linux doesn't provide d_namlen, and coreutils can't optimize for known
lengths on Linux. But BSD does:
At any rate, coreutils uses a macro _D_EXACT_NAMELEN(dirent), which
evaluates to either d_namlen, a calculation on d_reclen (if d_reclen is
accurate enough*), or a call to strlen() if all else fails; so that it is
portable to whichever the underlying semantics happen to be.
* If d_reclen minimally rounds up to an aligned size, for example if it is
only at most 8 bytes larger than strlen(d_name), then it is still faster
to do a strchr(,0)-d_name from a starting point 8 bytes before where
d_reclen says the record ends, rather than strlen(d_name).
Don't work too hard, make some time for fun as well!
Eric Blake firstname.lastname@example.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
-----END PGP SIGNATURE-----
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple