[comp.lang.c] Putenv

borzieri@KING.ICO.OLIVETTI.COM (Ivan Borzieri) (02/15/91)

Hi,

I URGENTLY need this information :

I wrote two c modules called by a fortran main.
in the first  c module I call the system function "putenv()" which should
set a variable in the environment.
In the second  c module I call the system function "getenv()" to read 
the value of the previous set variable.
The value returned by getenv() is NULL, id est, that variable
doesn't exist.

Now my question is : is this right ?
I know that in C-Shell scripts, when you set variables you loose them
as you exit the script.
Is it the same or this is a operating system bug ?

The system is SCO Unix System V 3.2

							Thanks,
							Ivan Borzieri

mcdonald@aries.scs.uiuc.edu (Doug McDonald) (02/15/91)

In article <50361@olivea.atc.olivetti.com> borzieri@KING.ICO.OLIVETTI.COM (Ivan Borzieri) writes:
>Hi,
>
>I URGENTLY need this information :
>
>I wrote two c modules called by a fortran main.
>in the first  c module I call the system function "putenv()" which should
>set a variable in the environment.
>In the second  c module I call the system function "getenv()" to read 
>the value of the previous set variable.
>The value returned by getenv() is NULL, id est, that variable
>doesn't exist.
>
>Now my question is : is this right ?
>I know that in C-Shell scripts, when you set variables you loose them
>as you exit the script.
>Is it the same or this is a operating system bug ?
>
>The system is SCO Unix System V 3.2
>


I would have used e-mail, but this is getting my hackles up:

This is a system-specific question. It has nothing to do with C or Fortran per 
se: It should be posted in an SCO Unix specific newsgroup, or at least
a Unix specific newsgroup. Not a general one like comp.lang.c.

I am not the slightest bit interested in Unix specific questions.

Other people have posted the same sort of requests.

Doug McDonald

mike (02/17/91)

In an article, aries.scs.uiuc.edu!mcdonald (Doug McDonald) writes:

[ in response to a question on putenv() and getenv() ]

>This is a system-specific question. It has nothing to do with C or Fortran per 
>se: It should be posted in an SCO Unix specific newsgroup, or at least
>a Unix specific newsgroup. Not a general one like comp.lang.c.

I don't believe that this is as system-specific as you would would like to
believe.  I have not yet encountered a C library that didn't include these
two _subroutines_ regardless of operating system.  Note that they are _not_
operating system calls, but rather simple routines that search and insert from
a list.  If your library doesn't have 'em, I would consider it broken.

-- 
Michael Stefanik, MGI Inc., Los Angeles| Opinions stated are not even my own.
Title of the week: Systems Engineer    | UUCP: ...!uunet!bria!mike
-------------------------------------------------------------------------------
Remember folks: If you can't flame MS-DOS, then what _can_ you flame?

mcdonald@aries.scs.uiuc.edu (Doug McDonald) (02/17/91)

In article <448@bria>  writes:
>In an article, aries.scs.uiuc.edu!mcdonald (Doug McDonald) writes:
>
>[ in response to a question on putenv() and getenv() ]
>
>>This is a system-specific question. It has nothing to do with C or Fortran per 
>>se: It should be posted in an SCO Unix specific newsgroup, or at least
>>a Unix specific newsgroup. Not a general one like comp.lang.c.
>
>I don't believe that this is as system-specific as you would would like to
>believe.  I have not yet encountered a C library that didn't include these
>two _subroutines_ regardless of operating system.  Note that they are _not_
>operating system calls, but rather simple routines that search and insert from
>a list.  If your library doesn't have 'em, I would consider it broken.
>
>-- 
>Michael Stefanik, MGI Inc., Los Angeles| Opinions stated are not even my own.



Yep, the system has to have getenv or its broken (or its a free-standing
implementation :-). But apparently NOT putenv. In fact, as best as I can tell,
"putenv" is on the list of functions a conforming C compiler CANNOT have!!


But anything they DO is "implememtation dependent", and should be discussed
in the appropriate implementation-dependent place. The only possible
portable thing "getenv" can do is return NULL.

Doug McDonald

gwyn@smoke.brl.mil (Doug Gwyn) (02/18/91)

In article <1991Feb17.014354.1677@ux1.cso.uiuc.edu> mcdonald@aries.scs.uiuc.edu (Doug McDonald) writes:
>"putenv" is on the list of functions a conforming C compiler CANNOT have!!

Wrong.

datangua@watmath.waterloo.edu (David Tanguay) (02/18/91)

In article <448@bria> uunet!bria!mike writes:
|[ in response to a question on putenv() and getenv() ]
|I don't believe that this is as system-specific as you would would like to
|believe.  I have not yet encountered a C library that didn't include these
|two _subroutines_ regardless of operating system.

The you've led a sheltered life :-)
I've seen several compilers without putenv on operating systems that don't
have environments. Both are easy to nop out, but any program that uses
putenv probably needs the proper semantics; getenv is more often used
to override program defaults.
-- 
David Tanguay            Software Development Group, University of Waterloo