Thank you for your replies, however, it still is not working, see below...
Andrew Chernow wrote:
Tim Hawes wrote:
text * pl_masterkey(PG_FUNCTION_ARGS)
{
char *e_var = getenv("PGMASTERKEY");
size_t length = VARSIZE(e_var) - VARHDRSZ;
The VARSIZE macro is for variable length structures, like a text or
bytea which contains a length and data member. You are using this
macro on a regular C string "e_var". Try this instead:
size_t length = e_var != NULL ? strlen(e_var) : 0;
@Jan:
It appears the cstring_to_text function is unique to the latest
PostgreSQL code. I do not have a def for that for PostgreSQL 8.2, and
currently I am stuck working with that version. I changed the return
value to Datum, and I had previously only copied from the examples at:
http://www.postgresql.org/docs/8.2/interactive/xfunc-c.html
@Andrew:
here is my new code:
Datum pl_masterkey(PG_FUNCTION_ARGS)
{
char *e_var = getenv("PGMASTERKEY");
size_t length = e_var != NULL ? strlen(e_var) : 0;
text * mkey = (text *) palloc(length);
VARATT_SIZEP(mkey) = length;
memcpy(VARDATA(mkey), e_var, length);
PG_RETURN_TEXT_P(mkey);
}
now gets:
select pl_masterkey();
ERROR: invalid memory alloc request size 4294967293
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers