git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Avoid crippled getpass function on Solaris

From
Jeff King <peff@peff.net>
Date
Aug 6, 2012, 22:42 UTC
Message-ID
<20120806224222.GA16721@sigill.intra.peff.net>
In-Reply-To
<1344292395-sup-1921@pinkfloyd.chass.utoronto.ca>
On Mon, Aug 06, 2012 at 06:39:55PM -0400, Ben Walton wrote:
Show 12 quoted lines
> Excerpts from Jeff King's message of Mon Aug 06 18:31:13 -0400 2012:
> 
> > Looking over the code, I recall now why I used stdio: strbuf_getline
> > requires it. These days we have strbuf_getwholeline_fd. It's
> > slightly less efficient (it has to read() a character at a time),
> > but since we are talking about a few characters of keyboard input,
> > it should be OK.
> 
> I noticed the same requirement.  I'm currently building/testing a
> patch that switches from FILE -> fd and also to
> strbuf_getwholeline_fd.  Personally, I like this approach more than
> calling an open function multiple times.
OK, I'll stop working on the same thing, then. :)

We might want to do this to factor out the extra chomp you'll need by using strbuf_getwholeline_fd:

-- >8 --
Subject: [PATCH] strbuf: implement strbuf_getline_fd
When reading a line into a strbuf, we have two options:
  1. Read from stdio, or from a descriptor
  2. Chomp the terminator, or leave it in
We already have:
  strbuf_getwholeline:    stdio, nochomp
  strbuf_getline:         stdio,   chomp
  strbuf_getwholeline_fd:    fd, nochomp
This patch adds the missing orthogonal function:
  strbuf_getline_fd:         fd,   chomp
---
 strbuf.c | 8 ++++++++
 strbuf.h | 1 +
 2 files changed, 9 insertions(+)
diff --git a/strbuf.c b/strbuf.c
index ec88266..a6dffcc 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -399,6 +399,14 @@ int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)
 	return 0;
 }
 
+int strbuf_getline_fd(struct strbuf *sb, int fd, int term)
+{
+	if (strbuf_getwholeline(sb, fd, term))
+		return EOF;
+	if (sb->buf[sb->len-1] == term)
+		strbuf_setlen(sb, sb->len-1);
+}
+
 int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)
 {
 	int fd, len;
diff --git a/strbuf.h b/strbuf.h
index b888d40..cc1abb2 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -119,6 +119,7 @@ extern int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint);
 extern int strbuf_getwholeline(struct strbuf *, FILE *, int);
 extern int strbuf_getline(struct strbuf *, FILE *, int);
 extern int strbuf_getwholeline_fd(struct strbuf *, int, int);
+extern int strbuf_getline_fd(struct strbuf *, int, int);
 
 extern void stripspace(struct strbuf *buf, int skip_comments);
 extern int launch_editor(const char *path, struct strbuf *buffer, const char *const *env);
Previous: Ben WaltonNext: Ben Walton
Message 13 of 27 in “Avoid crippled getpass function on Solaris”
  1. Avoid crippled getpass function on SolarisBen Walton, Aug 5, 2012
  2. Tay Ray ChuanAug 6, 2012
  3. Ben WaltonAug 6, 2012
  4. Junio C HamanoAug 6, 2012
  5. Ben WaltonAug 6, 2012
  6. Jeff KingAug 6, 2012
  7. Junio C HamanoAug 6, 2012
  8. Ben WaltonAug 6, 2012
  9. Jeff KingAug 6, 2012
  10. Ben WaltonAug 6, 2012
  11. Jeff KingAug 6, 2012
  12. Ben WaltonAug 6, 2012
  13. Jeff KingAug 6, 2012
  14. Ben WaltonAug 6, 2012
  15. Jeff KingAug 7, 2012
  16. Andreas SchwabAug 6, 2012
  17. Jeff KingAug 7, 2012
  18. Jeff KingAug 7, 2012
  19. Tay Ray ChuanAug 7, 2012
  20. Ben WaltonAug 7, 2012
  21. Enable HAVE_DEV_TTY for SolarisBen Walton, Aug 7, 2012
  22. Junio C HamanoAug 7, 2012
  23. Jeff KingAug 7, 2012
  24. Jeff KingAug 7, 2012
  25. Ben WaltonAug 7, 2012
  26. Erik Faye-LundAug 8, 2012
  27. Jeff KingAug 8, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.