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

[PATCH] pretty: use starts_with() to check for a prefix

From
René Scharfe <l.s.r@web.de>
Date
Feb 21, 2015, 19:53 UTC
Message-ID
<54E8E225.4070406@web.de>

Simplify the code and avoid duplication by using starts_with() instead of strlen() and strncmp() to check if a line starts with "encoding ".

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 pretty.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pretty.c b/pretty.c
index 9d34d02..7b49304 100644
--- a/pretty.c
+++ b/pretty.c
@@ -567,7 +567,7 @@ static char *replace_encoding_header(char *buf, const char *encoding)
 	char *cp = buf;
 
 	/* guess if there is an encoding header before a \n\n */
-	while (strncmp(cp, "encoding ", strlen("encoding "))) {
+	while (!starts_with(cp, "encoding ")) {
 		cp = strchr(cp, '\n');
 		if (!cp || *++cp == '\n')
 			return buf;
-- 
2.3.0
Message 1 of 1 in “pretty: use starts_with() to check for a prefix”
  1. pretty: use starts_with() to check for a prefixRené Scharfe, Feb 21, 2015

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.