From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ed86965848f8610b X-Google-Attributes: gid103376,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: Reading environment variables in ADA? Date: 1998/10/07 Message-ID: #1/1 X-Deja-AN: 398736215 References: <6tdl75$qs6$2@nyheter.chalmers.se> <6vdgvv$2h3$1@nnrp1.dejanews.com> <6vfgvo$ja0$1@nnrp1.dejanews.com> Organization: The Mitre Corp., Bedford, MA. Newsgroups: comp.lang.ada Date: 1998-10-07T00:00:00+00:00 List-Id: 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...