[PATCH v2 07/13] stdlib: Add internal __getenvarray function

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Wed Oct 30 20:11:12 GMT 2024



On 30/10/24 13:38, Florian Weimer wrote:
> * Adhemerval Zanella Netto:
> 
>>> diff --git a/stdlib/setenv.h b/stdlib/setenv.h
>>> index 3919943f87..69fa9367ed 100644
>>> --- a/stdlib/setenv.h
>>> +++ b/stdlib/setenv.h
>>> @@ -47,6 +47,13 @@ __environ_is_from_array_list (char **ep)
>>>    return eal != NULL && &eal->array[0] == ep;
>>>  }
>>>  
>>> +/* Make a copy of the environ array.  Writes up to LENGTH pointers to
>>> +   *RESULT, including a terminating null pointer if there is room.
>>> +   *Returns the total number of non-null elements in the environ
>>> +   *array.  This number can be larger than LENGTH.  */
> 
> (I see that Emacs has botched the comment formatting.)
> 
>> I am not sure returning a partial copy is really a good interface,
>> specially because it won't be NULL terminated if there is no size.
>> Maybe it would be better to just return -1 if there is no size,
>> even if input array is partially written.
> 
> Then I would have to add a size_t *lengthp argument that receives the
> actual size, otherwise there is no good way for the caller to get it.
> The getgroups function allows a caller to query to the number of groups
> by specifying a zero size, but that does not seem much better.

It is not clear to me why you need to get the length result, are we aiming
to support partial __getenvarray calls (sorry if I haven't read the patch
in full, it might be something later in the patch)?


More information about the Libc-alpha mailing list