-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdumpdev.c
More file actions
65 lines (52 loc) · 1014 Bytes
/
dumpdev.c
File metadata and controls
65 lines (52 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "util.h"
int main(int argc, char* argv[]) {
int rc, fd;
const char * path;
if (argc < 2) {
return -1;
}
path = argv[1];
fd = open(path, O_RDONLY);
if (fd < 0) {
perror(path);
close(fd);
return -1;
}
{
unsigned int num = 0;
double start = getTimestamp();
double previous = start;
while (1) {
char buffer[256];
int len = read(fd, buffer, sizeof(buffer));
double now = getTimestamp();
int i;
if (len < 0) {
perror(path);
close(fd);
return -1;
}
num++;
printf("#%-5d t: %5.3f dt: %5.4f len: %2d", num, now - start, now - previous, len);
if (len == 0) {
printf(" EOF\n");
return 0;
}
if (len <= 16) {
hex_dump(buffer, len, 0, " | ", "");
} else {
hex_dump(buffer, len, 1, "\n >>> ", " ... ");
}
previous = now;
}
}
}