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