bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] areadlink-with-size: guess a buffer size with 0 size


From: Pádraig Brady
Subject: [PATCH] areadlink-with-size: guess a buffer size with 0 size
Date: Sat, 6 Jul 2019 20:10:59 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 06/07/19 00:53, Paul Eggert wrote:
> Pádraig Brady wrote:
>> It would be nice to have areadlink_with_size treat 0 as auto select some 
>> lower bound.
> 
> Yes, that sounds good. However, I didn't see why that would entail changing 
> SYMLINK_MAX from 1024 to 1023, or why the patch would affect the documented 
> API.
> 
> How about the attached patch instead? When the guessed size is zero it 
> typically 
> avoids a realloc by using a small stack buffer.

Your patch has the advantage of allocating the exact right sized buffer
in the usual case, but the disadvantage of CPU overhead in string length 
determination,
and some extra code complexity in the separate small buffer handling.

Given Bruno's interim patch of shrinking to the exact sized buffer,
I've push the attached simpler patch that uses a starting buffer
of size 128 (suggested by Andreas), when SIZE==0 is specified.

cheers,
Pádraig

Attachment: areadlink-zero-size.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]