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

[PATCH 1/5] Add streq() to compat-util

From
CTChristian Thaeter <ct@pipapo.org>
Date
Jan 7, 2008, 05:47 UTC
Message-ID
<1199684855-14246-1-git-send-email-ct@pipapo.org>

streq() compares strings for equality, it differs from strcmp() in that it can handle NULL pointers and that it short-circruits if a==b.

returns 1 if the strings are equal (or both are NULL) and 0 when not.
Signed-off-by: Christian Thaeter <ct@pipapo.org>
---
Here comes a series of patches to reinit libgit with subsequent
setup_git_directory() calls. So far, this only suffices for simple
tasks like scanning a list of repositories (buiding the start page
of a repository browser). There are still a lot of things not
fixed yet (grep for '\tstatic', object & graft cache etc.).
Nevertheless, it works for me so far.
 git-compat-util.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index b6ef544..759e94c 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -424,4 +424,13 @@ static inline int strtol_i(char const *s, int base, int *result)
 	return 0;
 }
 
+static inline int streq(const char *a, const char* b)
+{
+	if (a == b)
+		return 1;
+	if (a && b)
+		return !strcmp(a, b);
+	return 0;
+}
+
 #endif
-- 
1.5.3.7
Next: Christian Thaeter
Message 1 of 8 in “Add streq() to compat-util”
  1. 1/5 Add streq() to compat-utilChristian Thaeter, Jan 7, 2008
  2. 2/5 First step, making setup (somewhat) reentrantChristian Thaeter, Jan 7, 2008
  3. 3/5 provide a reset_packed_git() functionChristian Thaeter, Jan 7, 2008
  4. 4/5 Export some more functions to enable resetting the git stateChristian Thaeter, Jan 7, 2008
  5. 5/5 Make setup_git_directory reentrantChristian Thaeter, Jan 7, 2008
  6. Johannes SchindelinJan 7, 2008
  7. Junio C HamanoJan 7, 2008
  8. Johannes SchindelinJan 7, 2008

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.