mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: Priorities for next release?
Date: Sat, 11 Aug 2012 17:22:58 -0400	[thread overview]
Message-ID: <20120811212258.GN27715@brightrain.aerifal.cx> (raw)
In-Reply-To: <20120811205128.GL27715@brightrain.aerifal.cx>

[-- Attachment #1: Type: text/plain, Size: 752 bytes --]

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

[-- Attachment #2: fgetln.c --]
[-- Type: text/plain, Size: 341 bytes --]

#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;
}

[-- Attachment #3: fgetln.diff --]
[-- Type: text/plain, Size: 631 bytes --]

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;

  parent reply	other threads:[~2012-08-11 21:22 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-10 19:12 Rich Felker
2012-08-10 19:23 ` Nathan McSween
2012-08-10 19:39   ` Unit/regression testing (was Re: [musl] Priorities for next release?) Rich Felker
2012-08-10 22:03 ` Priorities for next release? Luca Barbato
2012-08-11  0:05   ` Rich Felker
2012-08-11  0:54     ` Luca Barbato
2012-08-11  1:07       ` Rich Felker
2012-08-11  2:21       ` idunham
2012-08-11  2:36         ` Rich Felker
2012-08-11 12:21           ` Daniel Cegiełka
2012-08-11 12:27             ` Rich Felker
2012-08-11 12:35               ` Daniel Cegiełka
2012-08-11 16:09                 ` Rich Felker
2012-08-11 16:35                   ` Daniel Cegiełka
2012-08-11 16:50                     ` Rich Felker
2012-08-11 17:55                       ` orc
2012-08-11 18:41                         ` Daniel Cegiełka
2012-08-11 18:47                           ` orc
2012-08-11 19:05                             ` Daniel Cegiełka
2012-08-11 19:28                               ` Rich Felker
2012-08-11 19:56 ` Rich Felker
2012-08-11 20:26   ` Daniel Cegiełka
2012-08-11 20:51     ` Rich Felker
2012-08-11 20:56       ` Rich Felker
2012-08-11 21:22       ` Rich Felker [this message]
2012-08-12 12:52         ` Daniel Cegiełka
2012-08-11 22:25   ` Rich Felker
2012-08-12 12:40     ` Szabolcs Nagy
2012-08-13  8:40   ` Luca Barbato
2012-08-13 13:41     ` Rich Felker
2012-08-13 15:49       ` Szabolcs Nagy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120811212258.GN27715@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).