On 27 July 2010 18:03, Bernhard Reutner-Fischer <[email protected]> wrote: > 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)) {
Of course, but this way you have to have PROCPS_BUFSIZE in (at least) two different places, which is not generally nice. Regards, -- Alex _______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
