followup to nifty function
Jonathan Walther
djw@reactor-core.org
Mon, 11 Sep 2000 20:09:51 -0700 (PDT)
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.
--0-2022591370-968728191=:8486
Content-Type: TEXT/PLAIN; charset=US-ASCII
Fixed a memory leak in the usage of realloc().
Does anyone else see this as useful, or do you have better ways of parsing
non seekable streams such as stdin, sockets, pipes, fifos, and many
denizens of /dev ?
Jonathan
--0-2022591370-968728191=:8486
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="function-pointer.c"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.BSO.4.21.0009112009510.8486@reactor-core.org>
Content-Description: read_until.c
Content-Disposition: attachment; filename="function-pointer.c"
I2luY2x1ZGUgPHN0ZGlvLmg+DQojaW5jbHVkZSA8c3RkbGliLmg+DQoNCnR5
cGVkZWYgc3RydWN0IHsNCgljaGFyICAgICAgICAgICAqZGF0YTsNCglpbnQg
ICAgICAgICAgICAgbGVuOw0KfSAgICAgICAgICAgICAgIHJlYWRfdW50aWxf
dDsNCg0KZW51bSB7DQoJQ09OVElOVUUsIEVSUk9SLCBET05FDQp9Ow0KDQpy
ZWFkX3VudGlsX3QgICAqcmVhZF91bnRpbChpbnQsIGNoYXIgKiwgc2l6ZV90
LCBpbnQgKCopIChjaGFyICosIGludCkpOw0KDQovKg0KICogVGhlIHZhcmlh
YmxlICJzdGFjayIgYW5kIGluZm9ybWF0aW9uIGFib3V0IGl0cyBzaXplIHNv
bHZlIHRoZSBsb29rYWhlYWQNCiAqIHByb2JsZW0uICBJZiB5b3VyIGNvbmRp
dGlvbigpIGZ1bmN0aW9uIHJlcXVpcmVzIGNoYXJhY3RlcnMgdG8ga25vdyB3
aGVuIHRvDQogKiB0ZXJtaW5hdGUgdGhhdCB5b3UgY2FuJ3QgcHJvY2VzcyBu
b3csIGJ1dCB3YW50IHRvIHByb2Nlc3MgYXQgYSBsYXRlciBkYXRlLA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