summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2016-09-03 17:59:15 +0200
committerJunio C Hamano <gitster@pobox.com>2016-09-07 10:41:45 -0700
commitca2baa3f7532dfe1816b623f39489ed10f3c9a49 (patch)
tree4422885a6aa8511f04adedfbedc71c8599ad932e /compat
parente0c1ceafc5bece92d35773a75fff59497e1d9bd5 (diff)
downloadgit-ca2baa3f7532dfe1816b623f39489ed10f3c9a49.tar.gz
compat: move strdup(3) replacement to its own filers/compat-strdup
Move our implementation of strdup(3) out of compat/nedmalloc/ and allow it to be used independently from USE_NED_ALLOCATOR. The original nedmalloc doesn't come with strdup() and doesn't need it. Only _users_ of nedmalloc need it, which was added when we imported it to our compat/ hierarchy. This reduces the difference of our copy of nedmalloc from the original, making it easier to update, and allows for easier testing and reusing of our version of strdup(). Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat')
-rw-r--r--compat/nedmalloc/nedmalloc.c16
-rw-r--r--compat/strdup.c11
2 files changed, 11 insertions, 16 deletions
diff --git a/compat/nedmalloc/nedmalloc.c b/compat/nedmalloc/nedmalloc.c
index 2d4ef59013..1cc31c3502 100644
--- a/compat/nedmalloc/nedmalloc.c
+++ b/compat/nedmalloc/nedmalloc.c
@@ -948,22 +948,6 @@ void **nedpindependent_comalloc(nedpool *p, size_t elems, size_t *sizes, void **
return ret;
}
-#ifdef OVERRIDE_STRDUP
-/*
- * This implementation is purely there to override the libc version, to
- * avoid a crash due to allocation and free on different 'heaps'.
- */
-char *strdup(const char *s1)
-{
- size_t len = strlen(s1) + 1;
- char *s2 = malloc(len);
-
- if (s2)
- memcpy(s2, s1, len);
- return s2;
-}
-#endif
-
#if defined(__cplusplus)
}
#endif
diff --git a/compat/strdup.c b/compat/strdup.c
new file mode 100644
index 0000000000..f3fb978eb3
--- /dev/null
+++ b/compat/strdup.c
@@ -0,0 +1,11 @@
+#include "../git-compat-util.h"
+
+char *gitstrdup(const char *s1)
+{
+ size_t len = strlen(s1) + 1;
+ char *s2 = malloc(len);
+
+ if (s2)
+ memcpy(s2, s1, len);
+ return s2;
+}