aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--commit.c8
-rw-r--r--git-compat-util.h13
2 files changed, 13 insertions, 8 deletions
diff --git a/commit.c b/commit.c
index 754d1b8a0..eb911f44d 100644
--- a/commit.c
+++ b/commit.c
@@ -720,14 +720,6 @@ static char *logmsg_reencode(const struct commit *commit,
return out;
}
-static char *xstrndup(const char *text, int len)
-{
- char *result = xmalloc(len + 1);
- memcpy(result, text, len);
- result[len] = '\0';
- return result;
-}
-
static void fill_person(struct interp *table, const char *msg, int len)
{
int start, end, tz = 0;
diff --git a/git-compat-util.h b/git-compat-util.h
index e3cf3703b..bd93b6257 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -189,6 +189,19 @@ static inline void *xmalloc(size_t size)
return ret;
}
+static inline char *xstrndup(const char *str, size_t len)
+{
+ char *p;
+
+ p = memchr(str, '\0', len);
+ if (p)
+ len = p - str;
+ p = xmalloc(len + 1);
+ memcpy(p, str, len);
+ p[len] = '\0';
+ return p;
+}
+
static inline void *xrealloc(void *ptr, size_t size)
{
void *ret = realloc(ptr, size);