author | Pierre Habouzit <madcoder@debian.org> | |
Sat, 15 Sep 2007 21:53:05 +0000 (23:53 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 18 Sep 2007 10:07:58 +0000 (03:07 -0700) | ||
commit | 68d3025a805097ec148ec6e9b0b54a5db1ef138e | |
tree | f6e8d1a5fdb89dd52a7f90d34bb271a2c4048cc4 | tree | snapshot |
parent | 0557656930d41f10c90bccf90e3c5bd87bd53661 | commit | diff |
Add xmemdupz() that duplicates a block of memory, and NUL terminates it.
A lot of places in git's code use code like:
char *res;
len = ... find length of an interesting segment in src ...;
res = xmalloc(len + 1);
memcpy(res, src, len);
res[len] = '\0';
return res;
A new function xmemdupz() captures the allocation, copy and NUL
termination. Existing xstrndup() is reimplemented in terms of
this new function.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
A lot of places in git's code use code like:
char *res;
len = ... find length of an interesting segment in src ...;
res = xmalloc(len + 1);
memcpy(res, src, len);
res[len] = '\0';
return res;
A new function xmemdupz() captures the allocation, copy and NUL
termination. Existing xstrndup() is reimplemented in terms of
this new function.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-compat-util.h | diff | blob | history |