Mail Archives: cygwin/2009/09/01/21:38:57
-----BEGIN PGP SIGNED MESSAGE-----
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):
http://www.kernel.org/doc/man-pages/online/pages/man3/readdir.3.html
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
strlen(d_name)):
http://lkml.indiana.edu/hypermail/linux/kernel/9506/0033.html
So Linux doesn't provide d_namlen, and coreutils can't optimize for known
lengths on Linux. But BSD does:
http://www.gsp.com/cgi-bin/man.cgi?section=5&topic=dir
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 ebb9 AT byu DOT net
-----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/
iEYEARECAAYFAkqdzKQACgkQ84KuGfSFAYBtsQCgvYcI8Y7CLJOYxPKIySgwCpJn
dvAAoIVO47y0+F24lGktxBAF6gbj0rlh
=Zctr
-----END PGP SIGNATURE-----
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
- Raw text -