From 030ebaaa458f534871fe62a20fcea7e8ee1d5a57 Mon Sep 17 00:00:00 2001 From: Christopher Kings-Lynne Date: Fri, 25 Mar 2005 06:26:31 +0000 Subject: (PHP pg_unescape_bytea) Use libpq version of PQunescapeBytea if it exists. # The version in libpq is newer and faster than the one in PHP, but it is # necessary for me to add a string copy for freeing purposes. This copy # is only needed in Windows AFAIK, how can I detect that? --- ext/pgsql/pgsql.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'ext/pgsql/pgsql.c') diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index f90f8fa66c..37402cd06a 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -3414,6 +3414,7 @@ PHP_FUNCTION(pg_escape_bytea) } /* }}} */ +#if !HAVE_PQUNESCAPEBYTEA /* PQunescapeBytea() from PostgreSQL 7.3 to provide bytea unescape feature to 7.2 users. Renamed to php_pgsql_unescape_bytea() */ /* @@ -3517,12 +3518,13 @@ static unsigned char * php_pgsql_unescape_bytea(unsigned char *strtext, size_t * *retbuflen = buflen; return buffer; } +#endif /* {{{ proto string pg_unescape_bytea(string data) Unescape binary for bytea type */ PHP_FUNCTION(pg_unescape_bytea) { - char *from = NULL, *to = NULL; + char *from = NULL, *to = NULL, *tmp = NULL; size_t to_len; int from_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", @@ -3530,7 +3532,13 @@ PHP_FUNCTION(pg_unescape_bytea) return; } +#if HAVE_PQUNESCAPEBYTEA + tmp = (char *)PQunescapeBytea((unsigned char*)from, &to_len); + to = estrndup(tmp, to_len); + PQfreemem(tmp); +#else to = (char *)php_pgsql_unescape_bytea((unsigned char*)from, &to_len); +#endif if (!to) { RETURN_FALSE; } -- cgit v1.2.1