[PATCH 1/5] Add streq() to compat-util
- From
- Christian 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