environ var in gcc @ solaris 8++ @ intel && sparc

environ var in gcc @ solaris 8++ @ intel && sparc

Post by christian » Thu, 19 Jun 2003 05:25:33



Hi,

does anyone know how to get access to the entire environment of the
current process?
i need a solution for:
- solaris 8 and 9 at intel and sparc
- gcc 2.9x or 3.x

is there a synonym for the "environ" or "__environ" var like it exists
in gcc at linux? or is there no access to the entire environment at
solaris? i know about getenv and putenv but i need to enumerate, copy,
and manipulate the entire environment for a new process started by
execve().

thanks in advance
christian

 
 
 

environ var in gcc @ solaris 8++ @ intel && sparc

Post by Kenny McCorma » Thu, 19 Jun 2003 06:29:02




>Hi,

>does anyone know how to get access to the entire environment of the
>current process?
>i need a solution for:
>- solaris 8 and 9 at intel and sparc
>- gcc 2.9x or 3.x

>is there a synonym for the "environ" or "__environ" var like it exists
>in gcc at linux? or is there no access to the entire environment at
>solaris? i know about getenv and putenv but i need to enumerate, copy,
>and manipulate the entire environment for a new process started by
>execve().

char **environ;

should do the trick.  Have you actually tested this under Solaris?  It
should certainly be standard in any Unix or Unix-like environment (no pun
intended).

Alternatively, you can include a third arg to main, like this:

int main(int argc,char *argv,char *envp) { ...

Note that this last is not defined by the C standard (argc and argv are).
I don't know if it is actually required by SUS or POSIX, but I think it
will work in almost any C environment.

 
 
 

environ var in gcc @ solaris 8++ @ intel && sparc

Post by Kenny McCorma » Thu, 19 Jun 2003 06:30:09






>>Hi,

>>does anyone know how to get access to the entire environment of the
>>current process?
>>i need a solution for:
>>- solaris 8 and 9 at intel and sparc
>>- gcc 2.9x or 3.x

>>is there a synonym for the "environ" or "__environ" var like it exists
>>in gcc at linux? or is there no access to the entire environment at
>>solaris? i know about getenv and putenv but i need to enumerate, copy,
>>and manipulate the entire environment for a new process started by
>>execve().

>char **environ;

>should do the trick.  Have you actually tested this under Solaris?  It
>should certainly be standard in any Unix or Unix-like environment (no pun
>intended).

>Alternatively, you can include a third arg to main, like this:

>int main(int argc,char *argv,char *envp) { ...

Oops, that should, of course, be:

        int main(int argc,char **argv,char **envp) { ...

 
 
 

environ var in gcc @ solaris 8++ @ intel && sparc

Post by Villy Kru » Thu, 19 Jun 2003 23:42:21


On Tue, 17 Jun 2003 21:29:02 GMT,

Quote:

>Alternatively, you can include a third arg to main, like this:

>int main(int argc,char *argv,char *envp) { ...

>Note that this last is not defined by the C standard (argc and argv are).
>I don't know if it is actually required by SUS or POSIX, but I think it
>will work in almost any C environment.  

Appart from Unix or unix like systems can we realy tell?

More seriously, after a sufficient number of putenv() or setenv() calls
the envp from the arguments to main is no longer valid, whereas the
environ global pointer still is.  That is because the array of string
pointers pointed to by envp to begin with is moved if it needs room for
more entries.  The putenv() or getenv() knows how to update environ
but it has no access to the envp parameter.

Also, unless you define _GNU_SOURCE the environ variable isn't declared
in the unistd.h header; only __environ is declared.  This  suggests that
using environ isn't blessed by the standards, even when it has existed
in traditional unix for ages.

Villy

 
 
 

environ var in gcc @ solaris 8++ @ intel && sparc

Post by Mohun Biswa » Fri, 20 Jun 2003 00:12:08



> Also, unless you define _GNU_SOURCE the environ variable isn't declared
> in the unistd.h header; only __environ is declared.  This  suggests that
> using environ isn't blessed by the standards, even when it has existed
> in traditional unix for ages.

Why waste your time reading tea leaves when you could just RTFS? I just
took a look at SUS and it does in fact "bless" environ. If gcc/Linux get
this wrong, that's not a problem with the standard.

MB

 
 
 

environ var in gcc @ solaris 8++ @ intel && sparc

Post by Villy Kru » Fri, 20 Jun 2003 16:50:11


On Wed, 18 Jun 2003 15:12:08 GMT,


>> Also, unless you define _GNU_SOURCE the environ variable isn't declared
>> in the unistd.h header; only __environ is declared.  This  suggests that
>> using environ isn't blessed by the standards, even when it has existed
>> in traditional unix for ages.

>Why waste your time reading tea leaves when you could just RTFS? I just
>took a look at SUS and it does in fact "bless" environ. If gcc/Linux get
>this wrong, that's not a problem with the standard.

If the standards text is not easily available we have to read tealeaves.

Villy

 
 
 

environ var in gcc @ solaris 8++ @ intel && sparc

Post by Mohun Biswa » Fri, 20 Jun 2003 20:18:17



> On Wed, 18 Jun 2003 15:12:08 GMT,


>>>Also, unless you define _GNU_SOURCE the environ variable isn't declared
>>>in the unistd.h header; only __environ is declared.  This  suggests that
>>>using environ isn't blessed by the standards, even when it has existed
>>>in traditional unix for ages.

>>Why waste your time reading tea leaves when you could just RTFS? I just
>>took a look at SUS and it does in fact "bless" environ. If gcc/Linux get
>>this wrong, that's not a problem with the standard.

> If the standards text is not easily available we have to read tealeaves.

http://www.unix.org/version3/

MB

 
 
 

1. environ var in gcc @ solaris 8++ @ intel && sparc

Hi,

does anyone know how to get access to the entire environment of the
current process?
i need a solution for:
- solaris 8 and 9 at intel and sparc
- gcc 2.9x or 3.x

is there a synonym for the "environ" or "__environ" var like it exists
in gcc at linux? or is there no access to the entire environment at
solaris? i know about getenv and putenv but i need to enumerate, copy,
and manipulate the entire environment for a new process started by
execve().

thanks in advance
christian

2. array of structs ?

3. Got Solaris (Both Sparc & Intel) - need C compiler - want GCC

4. compaq smart 2/p raid 5 controller

5. &&&&----Looking for a unix shell------&&&&&

6. Matsushita CR-581 CD-ROM

7. ppp && PPPoE && ADSL && net && buffer(s)

8. Where to put the newsx.conf?

9. Solaris & gcc & libg++ & InterViews ???

10. 没有人用中文吗?

11. solaris 8 & solaris 9 for intel and sparc

12. solaris 8 & solaris 9 for intel e sparc

13. &&&&& WHERE TO GET FREE SOLARIS FOR X86