Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Straub <bs@github.com>2013-02-01 22:00:55 +0400
committerBen Straub <bs@github.com>2013-02-01 22:00:55 +0400
commitc4beee768135f70b91b2c0bfa1dbc99a58c1f311 (patch)
tree43a721f7b4147b016ce7d8dc37d3a987839374dd /src/util.h
parent8c36a3cdba57ce5fb81d81dc3186f3ff9f2702f7 (diff)
Introduce git__substrdup
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/util.h b/src/util.h
index e75d777a8..e9edd84a3 100644
--- a/src/util.h
+++ b/src/util.h
@@ -51,11 +51,7 @@ GIT_INLINE(char *) git__strndup(const char *str, size_t n)
while (length < n && str[length])
++length;
- ptr = (char*)malloc(length + 1);
- if (!ptr) {
- giterr_set_oom();
- return NULL;
- }
+ ptr = (char*)git__malloc(length + 1);
if (length)
memcpy(ptr, str, length);
@@ -65,6 +61,14 @@ GIT_INLINE(char *) git__strndup(const char *str, size_t n)
return ptr;
}
+/* NOTE: This doesn't do null or '\0' checking. Watch those boundaries! */
+GIT_INLINE(char *) git__substrdup(const char *start, size_t n)
+{
+ char *ptr = (char*)git__calloc(n+1, sizeof(char));
+ memcpy(ptr, start, n);
+ return ptr;
+}
+
GIT_INLINE(void *) git__realloc(void *ptr, size_t size)
{
void *new_ptr = realloc(ptr, size);