pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedMake C file for create type
2+ messages / 2 participants
[nested] [flat]
* Make C file for create type
@ 2005-08-05 08:51 Louise Catherine <r1c4n@yahoo.com>
0 siblings, 1 reply; 2+ messages in thread
From: Louise Catherine @ 2005-08-05 08:51 UTC (permalink / raw)
To: pgsql-sql
Hallo,
I found a problem making new data type kata,expecially
when make the C file ,can anyone help me solve it.
This error occur when I'm compiling the C file :
/usr/lib/gcc-lib/i586-suse-linux/3.3.1/../../../crt1.o(.text+0x18):
In function `_start':
../sysdeps/i386/elf/start.S:98: undefined reference to
`main'
collect2: ld returned 1 exit status
Here it's my code :
file3.c
-------
#include "postgres.h"
typedef struct kata
{
char kt[30];
} kata;
kata *input_kata(char *str);
char *output_kata(kata * kata);
kata *
input_kata(char *str)
{
char kt[30];
kata *result;
if (sscanf(str, "( %s )", &kt) !=1)
{
printf ("error\n");
return NULL;
}
result = (kata *) malloc(sizeof(kata));
strcpy(result->kt,kt);
return result;
}
char *
output_kata(kata * kata)
{
char kt[30];
char *result;
strcpy(kt,kata->kt);
if (strcmp(kt,NULL))
return NULL;
result = (char *) malloc(60);
sprintf(result, "(%s)", kata->kt);
return result;
}
kata.sql
--------
CREATE FUNCTION input_kata(cstring)
RETURNS kata
AS '_OBJWD_/file3'
LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION output_kata(kata)
RETURNS cstring
AS '_OBJWD_/file3'
LANGUAGE C IMMUTABLE STRICT;
CREATE TYPE kata (
INPUT = input_kata,
OUTPUT = output_kata
)
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Make C file for create type
@ 2005-08-05 10:48 Richard Huxton <dev@archonet.com>
parent: Louise Catherine <r1c4n@yahoo.com>
0 siblings, 0 replies; 2+ messages in thread
From: Richard Huxton @ 2005-08-05 10:48 UTC (permalink / raw)
To: Louise Catherine <r1c4n@yahoo.com>; +Cc: pgsql-sql
Louise Catherine wrote:
> Hallo,
> I found a problem making new data type kata,expecially
> when make the C file ,can anyone help me solve it.
>
> This error occur when I'm compiling the C file :
> /usr/lib/gcc-lib/i586-suse-linux/3.3.1/../../../crt1.o(.text+0x18):
> In function `_start':
> ../sysdeps/i386/elf/start.S:98: undefined reference to
> `main'
> collect2: ld returned 1 exit status
You don't have a main() function. This is the function that gets called
when you run an executable. Looking at your code, it seems like you want
to produce a library rather than a standalone program.
This might help:
http://www.tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
Also, read the section on C-language functions in the manuals.
Also, you're clearly missing bound-checking on your various copy
operations, and I think you're supposed to use palloc() rather than
malloc() if this is supposed to sit inside PostgreSQL.
Bear in mind it's been 10 years since I wrote any C though, so use your
own judgement on my advice.
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2005-08-05 10:48 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-08-05 08:51 Make C file for create type Louise Catherine <r1c4n@yahoo.com>
2005-08-05 10:48 ` Richard Huxton <dev@archonet.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox