root/tags/rel_1-0-1/ext/http11/tst_init.c

Revision 4, 0.8 kB (checked in by zedshaw, 3 years ago)

initial import into trunk

Line 
1
2 #include "tst.h"
3 #include <stdio.h>
4 #include <stdlib.h>
5
6 struct tst *tst_init(int width)
7 {
8    struct tst *tst;
9    struct node *current_node;
10    int i;
11
12
13 if((tst = (struct tst *) calloc(1, sizeof(struct tst))) == NULL)
14    return NULL;
15
16 if ((tst->node_lines = (struct node_lines *) calloc(1, sizeof(struct node_lines))) == NULL)
17 {
18    free(tst);
19    return NULL;
20 }
21
22 tst->node_line_width = width;
23 tst->node_lines->next = NULL;
24 if ((tst->node_lines->node_line = (struct node *) calloc(width, sizeof(struct node))) == NULL)
25 {
26    free(tst->node_lines);
27    free(tst);
28    return NULL;
29 }
30
31 current_node = tst->node_lines->node_line;
32 tst->free_list = current_node;
33 for (i = 1; i < width; i++)
34 {
35    current_node->middle = &(tst->node_lines->node_line[i]);
36    current_node = current_node->middle;
37 }
38 current_node->middle = NULL;
39 return tst;
40 }
41
Note: See TracBrowser for help on using the browser.