-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframes.c
44 lines (35 loc) · 849 Bytes
/
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
/* frames.c */
#include <stdlib.h>
#include "list.h"
/* alloc_frame*/
int alloc_frame(List *frames) {
int frame_number, *data;
if (list_size(frames) == 0) {
/* Remove 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 -1;
}