LIBBB: parse_config()

Denys Vlasenko vda.linux at googlemail.com
Tue Jul 8 03:56:49 UTC 2008


On Tuesday 08 July 2008 05:47, Denys Vlasenko wrote:
> [CC: busybox at busybox.net]
> 
> On Monday 07 July 2008 21:31, dronnikov at gmail.com wrote:
> > Please, comment and consider applying.

Another comment: the return value should be NULL
if file can't be opened; should contain at least one
element (NULL) if file was opened but no tokens
are found; else as usual.

Trimming it at the end with xrealloc to not take
space after terminating NULL might be not a bad idea too.
BTW... that data[] needs this even worse - config files tend
to have largish comments. Move stuff "to the left" in the data
as you parse it? a-la

dst = data;

...
...
*dst++ = *data++;
    and
dst = stpcpy(dst, data);

and then xrealloc it at the end. Much less of memory usage.

Ah crap, xrealloc can move it then... the trick may be
to store in token[] _indexes_ into data, not pointers,
and convert them to pointers after final shrinking xrealloc(data).
--
vda



More information about the busybox mailing list