aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/network.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/adt/network.c')
-rw-r--r--src/backend/utils/adt/network.c37
1 files changed, 5 insertions, 32 deletions
diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c
index 7eb6ffe306f..8e58374e9b1 100644
--- a/src/backend/utils/adt/network.c
+++ b/src/backend/utils/adt/network.c
@@ -1,7 +1,7 @@
/*
* PostgreSQL type definitions for the INET and CIDR types.
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.72 2007/11/15 21:14:39 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.73 2008/03/25 22:42:44 tgl Exp $
*
* Jon Postel RIP 16 Oct 1998
*/
@@ -601,8 +601,6 @@ Datum
network_host(PG_FUNCTION_ARGS)
{
inet *ip = PG_GETARG_INET_P(0);
- text *ret;
- int len;
char *ptr;
char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
@@ -617,12 +615,7 @@ network_host(PG_FUNCTION_ARGS)
if ((ptr = strchr(tmp, '/')) != NULL)
*ptr = '\0';
- /* Return string as a text datum */
- len = strlen(tmp);
- ret = (text *) palloc(len + VARHDRSZ);
- SET_VARSIZE(ret, len + VARHDRSZ);
- memcpy(VARDATA(ret), tmp, len);
- PG_RETURN_TEXT_P(ret);
+ PG_RETURN_TEXT_P(cstring_to_text(tmp));
}
/*
@@ -634,7 +627,6 @@ Datum
network_show(PG_FUNCTION_ARGS)
{
inet *ip = PG_GETARG_INET_P(0);
- text *ret;
int len;
char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
@@ -651,21 +643,14 @@ network_show(PG_FUNCTION_ARGS)
snprintf(tmp + len, sizeof(tmp) - len, "/%u", ip_bits(ip));
}
- /* Return string as a text datum */
- len = strlen(tmp);
- ret = (text *) palloc(len + VARHDRSZ);
- SET_VARSIZE(ret, len + VARHDRSZ);
- memcpy(VARDATA(ret), tmp, len);
- PG_RETURN_TEXT_P(ret);
+ PG_RETURN_TEXT_P(cstring_to_text(tmp));
}
Datum
inet_abbrev(PG_FUNCTION_ARGS)
{
inet *ip = PG_GETARG_INET_P(0);
- text *ret;
char *dst;
- int len;
char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
dst = inet_net_ntop(ip_family(ip), ip_addr(ip),
@@ -676,21 +661,14 @@ inet_abbrev(PG_FUNCTION_ARGS)
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("could not format inet value: %m")));
- /* Return string as a text datum */
- len = strlen(tmp);
- ret = (text *) palloc(len + VARHDRSZ);
- SET_VARSIZE(ret, len + VARHDRSZ);
- memcpy(VARDATA(ret), tmp, len);
- PG_RETURN_TEXT_P(ret);
+ PG_RETURN_TEXT_P(cstring_to_text(tmp));
}
Datum
cidr_abbrev(PG_FUNCTION_ARGS)
{
inet *ip = PG_GETARG_INET_P(0);
- text *ret;
char *dst;
- int len;
char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
dst = inet_cidr_ntop(ip_family(ip), ip_addr(ip),
@@ -701,12 +679,7 @@ cidr_abbrev(PG_FUNCTION_ARGS)
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("could not format cidr value: %m")));
- /* Return string as a text datum */
- len = strlen(tmp);
- ret = (text *) palloc(len + VARHDRSZ);
- SET_VARSIZE(ret, len + VARHDRSZ);
- memcpy(VARDATA(ret), tmp, len);
- PG_RETURN_TEXT_P(ret);
+ PG_RETURN_TEXT_P(cstring_to_text(tmp));
}
Datum