[PATCH] Use offsetof instead of magic number in scandir()

Corinna Vinschen vinschen@redhat.com
Thu Mar 28 12:42:00 GMT 2013


On Mar 28 12:44, Sebastian Huber wrote:
> On 03/28/2013 12:17 PM, Corinna Vinschen wrote:
> >Shouldn't we better use the upstream version as used in FreeBSD and
> >OpenBSD?
> >
> >   #define DIRSIZ(dp)                                                      \
> >           ((sizeof(struct dirent) - sizeof(dp)->d_name) +                 \
> >	      (((dp)->d_namlen + 1 + 3) &~ 3))
> 
> I have problems to understand this expression.  What is
> "sizeof(dp)->d_name"? I think this looks like a hand-crafted
> offsetof variant.

sizeof(dp)->d_name is sizeof((dp)->d_name), but without the lexically
unnecessary parens.  I was just thinking that using the upstream
version has the advnatage to use easier comparable code, given that
our scandir.c is the BSD version anyway.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat



More information about the Newlib mailing list