add buffering to java test progs
[lttv.git] / trunk / masters-pmf / java_speed_test / c / main.c
1 #define _LARGEFILE_SOURCE
2 #define _FILE_OFFSET_BITS 64
3
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <unistd.h>
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 int main(int argc, char **argv)
14 {
15 int result;
16 FILE *fp;
17 int print = 0;
18
19 if(argc >= 2 && !strcmp(argv[1], "-p"))
20 print = 1;
21
22 fp = fopen("../trace.dat", "r");
23 if(fp == NULL) {
24 perror("fopen");
25 return 1;
26 }
27
28 while(1) {
29 unsigned long timestamp;
30 unsigned short id;
31 unsigned char arglen;
32 char *args;
33
34 fscanf(fp, "%4c", &timestamp);
35 if(feof(fp))
36 break;
37
38 fscanf(fp, "%2c", &id);
39
40 fscanf(fp, "%1c", &arglen);
41
42 args = malloc(arglen);
43
44 // manually specify length of args
45 fscanf(fp, "%15c", args);
46
47 unsigned short arg1;
48 char *arg2;
49
50 arg1 = *(unsigned short *)args;
51 arg2 = args+2;
52
53 if(print)
54 printf("timestamp %lu id %hu args=(arg1=%hu arg2=\"%s\")\n", timestamp, id, arg1, arg2);
55
56 free(args);
57
58 }
59 fclose(fp);
60
61 return 0;
62 }
This page took 0.03116 seconds and 5 git commands to generate.