From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/1537 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Priorities for next release? Date: Sat, 11 Aug 2012 17:22:58 -0400 Message-ID: <20120811212258.GN27715@brightrain.aerifal.cx> References: <20120810191254.GA13232@brightrain.aerifal.cx> <20120811195649.GK27715@brightrain.aerifal.cx> <20120811205128.GL27715@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="tNQTSEo8WG/FKZ8E" X-Trace: dough.gmane.org 1344720142 2448 80.91.229.3 (11 Aug 2012 21:22:22 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 11 Aug 2012 21:22:22 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-1538-gllmg-musl=m.gmane.org@lists.openwall.com Sat Aug 11 23:22:22 2012 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1T0J8M-0001FN-69 for gllmg-musl@plane.gmane.org; Sat, 11 Aug 2012 23:22:10 +0200 Original-Received: (qmail 22248 invoked by uid 550); 11 Aug 2012 21:22:09 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 22240 invoked from network); 11 Aug 2012 21:22:09 -0000 Content-Disposition: inline In-Reply-To: <20120811205128.GL27715@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:1537 Archived-At: --tNQTSEo8WG/FKZ8E Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Aug 11, 2012 at 04:51:28PM -0400, Rich Felker wrote: > > I'm sending fgetln.c (+my diff), but please check it... > > btw. it based on /usr.bin/make/util.c from OpenBSD: > > If we add fgetln, I'd like a much higher quality of implementation. > It's not clear from the past documentation I've read for this function > that it's allowed to use a shared static buffer for all FILEs, and > even if it were, I find that really ugly. Instead, simply returning a > pointer into the FILE's buffer when the whole line is already present > in the buffer, and otherwise allocating a FILE-local buffer for it, > would be a lot nicer. fclose could then check the FILE-local pointer > and free if it it was allocated. See attached. Does it work okay? Rich --tNQTSEo8WG/FKZ8E Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="fgetln.c" #include "stdio_impl.h" char *fgetln(FILE *f, size_t *plen) { char *z; ssize_t l; if ((z=memchr(f->rpos, '\n', f->rend - f->rpos))) { char *ret = (char *)f->rpos; *plen = ++z - ret; f->rpos = (void *)z; return ret; } if ((l = getline(&f->getln_buf, (size_t[]){0}, f)) > 0) { *plen = l; return f->getln_buf; } return 0; } --tNQTSEo8WG/FKZ8E Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="fgetln.diff" diff --git a/src/internal/stdio_impl.h b/src/internal/stdio_impl.h index d54c918..65dcfbd 100644 --- a/src/internal/stdio_impl.h +++ b/src/internal/stdio_impl.h @@ -57,7 +57,7 @@ struct __FILE_s { int waiters; void *cookie; off_t off; - void *dummy4; + char *getln_buf; void *mustbezero_2; unsigned char *shend; off_t shlim, shcnt; diff --git a/src/stdio/fclose.c b/src/stdio/fclose.c index 373a2c7..8fdc3f7 100644 --- a/src/stdio/fclose.c +++ b/src/stdio/fclose.c @@ -16,6 +16,7 @@ int fclose(FILE *f) r = fflush(f); r |= f->close(f); + if (f->getln_buf) free(f->getln_buf); if (!perm) free(f); return r; --tNQTSEo8WG/FKZ8E--