updates to speed test
[lttv.git] / trunk / masters-pmf / java_speed_test / c / main.c
CommitLineData
f65716cf 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>
ce68a724 8#include <string.h>
f65716cf 9
ce68a724 10int main(int argc, char **argv)
f65716cf 11{
12 int result;
13 int fd;
ce68a724 14 int print = 0;
15
16 if(argc >= 2 && !strcmp(argv[1], "-p"))
17 print = 1;
f65716cf 18
19 result = fd = open("../trace.dat", O_RDONLY);
20 if(result == -1) {
21 perror("open");
22 return 1;
23 }
24
25 while(1) {
26 unsigned long timestamp;
27 unsigned short id;
28 unsigned char arglen;
29 char *args;
30
31 result = read(fd, &timestamp, 4);
32 if(result == 0)
33 break;
34 if(result < 4) {
35 perror("read");
36 return 1;
37 }
38
39 result = read(fd, &id, 2);
40 if(result < 2) {
41 perror("read");
42 return 1;
43 }
44
45 result = read(fd, &arglen, 1);
46 if(result < 1) {
47 perror("read");
48 return 1;
49 }
50
51 args = malloc(arglen);
52
53 result = read(fd, args, arglen);
54 if(result < arglen) {
55 perror("read");
56 return 1;
57 }
58
59 unsigned short arg1;
60 char *arg2;
61
62 arg1 = *(unsigned short *)args;
63 arg2 = args+2;
64
ce68a724 65 if(print)
66 printf("timestamp %lu id %hu args=(arg1=%hu arg2=\"%s\")\n", timestamp, id, arg1, arg2);
f65716cf 67
68 free(args);
69 }
70 close(fd);
71
72 return 0;
73}
This page took 0.024478 seconds and 4 git commands to generate.