-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpickrecord.c
More file actions
91 lines (77 loc) · 1.78 KB
/
pickrecord.c
File metadata and controls
91 lines (77 loc) · 1.78 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* pickrecord.c:
*
* Copyright (c) 2005 Tiankai Tu
* All rights reserved. May not be used, modified, or copied
* without permission.
*
* Contact:
* Tiankai Tu
* Computer Science Department
* Carnegie Mellon University
* 5000 Forbes Avenue
* Pittsburgh, PA 15213
* tutk@cs.cmu.edu
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include "xplatform.h"
int main(int argc, char **argv)
{
FILE *cvmfp;
off_t offset;
int ini, inj, ink;
int i, j, k;
endian_t targetformat, myformat;
if (argc != 4) {
printf("\nusage: pickrecord cvmfile format offset\n");
exit(1);
}
cvmfp = fopen(argv[1], "r");
if (cvmfp == NULL) {
perror("fopen");
exit(1);
}
if (strcmp(argv[2], "little") == 0) {
targetformat = little;
} else if (strcmp(argv[2], "big") == 0) {
targetformat = big;
} else {
fprintf(stderr, "Unknown target data format\n");
exit(1);
}
sscanf(argv[3], "%qd", &offset);
#ifdef BIGBEN
if (fseek(cvmfp, offset, SEEK_SET) != 0) {
perror("fseeko");
exit(1);
}
#else
if (fseeko(cvmfp, offset, SEEK_SET) != 0) {
perror("fseeko");
exit(1);
}
#endif
if ((fread(&ini, 4, 1, cvmfp) != 1) ||
(fread(&inj, 4, 1, cvmfp) != 1) ||
(fread(&ink, 4, 1, cvmfp) != 1)) {
perror("fread");
exit(1);
}
myformat = xplatform_testendian();
if (myformat == targetformat) {
i = ini;
j = inj;
k = ink;
} else {
xplatform_swapbytes(&i, &ini, 4);
xplatform_swapbytes(&j, &inj, 4);
xplatform_swapbytes(&k, &ink, 4);
}
printf("(i, j, k) = {%d, %d, %d}\n", i, j, k);
fclose(cvmfp);
return 0;
}