Date: Mon, 19 Feb 2001 20:12:11 +0100 From: mouss <usebsd@free.fr> To: Matt Dillon <dillon@earth.backplane.com>, "Andrey Simonenko" <simon@comsys.ntu-kpi.kiev.ua> Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Staticaly allocated buffers in library. Is it correct? Message-ID: <4.3.0.20010219200743.054eae40@pop.free.fr> In-Reply-To: <200102191723.f1JHNII37074@earth.backplane.com> References: <Pine.BSF.4.21.0102171202110.400-100000@scorpion.cosmos.all.net> <96rash$1m1d$1@igloo.uran.net.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi Matt, At 09:23 19/02/01 -0800, Matt Dillon wrote: > Yes. System libraries traditionally use statically allocated buffers > because, even now, there is no dynamic equivalent for fgets(). The > closest you can get is to mmap() the file and extract the lines that > way. > > But as long as the buffer sizes are reasonable and the library uses > fgets() with the proper length limitation, using a statically allocated > buffer is not a big deal. Most configuration files couldn't have long > lines and still be legal anyway. Note that the classical loop while (fgets(buf, n, fp) != NULL) { tokenize(buf, args...); ... } may have problems if the line is too long, so one needs to detect it by looking for the '\n'. if none is found, then one can either abort on error or ignore the line. In the latter case, you need to read the remaining chars so that the next fgets won't get them. regards, mouss To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4.3.0.20010219200743.054eae40>