diff options
author | Tom Lane | 2008-06-28 16:45:22 +0000 |
---|---|---|
committer | Tom Lane | 2008-06-28 16:45:22 +0000 |
commit | 943ee3420fe09c2d7e0190e37531b5e885d3bc7d (patch) | |
tree | 84958cd062fc3073dead318f90151c6d9fe75de7 | |
parent | 1e1aac7ae9b5115f69437b8058f4e7bd3fead029 (diff) |
If pnstrdup is going to be promoted to a generally available function,
it ought to conform to the rest of palloc.h in using Size for sizes.
-rw-r--r-- | src/backend/utils/mmgr/mcxt.c | 27 | ||||
-rw-r--r-- | src/include/utils/palloc.h | 4 |
2 files changed, 17 insertions, 14 deletions
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index 42aa4f3d12..0cfe1aa41b 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -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__) /* diff --git a/src/include/utils/palloc.h b/src/include/utils/palloc.h index f981ae99be..89fe60d79a 100644 --- a/src/include/utils/palloc.h +++ b/src/include/utils/palloc.h @@ -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); |