[PATCH] introduce CONFIG_BUFFER_SIZE()

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Tue Jul 27 15:03:53 UTC 2010


On Tue, Jul 27, 2010 at 05:55:13PM +0300, Alexander Shishkin wrote:
>On Tue, Jul 27, 2010 at 04:52:16 +0200, Bernhard Reutner-Fischer wrote:
>> On Tue, Jul 27, 2010 at 05:21:58PM +0300, Alexander Shishkin wrote:
>> >Since "sizeof buffer" won't work with dynamically allocated buffers,
>> >and we still sometimes need to know the size of the whole buffer, we
>> >need a way to always obtain said size.
>> 
>> I don't quite understand?
>> You have these three:
>> char b1[PROCPS_BUFSIZE]
>> char b2[FILENAME_MAX]
>> char b3[BUFSIZ]
>> you
>> RESERVE_CONFIG_BUFFER(b1, PROCPS_BUFSIZE)
>> RESERVE_CONFIG_BUFFER(b2, FILENAME_MAX)
>> RESERVE_CONFIG_BUFFER(b3, BUFSIZ)
>> and
>> RELEASE_CONFIG_BUFFER(b1)
>> accordingly.
>> 
>> Where do you need "sizeof(PROCPS_BUFSIZE)" as opposed to
>> "PROCPS_BUFSIZE", for example?
>
>No, you might need sizeof(b1), as in
>
>    fgets(b1, sizeof b1, ...)
>
>for example.

you had
char buf[PROCPS_BUFSIZE];
while (fgets(buf, sizeof buf , file)) {
(i'd strongly recommend to use sizeof(), always, just as a sidenote)
just say
RESERVE_CONFIG_BUFFER(buf, PROCPS_BUFSIZE)
while (fgets(buf, PROCPS_BUFSIZE , file)) {

see?


More information about the busybox mailing list