This is the mail archive of the newlib@sourceware.org mailing list for the newlib 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: [PATCH] Use offsetof instead of magic number in scandir()


On Mar 28 11:58, Sebastian Huber wrote:
> newlib/ChangeLog
> 2013-03-28  Sebastian Huber <sebastian.huber@embedded-brains.de>
> 
> 	* libc/posix/scandir.c (DIRSIZ): Use offsetof instead of magic
> 	number.
> ---
>  newlib/libc/posix/scandir.c |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/newlib/libc/posix/scandir.c b/newlib/libc/posix/scandir.c
> index 96a66de..8cb8ff8 100644
> --- a/newlib/libc/posix/scandir.c
> +++ b/newlib/libc/posix/scandir.c
> @@ -42,6 +42,7 @@ static char sccsid[] = "@(#)scandir.c	5.10 (Berkeley) 2/23/91";
>  
>  #include <sys/types.h>
>  #include <sys/stat.h>
> +#include <stddef.h>
>  #include <dirent.h>
>  #include <stdlib.h>
>  #include <string.h>
> @@ -56,10 +57,10 @@ static char sccsid[] = "@(#)scandir.c	5.10 (Berkeley) 2/23/91";
>  #undef DIRSIZ
>  #ifdef _DIRENT_HAVE_D_NAMLEN
>  #define DIRSIZ(dp) \
> -    ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
> +    (offsetof (struct dirent, d_name) + (((dp)->d_namlen+1 + 3) &~ 3))
>  #else
>  #define DIRSIZ(dp) \
> -    ((sizeof (struct dirent) - (MAXNAMLEN+1)) + ((strlen((dp)->d_name)+1 + 3) &~ 3))
> +    (offsetof (struct dirent, d_name) + ((strlen((dp)->d_name)+1 + 3) &~ 3))
>  #endif

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))

It just needs an additional !_DIRENT_HAVE_D_NAMLEN case.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat


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