From owner-freebsd-hackers Mon Feb 19 11:14: 2 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from smtp.nettoll.com (matrix.nettoll.net [212.155.143.61]) by hub.freebsd.org (Postfix) with ESMTP id B18E437B67D for ; Mon, 19 Feb 2001 11:13:57 -0800 (PST) Received: by smtp.nettoll.com; Mon, 19 Feb 2001 20:10:17 +0100 (MET) Message-Id: <4.3.0.20010219200743.054eae40@pop.free.fr> X-Sender: usebsd@pop.free.fr X-Mailer: QUALCOMM Windows Eudora Version 4.3 Date: Mon, 19 Feb 2001 20:12:11 +0100 To: Matt Dillon , "Andrey Simonenko" From: mouss Subject: Re: Staticaly allocated buffers in library. Is it correct? Cc: freebsd-hackers@FreeBSD.ORG In-Reply-To: <200102191723.f1JHNII37074@earth.backplane.com> References: <96rash$1m1d$1@igloo.uran.net.ua> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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