Mail Archives: djgpp/2001/05/14/08:02:11
On Mon, 14 May 2001, Waldemar Schultz wrote:
> Eli Zaretskii schrieb:
> >
> > On Mon, 14 May 2001, Waldemar Schultz wrote:
> >
> > > Thanks, and is there also a possibility of obtaining the
> > > available free space in environ (allocated size of environ)?
> >
> > I'm not sure what are you asking, exactly. There's space that is
> > allocate for `environ', which is an array of pointers, and there's
> > additional space allocated for each "VAR=VALUE" string. Which one of
> > these are you interested in?
>
> In simple words: can I write a (DOS) C-program that tells me
> how much environment space is free/occupied ?
Sorry, I still don't follow ;-)
First, the size of environ[] array is dynamically changed as needed,
since a program can use putenv or setenv to insert additional variables.
Second, each of the elements of the environ[] array is a pointer to
malloc'ed string "VAR=VALUE", and each string has a different size, which
is also dynamically allocated and reallocated if the program modifies the
environment. (For example, if you change the value of PATH, its string
might grow or shrink as appropriate.)
See the source of the putenv library function for the gory details.
Given this, what meaning can you assign to ``how much of the environment
space is free/occupied''? About the only meaningful answer would be to
count the number of free (i.e. NULL) elements in the environ[] array,
with a loop similar to what I posted. But this result can change as soon
as you call putenv, and it hardly says anything about the total storage
used by environment variables themselves.
- Raw text -