fast getline for busybox (proof of concept, untested)

Rich Felker dalias at aerifal.cx
Wed May 31 21:20:43 UTC 2006


On Wed, May 31, 2006 at 04:55:46PM -0400, Rich Felker wrote:
> size_t fgets_embedded_nul(char *s, size_t n, FILE *f)
> {
> 	char *p, *z;
> 	memset(s, 1, n);
> 	if (!fgets(s, n, f)) return 0;
> 	for (p=s; z = memchr(p, 0, n); n -= ++z-p, p=z);
> 	return p-s-1;
> }

I have a much better version of this I'll write up and send later
(tonite?) when I have time. It will eliminate a significant portion of
the performance hit beyond 'normal' fgets.

Rich




More information about the busybox mailing list