1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-25 20:23:07 +03:00

Offer pnstrdup to frontend code

We already had it on the backend.  Frontend can also use it now.

Discussion: https://postgr.es/m/20191204144021.GA17976@alvherre.pgsql
This commit is contained in:
Alvaro Herrera
2019-12-04 19:36:06 -03:00
parent b1abfec825
commit 0b9466fce2
6 changed files with 36 additions and 35 deletions

View File

@@ -175,25 +175,6 @@ deccopy(decimal *src, decimal *target)
memcpy(target, src, sizeof(decimal));
}
static char *
ecpg_strndup(const char *str, size_t len)
{
size_t real_len = strlen(str);
int use_len = (int) ((real_len > len) ? len : real_len);
char *new = malloc(use_len + 1);
if (new)
{
memcpy(new, str, use_len);
new[use_len] = '\0';
}
else
errno = ENOMEM;
return new;
}
int
deccvasc(const char *cp, int len, decimal *np)
{
@@ -205,7 +186,7 @@ deccvasc(const char *cp, int len, decimal *np)
if (risnull(CSTRINGTYPE, cp))
return 0;
str = ecpg_strndup(cp, len); /* decimal_in always converts the complete
str = pnstrdup(cp, len); /* decimal_in always converts the complete
* string */
if (!str)
ret = ECPG_INFORMIX_NUM_UNDERFLOW;