forked from sysprog21/fibdrv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.c
43 lines (36 loc) · 887 Bytes
/
client.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
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "bignum.h"
#define FIB_DEV "/dev/fibonacci"
int main(int argc, char *argv[])
{
if (argc < 2) {
printf("not enough argument\n");
return -1;
}
char buf[100000];
int offset = atoi(argv[2]);
int func = atoi(argv[1]);
/* 0 -> dp, 1 -> fast_doubling */
int fd = open(FIB_DEV, O_RDWR);
if (fd < 0) {
perror("Failed to open character device");
exit(1);
}
lseek(fd, func, SEEK_SET);
if (!write(fd, NULL, 0)) {
printf("not accurate function setting\n");
return -1;
}
lseek(fd, offset, SEEK_SET);
for (int j = 0; j < 100; j++) {
long long time_ns = read(fd, buf, sizeof(buf));
printf("%lld\n", time_ns);
}
close(fd);
return 0;
}