Skip to content

Commit 4a8d573

Browse files
committed
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.
1 parent dcc2334 commit 4a8d573

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/backend/utils/mmgr/mcxt.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.64 2008/06/18 18:42:54 momjian Exp $
17+
* $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.65 2008/06/28 16:45:22 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -624,18 +624,6 @@ repalloc(void *pointer, Size size)
624624
pointer, size);
625625
}
626626

627-
/* Like pstrdup(), but append null byte */
628-
char *
629-
pnstrdup(const char *in, int len)
630-
{
631-
char *out = palloc(len + 1);
632-
633-
memcpy(out, in, len);
634-
out[len] = '\0';
635-
return out;
636-
}
637-
638-
639627
/*
640628
* MemoryContextSwitchTo
641629
* Returns the current context; installs the given context.
@@ -676,6 +664,21 @@ MemoryContextStrdup(MemoryContext context, const char *string)
676664
return nstr;
677665
}
678666

667+
/*
668+
* pnstrdup
669+
* Like pstrdup(), but append null byte to a
670+
* not-necessarily-null-terminated input string.
671+
*/
672+
char *
673+
pnstrdup(const char *in, Size len)
674+
{
675+
char *out = palloc(len + 1);
676+
677+
memcpy(out, in, len);
678+
out[len] = '\0';
679+
return out;
680+
}
681+
679682

680683
#if defined(WIN32) || defined(__CYGWIN__)
681684
/*

src/include/utils/palloc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
2222
* Portions Copyright (c) 1994, Regents of the University of California
2323
*
24-
* $PostgreSQL: pgsql/src/include/utils/palloc.h,v 1.39 2008/06/18 18:42:54 momjian Exp $
24+
* $PostgreSQL: pgsql/src/include/utils/palloc.h,v 1.40 2008/06/28 16:45:22 tgl Exp $
2525
*
2626
*-------------------------------------------------------------------------
2727
*/
@@ -70,8 +70,6 @@ extern void pfree(void *pointer);
7070

7171
extern void *repalloc(void *pointer, Size size);
7272

73-
extern char *pnstrdup(const char *in, int len);
74-
7573
/*
7674
* MemoryContextSwitchTo can't be a macro in standard C compilers.
7775
* But we can make it an inline function when using GCC.
@@ -99,6 +97,8 @@ extern char *MemoryContextStrdup(MemoryContext context, const char *string);
9997

10098
#define pstrdup(str) MemoryContextStrdup(CurrentMemoryContext, (str))
10199

100+
extern char *pnstrdup(const char *in, Size len);
101+
102102
#if defined(WIN32) || defined(__CYGWIN__)
103103
extern void *pgport_palloc(Size sz);
104104
extern char *pgport_pstrdup(const char *str);

0 commit comments

Comments
 (0)