summaryrefslogtreecommitdiff
path: root/make_malloc.h
diff options
context:
space:
mode:
Diffstat (limited to 'make_malloc.h')
-rw-r--r--make_malloc.h19
1 files changed, 16 insertions, 3 deletions
diff --git a/make_malloc.h b/make_malloc.h
index 36d3eff3c027..ac804d79c711 100644
--- a/make_malloc.h
+++ b/make_malloc.h
@@ -1,4 +1,4 @@
-/* $NetBSD: make_malloc.h,v 1.4 2009/01/24 14:43:29 dsl Exp $ */
+/* $NetBSD: make_malloc.h,v 1.10 2020/08/29 16:47:45 rillig Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,12 +30,25 @@
void *bmake_malloc(size_t);
void *bmake_realloc(void *, size_t);
char *bmake_strdup(const char *);
-char *bmake_strndup(const char *, size_t);
+char *bmake_strldup(const char *, size_t);
#else
#include <util.h>
#define bmake_malloc(x) emalloc(x)
#define bmake_realloc(x,y) erealloc(x,y)
#define bmake_strdup(x) estrdup(x)
-#define bmake_strndup(x,y) estrndup(x,y)
+#define bmake_strldup(x,y) estrndup(x,y)
#endif
+char *bmake_strsedup(const char *, const char *);
+/* Thin wrapper around free(3) to avoid the extra function call in case
+ * p is NULL, which on x86_64 costs about 12 machine instructions.
+ * Other platforms are similarly affected.
+ *
+ * The case of a NULL pointer happens especially often after Var_Value,
+ * since only environment variables need to be freed, but not others. */
+static inline void MAKE_ATTR_UNUSED
+bmake_free(void *p)
+{
+ if (p != NULL)
+ free(p);
+}