-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinspact.c
62 lines (56 loc) · 1.83 KB
/
inspact.c
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
/*
* Copyright (c) 2017 ltlollo
* Licensed under the MIT license <LICENSE-MIT or
* http://opensource.org/licenses/MIT>. This file may not be copied,
* modified, or distributed except according to those terms.
*/
#include <stdio.h>
#include <err.h>
#include "splib.h"
#include "ebutil.h"
extern char *__progname;
static void usage(void);
int
main(int argc, char *argv[]) {
if (argc-1 < 1) {
usage();
errx(1, "not enough arguments");
}
Info spi;
FILE *file;
for (int i = 1; i < argc; ++i) {
if ((file = fopen(argv[i], "r")) == NULL) {
warn("%s could not be inspected", argv[i]);
continue;
}
if (fread(&spi, 1, sizeof(Info), file) == sizeof(Info)) {
spi.size = htole64(spi.size);
(void)printf("fsig: 0x%.2X, ele: %u, n: %u, m: %u, size: %lu; %s\n"
, spi.fsig, spi.ele, spi.n, spi.m, spi.size, argv[i]);
if (spi.fsig != FSIG) {
(void)fprintf(stderr, "%s: wrong file signature\n", argv[i]);
}
if (spi.ele > spi.m) {
(void)fprintf(stderr, "%s: wrong ele number\n", argv[i]);
}
if (spi.n > spi.m || spi.n < 2) {
(void)fprintf(stderr, "%s: wrong n number\n", argv[i]);
}
if (spi.m < 2) {
(void)fprintf(stderr, "%s: wrong m number\n", argv[i]);
}
} else {
warn("could read from %s", argv[i]);
}
(void)fclose(file);
}
return 0;
}
static void
usage(void) {
(void)fprintf(stderr, "Usage\t%s file [...files]"
"\n\tfile<string>: first input file"
"\n\tfils<strings>: additional input files"
"\nScope: show spac file infos of the arguments"
"\n", __progname);
}