X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_SOFTFAIL X-Spam-Check-By: sourceware.org Message-ID: <4A9DCCA4.9070808@byu.net> Date: Tue, 01 Sep 2009 19:38:44 -0600 From: Eric Blake User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: struct dirent.d_reclen References: <20090901233750 DOT GA32145 AT ednor DOT casa DOT cgf DOT cx> <4A9DC5FC DOT 2070202 AT byu DOT net> In-Reply-To: <4A9DC5FC.2070202@byu.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com -----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