aboutsummaryrefslogtreecommitdiff
path: root/query.c
blob: 09e757839904de285ce721983b33451ea08287d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "query.h"

void
setqs()
{
	qs = getenv("QUERY_STRING");
	if(!qs){
		fprintf(stderr, "no QUERY_STRING\n");
		exit(1);
	}
}

char *
query(char *key)
{
	char *w;
	int n;
	
	for(w = strtok(qs, "&"); w; w = strtok(NULL, "&")){
		n = strcspn(w, "=");
		if(strncmp(w, key, n) == 0)
			return w + n + (w[n] == '=');
	}
	
	return NULL;
}