-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframes.c
102 lines (93 loc) · 2.33 KB
/
frames.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* =====================================================================================
*
* Filename: frame.c
*
* Description: frame
*
* Version: 1.0
* Created: 2015年08月09日 18时19分11秒
* Revision: none
* Compiler: gcc
*
* Author: Chen Liang (),
* Organization:
*
* =====================================================================================
*/
#include <stdlib.h>
#include <stdio.h>
#include "frames.h"
#include "list.h"
int
alloc_frame(List *frames){
int frame_number,*data;
if(list_size(frames) == 0)
return -1;
else{
if (list_rem_next(frames,NULL,(void **)&data) != 0)
return -1;
else{
frame_number = *data;
free(data);
}
}
return frame_number;
}
int
free_frame(List *frames, int frame_number){
int *data;
if ((data = (int *)malloc(sizeof(int))) == NULL)
return -1;
*data = frame_number;
if (list_ins_next(frames, NULL,data) != 0)
return -1;
return 0;
}
void
destroy(void *data){
if (data){
free(data);
}
return;
}
/*
* === FUNCTION ======================================================================
* Name: main
* Description:
* =====================================================================================
*/
int
main ( int argc, char *argv[] )
{
List * list = (List *)malloc(sizeof(List));
list_init(list,destroy);
int *data = (int *)malloc(sizeof(int));
*data = 10;
list_ins_next(list,NULL,data);
data = (int *)malloc(sizeof(int));
*data = 20;
list_ins_next(list,NULL,data);
ListElmt * tempElmt = list->head;
int size = list_size(list);
printf("size: %d\n",size);
while (size >0){
int * temp = (int *)(tempElmt->data);
fprintf(stdout,"%d\n",*temp);
tempElmt = tempElmt->next;
size--;
}
tempElmt = list->head;
while (tempElmt){
if (list->destroy){
list->destroy(tempElmt->data);
printf("destroy is not null\n");
}else{
printf("destroy is null\n");
free(tempElmt->data);
}
tempElmt = tempElmt->next;
}
free(list);
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */