aboutsummaryrefslogtreecommitdiff
path: root/src/common/fe_memutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/fe_memutils.c')
-rw-r--r--src/common/fe_memutils.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/common/fe_memutils.c b/src/common/fe_memutils.c
index ce99b4f4da1..2bc6606b80c 100644
--- a/src/common/fe_memutils.c
+++ b/src/common/fe_memutils.c
@@ -142,6 +142,33 @@ pstrdup(const char *in)
return pg_strdup(in);
}
+char *
+pnstrdup(const char *in, Size size)
+{
+ char *tmp;
+ int len;
+
+ if (!in)
+ {
+ fprintf(stderr,
+ _("cannot duplicate null pointer (internal error)\n"));
+ exit(EXIT_FAILURE);
+ }
+
+ len = strnlen(in, size);
+ tmp = malloc(len + 1);
+ if (tmp == NULL)
+ {
+ fprintf(stderr, _("out of memory\n"));
+ exit(EXIT_FAILURE);
+ }
+
+ memcpy(tmp, in, len);
+ tmp[len] = '\0';
+
+ return tmp;
+}
+
void *
repalloc(void *pointer, Size size)
{