This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: struct dirent.d_reclen

Hash: SHA1

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
documentation bug):

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[0]).

- --
Don't work too hard, make some time for fun as well!

Eric Blake   
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at
Comment: Using GnuPG with Mozilla -


Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]