-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrthreads.c
More file actions
50 lines (36 loc) · 938 Bytes
/
rthreads.c
File metadata and controls
50 lines (36 loc) · 938 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
#include "rthreads.h"
void *rt_thread(void* args) {
assert(args);
struct rt_args_t * params = (struct rt_args_t *) args;
struct list_t * filename_list = params->filename_list,
* file_list = params->file_list;
assert(params->filename_list);
assert(params->file_list);
void* restrict val;
FILE* restrict fp;
size_t sz = 0;
char* restrict fd;
while(1) {
val = pop_front(filename_list);
//printf("stuffing %d\t", params->done);
if(params->done)
return NULL;
if(!val)
continue;
//printf("%s\n", val);
fp = fopen((const char* restrict) val, "r");
if(fp) {
// Get size of file
fseek(fp, 0L, SEEK_END);
sz = ftell(fp);
fseek(fp, 0L, SEEK_SET);
// Allocate memory
fd = (char* restrict) malloc(sizeof(char) * sz + 1);
fread((void*) fd, sz, sizeof(char), fp);
fd[sz] = '\0';
push_back(file_list, fd, sz, (char * restrict) val, 0);
free(val);
}
}
return NULL;
}