From: Tor Arntsen Date: Wed, 25 May 2011 20:37:34 GMT Subject: Re: [PATCH 2/2] Include unistd.h. Message-ID: In-Reply-To: <7vd3j64oq6.fsf@alter.siamese.dyndns.org> On Wed, May 25, 2011 at 20:30, Junio C Hamano wrote: > mduft@gentoo.org writes: > >> At least on Interix, NULL is defined in unistd.h, and not including it >> causes compilation failure. >> >> Signed-off-by: Markus Duft >> --- >>  compat/fnmatch/fnmatch.c |    1 + >>  1 files changed, 1 insertions(+), 0 deletions(-) >> >> diff --git a/compat/fnmatch/fnmatch.c b/compat/fnmatch/fnmatch.c >> index 14feac7..0238cca 100644 >> --- a/compat/fnmatch/fnmatch.c >> +++ b/compat/fnmatch/fnmatch.c >> @@ -25,6 +25,7 @@ >>  # define _GNU_SOURCE 1 >>  #endif >> >> +#include >>  #include >>  #include >>  #include > > The header stddef.h is where NULL is supposed to be defined, and commonly > used headers are supposed to define NULL the same way as stddef.h does. > There is a conditional inclusion of stdlib.h in fnmatch.c and stdlib.h is > one of those files; probably that is how the upstream pulls in NULL when > compiling this. According to POSIX (well, IEEE Std 1003.1, 2004 Edition at least) unistd.h must define NULL: " The following symbolic constant shall be defined: NULL Null pointer " > But we don't define STDC_HEADERS nor _LIBC (and we shouldn't), so I don't > know how the existing users of compat/fnmatch/ gets the defintion of NULL > from. Output from "gcc -E -dD -DNO_FNMATCH compat/fnmatch/fnmatch.c" does > not seem to show any NULL defined. > > Other platforms (e.g. SunOS, IRIX, HPUX, Windows) use NO_FNMATCH_CASEFOLD > and compile this file.  How are they getting their NULLs? IRIX defines NULL in and (the latter via ). Solaris 10 defines NULL in , but also in via Tru64 v5.1 in and and a bunch of other places (string.h, stdio,h, stdlib.h, everywhere) AIX 5.1 in and and just about everywhere. Linux also gets NULL via because it includes , but then stddef.h isn't in /usr/include, at least on my system - presumably it's in some compiler-provided place. For all those non-Linu systems it's always a straight-forward no-dependency #ifndef NULL #define NULL 0 /* or sometimes 0L */ #endif -Tor