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

Re: [PATCH] config: avoid "write_in_full(fd, buf, len) != len" pattern

From
René Scharfe <l.s.r@web.de>
Date
Nov 18, 2017, 10:20 UTC
Message-ID
<f3038984-1cd8-e11f-61fd-10bf0cc33e2d@web.de>
In-Reply-To
<20171117220633.6yoovfgpbr3rsykr@sigill.intra.peff.net>
Am 17.11.2017 um 23:06 schrieb Jeff King:
> There's one more case in write_section() that uses "==". That's not
> actually wrong, but I wonder if we'd want to make it "< 0" for
> consistency.
Actually it *is* wrong.
-- >8 --
Subject: [PATCH] config: flip return value of write_section()

d9bd4cbb9cc (config: flip return value of store_write_*()) made write_section() follow the convention of write(2) to return -1 on error and the number of written bytes on success. 3b48045c6c7 (Merge branch 'sd/branch-copy') changed it back to returning 0 on error and 1 on success, but left its callers still checking for negative values.

Let write_section() follow the convention of write(2) again to meet the expectations of its callers.

Reported-by: Jeff King <peff@peff.net>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/config.c b/config.c
index 903abf9533..3f079c77ad 100644
--- a/config.c
+++ b/config.c
@@ -2315,7 +2315,7 @@ static ssize_t write_section(int fd, const char *key)
 	struct strbuf sb = store_create_section(key);
 	ssize_t ret;
 
-	ret = write_in_full(fd, sb.buf, sb.len) == sb.len;
+	ret = write_in_full(fd, sb.buf, sb.len);
 	strbuf_release(&sb);
 
 	return ret;
-- 
2.15.0
Previous: Jeff KingNext: Jeff King
Message 4 of 7 in “config: avoid "write_in_full(fd, buf, len) != len" pattern”
  1. config: avoid "write_in_full(fd, buf, len) != len" patternPhillip Wood, Nov 15, 2017
  2. Junio C HamanoNov 16, 2017
  3. Jeff KingNov 17, 2017
  4. René ScharfeNov 18, 2017
  5. Jeff KingNov 18, 2017
  6. René ScharfeNov 18, 2017
  7. Phillip WoodNov 18, 2017

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.