git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] Include unistd.h.

From
TATor Arntsen <tor@spacetec.no>
Date
May 25, 2011, 20:37 UTC
Message-ID
<BANLkTim4gPAyA9vLnpBz7qRY+b4RQ7LwNw@mail.gmail.com>
In-Reply-To
<7vd3j64oq6.fsf@alter.siamese.dyndns.org>
On Wed, May 25, 2011 at 20:30, Junio C Hamano <gitster@pobox.com> wrote:
Show 28 quoted lines
> 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 <mduft@gentoo.org>
>> ---
>>  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 <unistd.h>
>>  #include <errno.h>
>>  #include <fnmatch.h>
>>  #include <ctype.h>
>
> 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
"
Show 7 quoted lines
> 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 <unistd.h> and <stddef.h> (the latter via <internal/stddef_core.h>). Solaris 10 defines NULL in <unistd.h>, but also in <stddef.h> via <iso/stddef_iso.h> Tru64 v5.1 in <unistd.h> and <stddef.h> and a bunch of other places (string.h, stdio,h, stdlib.h, everywhere) AIX 5.1 in <unistd.h> and <stddef.h> and just about everywhere. Linux also gets NULL via <unistd.h> because it includes <stddef.h>, 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
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 18 in “Interix catch-ups for recent changes/releases.”
  1. Interix catch-ups for recent changes/releases.mduft@gentoo.org, May 25, 2011
  2. 1/2 Add additional build options for Interix, and remove obsolete ones.mduft@gentoo.org, May 25, 2011
  3. Junio C HamanoMay 25, 2011
  4. Markus DuftMay 26, 2011
  5. Junio C HamanoMay 26, 2011
  6. 2/2 Include unistd.h.mduft@gentoo.org, May 25, 2011
  7. Junio C HamanoMay 25, 2011
  8. Tor ArntsenMay 25, 2011
  9. Junio C HamanoMay 25, 2011
  10. Erik Faye-LundMay 25, 2011
  11. Jonathan NiederMay 26, 2011
  12. Junio C HamanoMay 26, 2011
  13. Jonathan NiederMay 26, 2011
  14. Markus DuftMay 30, 2011
  15. Markus DuftJun 15, 2011
  16. Jonathan NiederJun 15, 2011
  17. Update the Interix default build configuration.mduft@gentoo.org, Jun 15, 2011
  18. Markus DuftMay 27, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.