>> The best things might be not to mess with this but call textin() and
>> textout() to convert your data to C strings.
textin() and textout() are notationally painful to call these days.
Personally I think it's just as easy to do your own manipulation of
text objects. There are examples at
http://www.postgresql.org/users-lounge/docs/7.1/postgres/xfunc-c.html
--- see the copytext and concat_text() samples in particular.
regards, tom lane