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 30 31 32 33 34 35 36 37 38 39 40 | typedef struct __MAILOP_RECORD_{
struct com_list_head list;
char filename[16];
char code[32];
char id[16];
}sop;
int listtest(int argc, char **argv){
struct com_list_head *node;
sop *loghead;
sop *lognode;
loghead = (sop * )calloc(1, sizeof(sop));
com_INIT_LIST_HEAD(&loghead->list);
loghead->filename[0] = 'a';
lognode =(sop * )calloc(1, sizeof(sop));
lognode->filename[0] = 'b';
com_list_add(&lognode->list, &loghead->list);
lognode =(sop * )calloc(1, sizeof(sop));
lognode->filename[0] = 'c';
com_list_add_tail(&lognode->list, &loghead->list);
com_list_for_each(node, &loghead->list){
lognode = com_list_entry(node, sop, list);
printf("--%s--\n", lognode->filename);
}
printf("--%s--\n", loghead->filename);
return 0;
}
|
Tags: list
free the list
eyou_list_for_each_safe(node, tmp, &loghead->list){ lognode = eyou_list_entry(node, sop, list); printf("free: %d\n", lognode);
//and free the memory } eyou_list_del(&loghead->list);