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

[PATCH] imap-send: simplify v_issue_imap_cmd() and get_cmd_result() using starts_with()

From
René Scharfe <l.s.r@web.de>
Date
Aug 30, 2014, 16:14 UTC
Message-ID
<5401F860.4030902@web.de>

Use starts_with() instead of memcmp() to check if NUL-terminated strings match prefixes. This gets rid of some magic string length constants.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 imap-send.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/imap-send.c b/imap-send.c
index 524fbab..b079a0d 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -524,7 +524,7 @@ static struct imap_cmd *v_issue_imap_cmd(struct imap_store *ctx,
 	if (Verbose) {
 		if (imap->num_in_progress)
 			printf("(%d in progress) ", imap->num_in_progress);
-		if (memcmp(cmd->cmd, "LOGIN", 5))
+		if (!starts_with(cmd->cmd, "LOGIN"))
 			printf(">>> %s", buf);
 		else
 			printf(">>> %d LOGIN <user> <pass>\n", cmd->tag);
@@ -802,7 +802,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
 				resp = DRV_OK;
 			else {
 				if (!strcmp("NO", arg)) {
-					if (cmdp->cb.create && cmd && (cmdp->cb.trycreate || !memcmp(cmd, "[TRYCREATE]", 11))) { /* SELECT, APPEND or UID COPY */
+					if (cmdp->cb.create && cmd &&
+					    (cmdp->cb.trycreate ||
+					     starts_with(cmd, "[TRYCREATE]"))) {
+						/* SELECT, APPEND or UID COPY */
 						p = strchr(cmdp->cmd, '"');
 						if (!issue_imap_cmd(ctx, NULL, "CREATE \"%.*s\"", (int)(strchr(p + 1, '"') - p + 1), p)) {
 							resp = RESP_BAD;
@@ -827,7 +830,7 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
 				} else /*if (!strcmp("BAD", arg))*/
 					resp = RESP_BAD;
 				fprintf(stderr, "IMAP command '%s' returned response (%s) - %s\n",
-					 memcmp(cmdp->cmd, "LOGIN", 5) ?
+					!starts_with(cmdp->cmd, "LOGIN") ?
 							cmdp->cmd : "LOGIN <user> <pass>",
 							arg, cmd ? cmd : "");
 			}
-- 
2.1.0
Next: Junio C Hamano
Message 1 of 3 in “imap-send: simplify v_issue_imap_cmd() and get_cmd_result() using starts_with()”
  1. imap-send: simplify v_issue_imap_cmd() and get_cmd_result() using starts_with()René Scharfe, Aug 30, 2014
  2. Junio C HamanoSep 2, 2014
  3. René ScharfeSep 3, 2014

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.