e7bac623d9b14ac641e15b5d6ea35555d1685b5f
[lttv.git] / trunk / masters-pmf / java_speed_test / c / main.c
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <fcntl.h>
4 #include <unistd.h>
5
6 #include <stdio.h>
7 #include <stdlib.h>
8
9 int main()
10 {
11 int result;
12 int fd;
13
14 result = fd = open("../trace.dat", O_RDONLY);
15 if(result == -1) {
16 perror("open");
17 return 1;
18 }
19
20 while(1) {
21 unsigned long timestamp;
22 unsigned short id;
23 unsigned char arglen;
24 char *args;
25
26 result = read(fd, &timestamp, 4);
27 if(result == 0)
28 break;
29 if(result < 4) {
30 perror("read");
31 return 1;
32 }
33
34 result = read(fd, &id, 2);
35 if(result < 2) {
36 perror("read");
37 return 1;
38 }
39
40 result = read(fd, &arglen, 1);
41 if(result < 1) {
42 perror("read");
43 return 1;
44 }
45
46 args = malloc(arglen);
47
48 result = read(fd, args, arglen);
49 if(result < arglen) {
50 perror("read");
51 return 1;
52 }
53
54 unsigned short arg1;
55 char *arg2;
56
57 arg1 = *(unsigned short *)args;
58 arg2 = args+2;
59
60 printf("timestamp %u id %hu args=(arg1=%hu arg2=\"%s\")\n", timestamp, id, arg1, arg2);
61
62 free(args);
63 }
64 close(fd);
65
66 return 0;
67 }
This page took 0.030465 seconds and 3 git commands to generate.