Topic: ::getenv() - check! ::setenv() - huh!?
Author: jcoffin@taeus.com (Jerry Coffin)
Date: 1998/11/30 Raw View
In article <Pine.SUN.3.96.981127131656.9008C-100000@caris>,
henry@universal.ca says...
>
> Why is there a getenv but no setenv? I found a platform-specific _putenv()
> in my implementation but why was there no setenv in the standard?
It's almost impossible to say exactly what setenv should do, and most
systems don't support many of the things you'd probably want it to do.
> How is one supposed to write an environment manager!?
What do you want your "environment manager" to do? Most (system-
specific) _setenv() or similar functions only affect what subsequent
calls to getenv in the same process will return.
If you want something similar to that, you can fairly easily write an
environment manager to handle that: implement a class that includes
get and set members (or something similar) to set and retrieve
variables. Store the variables that have been set in a map. When
your get() function is called, it will first look things up in the
map. If that search fails, it will attempt to find the variable using
getenv().
If you want to write something that affects the environments of other
processes, things get very mess (and VERY non-portable) in a hurry.
Most systems simply don't provide any support for doing things like
this -- the environment starts at the top and is inherited downward,
with no provision made for changes in the other direction.
Worse yet, there's no predicting exactly what'll happen when/if you DO
manage to make a change -- for example, many programs read environment
variables when they start up. When you call getenv, it reads an
internal copy of the environment variables rather than reading the
environment directly, so even if you could manage to change the
environment, the program wouldn't notice.
Most of these limitations are based on the original design of UNIX.
More modern and advanced systems provide for such possibilities,
including both methods of changing the global environment and methods
to tell individual processes that it has changed so they should react
appropriately. However, there are enough existing systems that lack
this sort of capability to prevent it from being standardized, at
least at the present time.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: David A Henry <henry@universal.ca>
Date: 1998/11/28 Raw View
Why is there a getenv but no setenv? I found a platform-specific _putenv()
in my implementation but why was there no setenv in the standard? How is
one supposed to write an environment manager!?
Thanks...
David A Henry
dhenry_bigfoot_com
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: brownsta@concentric.net (Stan Brown)
Date: 1998/11/29 Raw View
henry@universal.ca (David A Henry) wrote:
>
>Why is there a getenv but no setenv? I found a platform-specific _putenv()
>in my implementation but why was there no setenv in the standard? How is
>one supposed to write an environment manager!?
Quoting from the Rationale issued with the ANSI C Standard X3.159-1989:
"A corresponding putenv function was omitted from the Standard, since
its utility outside a multi-process environment is questionable, and
since its definition is properly the domain of an operating system
standard."
--
Stan Brown, Oak Road Systems, Cleveland, Ohio, USA
http://www.concentric.net/%7eBrownsta/
"I'm not even supposed to BE here!" -- the mantra from /Clerks/
My reply address is correct as is. The courtesy of providing a correct
reply address is more important to me than time spent deleting spam.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]