Date: Mon, 19 Feb 2001 12:46:47 -0800 (PST) From: Matt Dillon <dillon@earth.backplane.com> To: mouss <usebsd@free.fr> Cc: "Andrey Simonenko" <simon@comsys.ntu-kpi.kiev.ua>, freebsd-hackers@FreeBSD.ORG Subject: Re: Staticaly allocated buffers in library. Is it correct? Message-ID: <200102192046.f1JKkl738082@earth.backplane.com> References: <Pine.BSF.4.21.0102171202110.400-100000@scorpion.cosmos.all.net> <96rash$1m1d$1@igloo.uran.net.ua> <4.3.0.20010219200743.054eae40@pop.free.fr>
next in thread | previous in thread | raw e-mail | index | archive | help
:> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200102192046.f1JKkl738082>