-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframes.c
More file actions
66 lines (52 loc) · 891 Bytes
/
frames.c
File metadata and controls
66 lines (52 loc) · 891 Bytes
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
#include <stdlib.h>
#include "frames.h"
#include "list.h"
/*
alloc_frame
*/
int alloc_frame(List * frames)
{
int frame_number;
int * data;
if (list_size(frames) == 0)
/*
Return that there are no frames available.
*/
return -1;
else
{
if ((list_rem_next(frames, NULL, (void **)&data)) != 0)
/*
Return that a frame could not be retrieved.
*/
return -1;
else
{
/*
Store the number of the available frame.
*/
frame_number = *data;
free(data);
}
}
return frame_number;
}
/*
free_frame
*/
int free_frame(List * frames, int frame_number)
{
int * data;
/*
Allocate storage for the frame number.
*/
if ((data = (int *)malloc(sizeof(int))) == NULL)
return -1;
/*
Put the frame back in the list of available frames.
*/
*data = frame_number;
if ((list_ins_next(frames, NULL, data)) != 0)
return -1;
return 0;
}