mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
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.
This commit is contained in:
@ -14,7 +14,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.64 2008/06/18 18:42:54 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.65 2008/06/28 16:45:22 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -624,18 +624,6 @@ repalloc(void *pointer, Size size)
|
|||||||
pointer, 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
|
* MemoryContextSwitchTo
|
||||||
* Returns the current context; installs the given context.
|
* Returns the current context; installs the given context.
|
||||||
@ -676,6 +664,21 @@ MemoryContextStrdup(MemoryContext context, const char *string)
|
|||||||
return nstr;
|
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__)
|
#if defined(WIN32) || defined(__CYGWIN__)
|
||||||
/*
|
/*
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/utils/palloc.h,v 1.39 2008/06/18 18:42:54 momjian Exp $
|
* $PostgreSQL: pgsql/src/include/utils/palloc.h,v 1.40 2008/06/28 16:45:22 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -70,8 +70,6 @@ extern void pfree(void *pointer);
|
|||||||
|
|
||||||
extern void *repalloc(void *pointer, Size size);
|
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.
|
* MemoryContextSwitchTo can't be a macro in standard C compilers.
|
||||||
* But we can make it an inline function when using GCC.
|
* 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))
|
#define pstrdup(str) MemoryContextStrdup(CurrentMemoryContext, (str))
|
||||||
|
|
||||||
|
extern char *pnstrdup(const char *in, Size len);
|
||||||
|
|
||||||
#if defined(WIN32) || defined(__CYGWIN__)
|
#if defined(WIN32) || defined(__CYGWIN__)
|
||||||
extern void *pgport_palloc(Size sz);
|
extern void *pgport_palloc(Size sz);
|
||||||
extern char *pgport_pstrdup(const char *str);
|
extern char *pgport_pstrdup(const char *str);
|
||||||
|
Reference in New Issue
Block a user