Why this cgi library ?

There are some other CGI helper libraries around on the internet, but none of those really fits my requirements. Some of them are rather bloated and therefore slow (on my hardware), but none of the ones I found had functions to use HTML templates.
In my opinion, a cgi library without HTML templates is more or less useless, because you would have to hardcode all HTML inside the CGI programs.


The programming API

NOTE: This API overview is far away from being complete !
Have a look at the include file to find more functions !

Config file functions

int cgi_readconfig(cgi_ctx c, char *file);	/* read a config file */
char *cgi_get_configval(cgi_ctx c, char *key);	/* get value of key */

HTML template functions

int cgi_tmpl_open(cgi_ctx c, char *f)	/* open a html template file */
int cgi_tmpl_set(cgi_ctx c, char *k, char *v);
int cgi_tmpl_print(cgi_ctx c);		/* print the template to stdout */

Short example

This short example opens a template file, fills in a testcookie (if set), a form testvalue (if set) and then displays the template.

int main(int argc, char **argv)
	char *p;
	cgi_ctx	mycgi = NULL;

	if((mycgi=cgi_initlib()) == NULL) {
		fatal_error("out of memory");
	if(cgi_requestmethod(mycgi) != REQ_M_GET) {
		cgi_errlog("programm not called with GET");
		cgi_exit_status_405(mycgi, "GET");
	cgi_tmpl_open(mycgi, "example.tmpl");
	if((p=cgi_get_formval(mycgi, "test")) != NULL) {
		cgi_tmpl_set(mycgi, "form_test", p);
	if((p=cgi_get_cookieval(mycgi, "TEST")) != NULL) {
		cgi_tmpl_set(mycgi, "cookie_test", p);
	cgi_sendheader(mycgi, 200, "text/html");
	return 0;