[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: environ

From: Eric Blake
Subject: Re: environ
Date: Mon, 16 May 2011 16:15:35 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.10

On 05/16/2011 04:04 PM, Sam Steingold wrote:
> does importing the environ module mean that I can remove this:
> extern_C char** environ;
> #endif
> from my sources and assume that environ is properly declared in unistd?

Well, POSIX doesn't require <unistd.h> to declare environ; but since it
is a common glibc extension when _GNU_SOURCE is defined, yes, our
<unistd.h> replacement header guarantees it.

> also, how can I come up with the answer to this question myself without
> bothering you?

The preferred method is by reading the documentation:

From doc/posix-functions/environ.texi:

Gnulib module: environ

Portability problems fixed by Gnulib:
POSIX does not require this variable to be declared, and it is indeed not
declared on some platforms:
MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, IRIX 6.5, Solaris 11

Or you can look in lib/unistd.in.h.  Note that there is a section:

# if address@hidden@
/* Set of environment variables and values.  An array of strings of the form
   "VARIABLE=VALUE", terminated with a NULL.  */
#  if defined __APPLE__ && defined __MACH__
#   include <crt_externs.h>
#   define environ (*_NSGetEnviron ())
#  else
#   ifdef __cplusplus
extern "C" {
#   endif
extern char **environ;

that is; if you are using the gnulib environ module, then there will be
a declaration for environ in the replacement header (either by including
other headers, or by direct declaration).

Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]