This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] glob: Avoid copying the d_name field of struct dirent [BZ #19779]
- From: Paul Eggert <eggert at cs dot ucla dot edu>
- To: Florian Weimer <fweimer at redhat dot com>, Roland McGrath <roland at hack dot frob dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Wed, 30 Mar 2016 16:58:45 -0700
- Subject: Re: [PATCH] glob: Avoid copying the d_name field of struct dirent [BZ #19779]
- Authentication-results: sourceware.org; auth=none
- References: <56E339A7 dot 7060704 at redhat dot com> <20160311222757 dot DB90C2C3C24 at topped-with-meat dot com> <56FBBA94 dot 1040605 at redhat dot com>
> +# if defined _DIRENT_HAVE_D_TYPE || defined HAVE_STRUCT_DIRENT_D_TYPE
> + __typeof__ (((struct dirent) {}).d_type) type;
> +# endif
__typeof__ isn't portable to non-GCC compilers. How about if we just
declare d_type to be 'unsigned char'? That should be portable enough in
practice.
> +# if defined _DIRENT_HAVE_D_TYPE || defined HAVE_STRUCT_DIRENT_D_TYPE
> +/* Designated initializer based on the d_type member of struct
> + dirent. */
> +# define D_TYPE_TO_RESULT(source) .type = (source)->d_type
Gnulib still ports to C89, which makes compound literals dicey. We've
been thinking of upping that to C99 so this is not an insurmountable
obstacle (so long as the code sticks to C99-compatible compound
literals, which I think it does). Still, this macro and its relatives
are a bit tricky, and if we're going to use tricky macros anyway perhaps
we'd be better off having them expand to C89 as that shouldn't make
things much more obscure.
> +/* True if the directory entry D might be a symbolic link. */
> +static inline bool
In Gnulib we typically prefer to say just 'static' without the clutter
of 'inline', for the same reason we typically don't bother with the
clutter of 'register'.
> +# define GL_READDIR(pglob, stream) (pglob)->gl_readdir ((stream))
No need for double parenthesization.