simple C function

Поиск
Список
Период
Сортировка
Искать

simple C function

От:
M.Mazurek@poznan.multinet.pl
Дата:
Hi,
I'm trying to write a simple C function:
                                        
char *pg_crypt (char *pass) {
	char *salt="xyz";
        char *res;
	res = (char *) palloc(14);
	res=crypt(pass,salt);
	return res;
}

CREATE FUNCTION pg_crypt(text) RETURNS text as
'/home/mazek/pgsql/pg_crypt.so' LANGUAGE  'c';

psql just got stuck and I can't even DROP this function, because psql
hangs. Can You give me a hint me where should I look for errors. How to
get rid of this function without reinitializing $PGDATA and destroying
other data (accordind to former discussion:) ).
 LINUX RH6.2,PG 7.0        

Marcin Mazurek

--
administrator
MULTINET SA o/Poznan
http://www.multinet.pl/

Re: simple C function

От:
"Ross J. Reedstrom" <reedstrm@wallace.ece.rice.edu>
Дата:
Вложения:
On Fri, May 19, 2000 at 05:54:55PM +0200, M.Mazurek@poznan.multinet.pl wrote:
> Hi,
> I'm trying to write a simple C function:
>                                         
> char *pg_crypt (char *pass) {
> 	char *salt="xyz";
>         char *res;
> 	res = (char *) palloc(14);
> 	res=crypt(pass,salt);
> 	return res;
> }

you can't pass char pointers around like that for pgsql functions. 
Here's my version of the above function. It includes random salt
selection if you don't supply it. (Hmm, I suppose I should put
this is contrib, eh? I did start with someone elses boilerplate,
so I'm not sure about the #define at the top.)

I compile it on linux with gcc as so:

gcc -fPIC -shared -I /usr/local/pgsql/include -L /usr/local/pgsql/lib \
    -o sqlcrypt.so sqlcrypt.c

And install it like so:

CREATE FUNCTION "sqlcrypt" (text,text ) RETURNS text AS '/usr/local/lib/sqlcrypt
.so' LANGUAGE 'C';

CREATE FUNCTION "sqlcrypt" (text ) RETURNS text AS 'select sqlcrypt($1,'''')' LA
NGUAGE 'SQL';

Ross
-- 
Ross J. Reedstrom, Ph.D.,  
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St.,  Houston, TX 77005
FAQ