show worst latencies as well
[tridge/junkcode.git] / pread.c
1 #define _XOPEN_SOURCE 500
2
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <errno.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include <string.h>
9
10 static void pread_file(const char *fname)
11 {
12         int fd;
13         char buf[61440];
14         off_t ofs = 0;
15
16         fd = open(fname, O_RDONLY);
17         if (fd == -1) {
18                 perror(fname);
19                 return;
20         }
21
22         while (1) {
23                 ssize_t ret = pread(fd, buf, sizeof(buf), ofs);
24                 if (ret <= 0) {
25                         printf("read error at ofs %lld - gave %d (%s)\n", 
26                                (long long)ofs, (int)ret, strerror(errno));
27                         break;
28                 }
29                 ofs += ret;             
30         }
31         close(fd);
32 }
33
34 int main(int argc, const char *argv[])
35 {
36         int i;
37         for (i=1;i<argc;i++) {
38                 pread_file(argv[i]);
39         }
40         return 0;
41 }