Eric Blake wrote: > --- a/lib/unistd.in.h > +++ b/lib/unistd.in.h > @@ -33,10 +33,17 @@ > #include <stddef.h> > > /* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */ > -#if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) > +/* Cygwin 1.7.1 declares symlinkat in <stdio.h>, not in <unistd.h>. */ > +#if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \ > + || @GNULIB_SYMLINKAT@) > # include <stdio.h> > #endif > > +/* Cygwin 1.7.1 declares unlinkat in <fcntl.h>, not in <unistd.h>. */ > +#if @GNULIB_UNLINKAT@ > +# include <fcntl.h> > +#endif
Hmm, I'm not so happy to see additional headers being included, even on glibc systems. This "namespace pollution" has the effect that a developer will, for example, write code that does #include <unistd.h> ... { printf (...); } and get no error because <unistd.h> happens to drag in <stdio.h>. It's not possible to avoid all possible #include on all platforms - gnulib provides them precisely because they are necessary on some platforms -, but for glibc systems, where most developers write and test their programs, I can make an extra effort to exclude unnecessary headers. In fact, one example of such a mistake is already present in lib/fcntl.c. Applying this: 2009-12-24 Bruno Haible <br...@clisp.org> Reduce namespace pollution on glibc systems. * lib/inttypes.in.h: Don't include <stdint.h> on glibc systems. * lib/stdlib.in.h: Don't include <stdint.h>, <unistd.h> on glibc systems. * lib/unistd.in.h: Don't include <stdio.h>, <fcntl.h>, <stdlib.h>, <getopt.h> on glibc systems. * lib/fcntl.in.h: Don't include <sys/stat.h>, <unistd.h> on glibc systems. * lib/fcntl.c: Include <unistd.h> here instead. --- lib/inttypes.in.h.orig Thu Dec 24 16:57:08 2009 +++ lib/inttypes.in.h Thu Dec 24 16:54:49 2009 @@ -36,8 +36,11 @@ #if ! defined INTTYPES_H && ! defined _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H #define INTTYPES_H -/* Include <stdint.h> or the gnulib replacement. */ -#include <stdint.h> +/* Include <stdint.h> or the gnulib replacement. + But avoid namespace pollution on glibc systems. */ +#ifndef __GLIBC__ +# include <stdint.h> +#endif /* Get CHAR_BIT. */ #include <limits.h> --- lib/stdlib.in.h.orig Thu Dec 24 16:57:09 2009 +++ lib/stdlib.in.h Thu Dec 24 16:55:51 2009 @@ -49,8 +49,8 @@ # include <random.h> #endif -#if (@GNULIB_RANDOM_R@ || !...@have_struct_random_data@ \ - || defined GNULIB_POSIXCHECK) +#if !...@have_struct_random_data@ || (@GNULIB_RANDOM_R@ && !...@have_random_r@) \ + || defined GNULIB_POSIXCHECK # include <stdint.h> #endif @@ -67,9 +67,10 @@ }; #endif -#if @GNULIB_MKSTEMP@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK +#if (@GNULIB_MKSTEMP@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ /* On MacOS X 10.3, only <unistd.h> declares mkstemp. */ /* On Cygwin 1.7.1, only <unistd.h> declares getsubopt. */ +/* But avoid namespace pollution on glibc systems. */ # include <unistd.h> #endif --- lib/unistd.in.h.orig Thu Dec 24 16:57:09 2009 +++ lib/unistd.in.h Thu Dec 24 16:56:52 2009 @@ -34,20 +34,26 @@ /* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */ /* Cygwin 1.7.1 declares symlinkat in <stdio.h>, not in <unistd.h>. */ +/* But avoid namespace pollution on glibc systems. */ #if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \ - || @GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK) + || (@GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK)) \ + && ! defined __GLIBC__ # include <stdio.h> #endif /* Cygwin 1.7.1 declares unlinkat in <fcntl.h>, not in <unistd.h>. */ -#if @GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK +/* But avoid namespace pollution on glibc systems. */ +#if (@GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ # include <fcntl.h> #endif /* mingw fails to declare _exit in <unistd.h>. */ /* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>. */ /* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>. */ -#include <stdlib.h> +/* But avoid namespace pollution on glibc systems. */ +#ifndef __GLIBC__ +# include <stdlib.h> +#endif /* mingw declares getcwd in <io.h>, not in <unistd.h>. */ #if ((@GNULIB_GETCWD@ || defined GNULIB_POSIXCHECK) \ @@ -63,8 +69,9 @@ # include <sys/types.h> #endif -/* Get getopt(), optarg, optind, opterr, optopt. */ -#if @GNULIB_UNISTD_H_GETOPT@ && !defined _GL_SYSTEM_GETOPT +/* Get getopt(), optarg, optind, opterr, optopt. + But avoid namespace pollution on glibc systems. */ +#if @GNULIB_UNISTD_H_GETOPT@ && !defined __GLIBC__ && !defined _GL_SYSTEM_GETOPT # include <getopt.h> #endif --- lib/fcntl.in.h.orig Thu Dec 24 16:57:08 2009 +++ lib/fcntl.in.h Thu Dec 24 16:54:17 2009 @@ -25,8 +25,10 @@ /* Special invocation convention. */ #include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> +#ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */ +# include <sys/stat.h> +# include <unistd.h> +#endif #...@include_next@ @NEXT_FCNTL_H@ #else @@ -35,8 +37,10 @@ #ifndef _GL_FCNTL_H #include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> +#ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */ +# include <sys/stat.h> +# include <unistd.h> +#endif /* The include_next requires a split double-inclusion guard. */ #...@include_next@ @NEXT_FCNTL_H@ --- lib/fcntl.c.orig Thu Dec 24 16:57:08 2009 +++ lib/fcntl.c Thu Dec 24 16:43:30 2009 @@ -25,6 +25,7 @@ #include <errno.h> #include <limits.h> #include <stdarg.h> +#include <unistd.h> #if !HAVE_FCNTL # define rpl_fcntl fcntl