# [PATCH 1/5] Make xstrndup common

1 messages from 2007-04-28 to 2007-04-28. Participants: Daniel Barkalow.
Thread: https://gitlist.dev/t/7887

## Daniel Barkalow, 2007-04-28 17:05

Subject: [PATCH 1/5] Make xstrndup common
Message-ID: <Pine.LNX.4.64.0704281303371.28708@iabervon.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0704281303371.28708%40iabervon.org

```
It was implemented in commit.c; move it with the other x memory functions.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
 commit.c          |    8 --------
 git-compat-util.h |    8 ++++++++
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/commit.c b/commit.c
index f1ba972..aa7059c 100644
--- a/commit.c
+++ b/commit.c
@@ -718,14 +718,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 2c84016..615c353 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -197,6 +197,14 @@ static inline void *xmalloc(size_t size)
 	return ret;
 }
 
+static inline char *xstrndup(const char *str, int len)
+{
+	char *ret = xmalloc(len + 1);
+	memcpy(ret, str, len);
+	ret[len] = '\0';
+	return ret;
+}
+
 static inline void *xrealloc(void *ptr, size_t size)
 {
 	void *ret = realloc(ptr, size);
-- 
1.5.1.2.255.g6ead4-dirty

```
