tarfix  1.0
About: Tools for processing damaged tar archive files
  Fossies Dox: tarfix-1.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

 All Data Structures Files Functions Variables Macros
tarl.c
Go to the documentation of this file.
1 #include <stdio.h>
2 
3 #define NAMSIZ 100
4 struct matches {
5  int offset;
6  char value;
7 } matches[] = {
8  NAMSIZ+6, ' ',
9  NAMSIZ+7, '\0',
10  NAMSIZ+8+6, ' ',
11  NAMSIZ+8+7, '\0',
12  NAMSIZ+16+6, ' ',
13  NAMSIZ+16+7, '\0',
14  NAMSIZ+24+11, ' ',
15  NAMSIZ+36+11, ' ',
16  NAMSIZ+48+6, '\0',
17  0, 0,
18 };
19 
20 int
21 istar(block)
22 char *block;
23 {
24  int loop;
25 
26  for (loop = 0; matches[loop].offset != 0; loop++)
27  if (block[matches[loop].offset] != matches[loop].value)
28  return(0);
29  return(1);
30 }
31 
32 char buf[10240];
33 int bad;
34 int nleft = 0;
36 
38 {
39  int loop;
40  int dir;
41  char *block;
42  extern char *readblock();
43 
44  bad = 0;
45 
46  for(;;) {
47  block = readblock(0);
48 
49  if (block != NULL && istar(block))
50  printf("%s\n", block);
51  }
52 }
53 
54 char *
55 readblock(desc)
56 int desc;
57 {
58  int count;
59 
60  if (nleft > 0) {
61  whichnow++;
62  nleft--;
63  return(buf+whichnow*512);
64  }
65 
66  count = read(desc, buf, (int)sizeof(buf));
67  if (count <= 0 || count%512 != 0) {
68  if (count == 0)
69  printf("---apparent EOF\n");
70  else
71  printf("---error\n");
72  if (bad > 20)
73  exit(1);
74  bad++;
75  return(NULL);
76  }
77  bad = 0;
78  whichnow = 0;
79  nleft = count/512 - 1;
80  return(buf);
81 }