comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: Reading environment variables in ADA?
Date: 1998/10/07
Date: 1998-10-07T00:00:00+00:00	[thread overview]
Message-ID: <EACHUS.98Oct7154628@spectre.mitre.org> (raw)
In-Reply-To: 6vfgvo$ja0$1@nnrp1.dejanews.com

In article <6vfgvo$ja0$1@nnrp1.dejanews.com> dewarr@my-dejanews.com writes:

  > I find this a specious argument, it would equally well apply to constants
  > at the global level which you allowed C to modify, and there is no way of
  > generating inefficient code to allow this to "work" whatever that means.

  > A constant is a constant, it cannot be modified after declaration
  > time. If you have your C code modify it that is morally equivalent
  > to having C destroy your Ada generated code by poking at it. This
  > is just plain junk buggy code, and it is absurd to generate
  > deliberately suboptimal code so that this particularly bug can be
  > got away with!

   Agreed, it is absurd, but it is also, unfortunately, practical
advice, especially in the case of environment variables. (See the
man page from SunOS atttached.) I don't like creating storage leaks,
but the Ada version of putenv I use explicitly allocates heap space
and forgets about it after the return.  Much easier than finding the
insidious bugs caused when it is called with a stack or constant
value.

SYNOPSIS
     int putenv(string)
     char *string;

DESCRIPTION
     string points to a string of the form `name=value'  putenv()
     makes  the  value  of the environment variable name equal to
     value by altering an existing variable  or  creating  a  new
     one.   In  either  case,  the  string  pointed  to by string
     becomes part of the environment, so altering the string will
     change  the  environment.   The  space  used by string is no
     longer used once a new string-defining  name  is  passed  to
     putenv().

SEE ALSO
     execve(2V), getenv(3V), malloc(3V), environ(5V).

DIAGNOSTICS
     putenv() returns non-zero if it was unable to obtain  enough
     space  using  malloc(3V) for an expanded environment, other-
     wise zero.

WARNINGS
     putenv() manipulates the environment pointed to by  environ,
     and can be used in conjunction with getenv().  However, envp
     (the third argument to main) is not changed.

     This routine uses malloc(3V) to enlarge the environment.

     After putenv() is called, environmental variables are not in
     alphabetical order.

     A potential error is to  call  putenv()  with  an  automatic
     variable  as  the  argument,  then exit the calling function
     while string is still part of the environment.
--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




  reply	other threads:[~1998-10-07  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-09-12  0:00 Reading environment variables in ADA? Stefan Lingdell
1998-09-12  0:00 ` David C. Hoos, Sr
1998-09-13  0:00 ` Steven Hovater
1998-09-17  0:00 ` Gisle S{lensminde
1998-10-06  0:00   ` Matthew Heaney
1998-10-06  0:00     ` dewarr
1998-10-06  0:00       ` Robert I. Eachus
1998-10-07  0:00         ` dewarr
1998-10-07  0:00           ` Robert I. Eachus [this message]
1998-10-13  0:00             ` Simon Wright
1998-09-17  0:00 ` Matthew Heaney
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox