From owner-freebsd-hackers Mon Feb 19 12:47: 0 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from earth.backplane.com (earth-nat-cw.backplane.com [208.161.114.67]) by hub.freebsd.org (Postfix) with ESMTP id EED8237B65D for ; Mon, 19 Feb 2001 12:46:58 -0800 (PST) Received: (from dillon@localhost) by earth.backplane.com (8.11.2/8.9.3) id f1JKkl738082; Mon, 19 Feb 2001 12:46:47 -0800 (PST) (envelope-from dillon) Date: Mon, 19 Feb 2001 12:46:47 -0800 (PST) From: Matt Dillon Message-Id: <200102192046.f1JKkl738082@earth.backplane.com> To: mouss Cc: "Andrey Simonenko" , freebsd-hackers@FreeBSD.ORG Subject: Re: Staticaly allocated buffers in library. Is it correct? References: <96rash$1m1d$1@igloo.uran.net.ua> <4.3.0.20010219200743.054eae40@pop.free.fr> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG :> 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 Yes, but we are talking about simple stupid config files here. Programs which actually tokenize an input stream typically do not use fgets(). Tokenizers either use [f]lex, [f]getc(), read() (and handle the buffering themselves), or mmap(). -Matt To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message