If pnstrdup is going to be promoted to a generally available function,
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 28 Jun 2008 16:45:22 +0000 (16:45 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 28 Jun 2008 16:45:22 +0000 (16:45 +0000)
it ought to conform to the rest of palloc.h in using Size for sizes.

src/backend/utils/mmgr/mcxt.c
src/include/utils/palloc.h

index 42aa4f3d12708417032b1b6097cd1f33c1393095..0cfe1aa41ba99dfd5bd635fbacff945212535717 100644 (file)
@@ -624,18 +624,6 @@ repalloc(void *pointer, Size size)
                                                                                                 pointer, size);
 }
 
-/* Like pstrdup(), but append null byte */
-char *
-pnstrdup(const char *in, int len)
-{
-       char       *out = palloc(len + 1);
-
-       memcpy(out, in, len);
-       out[len] = '\0';
-       return out;
-}
-
-
 /*
  * MemoryContextSwitchTo
  *             Returns the current context; installs the given context.
@@ -676,6 +664,21 @@ MemoryContextStrdup(MemoryContext context, const char *string)
        return nstr;
 }
 
+/*
+ * pnstrdup
+ *             Like pstrdup(), but append null byte to a
+ *             not-necessarily-null-terminated input string.
+ */
+char *
+pnstrdup(const char *in, Size len)
+{
+       char       *out = palloc(len + 1);
+
+       memcpy(out, in, len);
+       out[len] = '\0';
+       return out;
+}
+
 
 #if defined(WIN32) || defined(__CYGWIN__)
 /*
index f981ae99be4941b6900463b0dd4378decb88813e..89fe60d79a022e9e43e3358f670019d9259f2cfe 100644 (file)
@@ -70,8 +70,6 @@ extern void pfree(void *pointer);
 
 extern void *repalloc(void *pointer, Size size);
 
-extern char *pnstrdup(const char *in, int len);
-
 /*
  * MemoryContextSwitchTo can't be a macro in standard C compilers.
  * But we can make it an inline function when using GCC.
@@ -99,6 +97,8 @@ extern char *MemoryContextStrdup(MemoryContext context, const char *string);
 
 #define pstrdup(str)  MemoryContextStrdup(CurrentMemoryContext, (str))
 
+extern char *pnstrdup(const char *in, Size len);
+
 #if defined(WIN32) || defined(__CYGWIN__)
 extern void *pgport_palloc(Size sz);
 extern char *pgport_pstrdup(const char *str);