14 void sighandler(int sig)
19 int main(int argc, char **argv)
23 time_t starttime, endtime;
27 int thisrec, numrecs, numuses, maxrec;
32 fprintf(stderr, "usage: speedrec recfile\n");
36 starttime = endtime = 0;
39 signal(SIGHUP, sighandler);
40 signal(SIGINT, sighandler);
41 signal(SIGTERM, sighandler);
44 ret = read(0, buf, sizeof(buf));
45 if((ret < 0) && (errno != EINTR))
47 perror("cannot read");
53 starttime = time(NULL);
59 ret = write(1, buf, datalen);
60 if((ret < 0) && (errno != EINTR))
62 perror("cannot write");
65 memmove(buf, buf + ret, datalen -= ret);
68 if((starttime == 0) || (endtime == 0) || (endtime == starttime))
72 thisrec = (int)(numbytes / ((long long)(endtime - starttime)));
73 if((fd = open(argv[1], O_RDWR | O_CREAT, 0666)) < 0)
78 recfile = fdopen(fd, "r+");
82 if(fscanf(recfile, "%i\n", &numuses) < 1)
84 if(fscanf(recfile, "%i\n", &maxrec) < 1)
86 if(fscanf(recfile, "%i\n", &numrecs) < 1)
88 for(i = 0; i < numrecs; i++)
89 fscanf(recfile, "%i\n", &recs[i]);
92 for(i = 0; i < 4; i++)
93 recs[i] = recs[i + 1];
96 recs[numrecs++] = thisrec;
99 fprintf(recfile, "%i\n", numuses + 1);
100 fprintf(recfile, "%i\n", (thisrec > maxrec)?thisrec:maxrec);
101 fprintf(recfile, "%i\n", numrecs);
102 for(i = 0; i < numrecs; i++)
103 fprintf(recfile, "%i\n", recs[i]);