[1/9] posix: Sync glob with gnulib [BZ #1062]
Commit Message
Adhemerval Zanella wrote:
> +/* Any distinct values will do here.
> + Undef any existing macros out of the way. */
> +#ifndef DT_UNKNOWN
> +# define DT_UNKNOWN 0
> +#endif
> +#ifndef DT_DIR
> +# define DT_DIR 1
> +#endif
> +#ifndef DT_LNK
> +# define DT_LNK 2
> +#endif
The comment here does not match the code, as nothing is being undeffed. Instead
of this change, how about the following?
#if !defined _LIBC && !defined HAVE_STRUCT_DIRENT_D_TYPE
/* Any distinct values will do here.
Undef any existing macros out of the way. */
# undef DT_UNKNOWN
# undef DT_DIR
# undef DT_LNK
# define DT_UNKNOWN 0
# define DT_DIR 1
# define DT_LNK 2
#endif
This makes it more clear to the casual reader that this code is for use only
outside glibc. Also, it's more robust for hopefully only-hypothetical non-glibc
platforms that define some DT_ symbols but not others, because it guarantees
their uniqueness in that case. I installed the attached patch into Gnulib, along
these lines.
Comments
On 05/09/2017 23:01, Paul Eggert wrote:
> Adhemerval Zanella wrote:
>> +/* Any distinct values will do here.
>> + Undef any existing macros out of the way. */
>> +#ifndef DT_UNKNOWN
>> +# define DT_UNKNOWN 0
>> +#endif
>> +#ifndef DT_DIR
>> +# define DT_DIR 1
>> +#endif
>> +#ifndef DT_LNK
>> +# define DT_LNK 2
>> +#endif
>
> The comment here does not match the code, as nothing is being undeffed. Instead of this change, how about the following?
Indeed, I forgot to update the comments after the fix.
> #if !defined _LIBC && !defined HAVE_STRUCT_DIRENT_D_TYPE
> /* Any distinct values will do here.
> Undef any existing macros out of the way. */
> # undef DT_UNKNOWN
> # undef DT_DIR
> # undef DT_LNK
> # define DT_UNKNOWN 0
> # define DT_DIR 1
> # define DT_LNK 2
> #endif
>
> This makes it more clear to the casual reader that this code is for use only outside glibc. Also, it's more robust for hopefully only-hypothetical non-glibc platforms that define some DT_ symbols but not others, because it guarantees their uniqueness in that case. I installed the attached patch into Gnulib, along these lines.
I do not have a strong preference here, I am ok with your approach and I will
update my patch with this change. In fact I would prefer that all this
boilerplate that is non required for glibc code to be on a specific header
(maybe glob-gnulib.h or something), but we can think about it later.
From e73addd2704d4eb68b126210f5b41b428d5d4956 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Tue, 5 Sep 2017 18:58:50 -0700
Subject: [PATCH] glob: fix for use in glibc
Problem reported by Adhemerval Zanella in:
https://sourceware.org/ml/libc-alpha/2017-09/msg00213.html
* lib/glob.c (DT_UNKNOWN, DT_DIR, DT_LINK):
Do not redefine if _LIBC.
---
ChangeLog | 8 ++++++++
lib/glob.c | 2 +-
2 files changed, 9 insertions(+), 1 deletion(-)
@@ -1,3 +1,11 @@
+2017-09-05 Paul Eggert <eggert@cs.ucla.edu>
+
+ glob: fix for use in glibc
+ Problem reported by Adhemerval Zanella in:
+ https://sourceware.org/ml/libc-alpha/2017-09/msg00213.html
+ * lib/glob.c (DT_UNKNOWN, DT_DIR, DT_LINK):
+ Do not redefine if _LIBC.
+
2017-09-02 Paul Eggert <eggert@cs.ucla.edu>
glob: fix bugs with long login names
@@ -80,7 +80,7 @@ static const char *next_brace_sub (const char *begin, int flags) __THROWNL;
typedef uint_fast8_t dirent_type;
-#ifndef HAVE_STRUCT_DIRENT_D_TYPE
+#if !defined _LIBC && !defined HAVE_STRUCT_DIRENT_D_TYPE
/* Any distinct values will do here.
Undef any existing macros out of the way. */
# undef DT_UNKNOWN
--
2.7.4