Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / pmax / test / sum.c
blobb6b4f87f3af5fbe80941c904e8f43671f5bc492b
1 #include <sys/param.h>
2 #include <sys/exec.h>
4 /*
5 * Print simple check sum for text and data section.
6 */
7 void
8 main(argc, argv)
9 int argc;
10 char **argv;
12 register int fd, i, n;
13 char *fname;
14 struct coff_exec ex;
15 int tsum, dsum, word;
17 if (argc < 2) {
18 printf("usage: sum <file>\n");
19 goto err;
21 if ((fd = open(fname = argv[1], 0)) < 0)
22 goto err;
24 /* read the COFF header */
25 i = read(fd, (char *)&ex, sizeof(ex));
26 if (i != sizeof(ex) || COFF_BADMAG(ex)) {
27 printf("No COFF header\n");
28 goto cerr;
30 if (lseek(fd, COFF_TEXTOFF(ex), 0)) {
31 perror("lseek");
32 goto cerr;
34 tsum = 0;
35 for (n = ex.aouthdr.tsize; n > 0; n -= sizeof(int)) {
36 if (read(fd, &word, sizeof(word)) != sizeof(word)) {
37 perror("read text");
38 goto cerr;
40 tsum += word;
42 dsum = 0;
43 for (n = ex.aouthdr.dsize; n > 0; n -= sizeof(int)) {
44 if (read(fd, &word, sizeof(word)) != sizeof(word)) {
45 perror("read data");
46 goto cerr;
48 dsum += word;
50 printf("tsum %d dsum %d\n", tsum, dsum);
52 cerr:
53 close(fd);
54 err:
55 exit(0);