[patch] sed replace bb_get_chunk_from_file

Rich Felker dalias at aerifal.cx
Wed May 17 17:49:08 UTC 2006


On Wed, May 17, 2006 at 06:20:33PM +0200, walter harms wrote:
> 
> 
> Rich Felker wrote:
> >On Wed, May 17, 2006 at 10:07:42AM +0200, walter harms wrote:
> >>hi list,
> >>this patch replaces bb_get_chunk_from_file() with getline() that is part 
> >>of glibc. I did some simple tests and found no problems.
> >
> >It's part of glibc!! Not standard. Please make this conditional on a
> >configured option. Also see the patch I sent a while back that fixes
> >the massive slowness in this function by using fgets, which is
> >portable.
> >
> The pont of use getline() is that it can handle any line lenght.
> fgets() needs an already allocated buffer.
> or are your talking about bb_get_chunk_from_file() ?

bb_get_chunk_from_file can be implemented with fgets, reallocating and
repeating if the original buffer is too short. This is much faster
than the current implementation.

> I agree that getline() is GNU only, it would be helpfull if we can agree 
> that we use gnu extension and provide an replacement that can be linked
> anytime if such beast is missing.

I'm not sure whether it's better to do this, or to have an option to
select whether bb_get_chunk_from_file is implemented with getline() or
the more portable way. If you always make the call as "getline()" then
there's the implication that semantics should be identical to GNU
getline, even if BB only cares about (and implements) a subset of
these semantics. IMO that's confusing to developers and to people
reading the code, and may lead to bugs. Calling the function as
bb_get_chunk_from_file and using getline if it's available would avoid
this problem.

Rich




More information about the busybox mailing list