Make xstrndup common

This also improves the implementation to match how strndup is
specified (by GNU): if the length given is longer than the string,
only the string's length is allocated and copied, but the string need
not be null-terminated if it is at least as long as the given length.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Daniel Barkalow
2007-05-02 22:49:41 -04:00
committed by Junio C Hamano
parent cdda666201
commit 5094102e13
2 changed files with 13 additions and 8 deletions

View File

@ -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;