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)
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Macros
targ.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;
35
int
whichnow
;
36
37
int
opened
= 0;
38
int
f
;
39
long
nwrite
;
40
41
main
(argc, argv)
42
int argc;
43
char
**argv;
44
{
45
int
loop;
46
char
*block;
47
extern
char
*
readblock
();
48
49
bad
= 0;
50
51
for
(;;) {
52
block =
readblock
(0);
53
54
if
(block != NULL)
55
doblock
(block, argc, argv);
56
}
57
}
58
59
doblock
(block, argc, argv)
60
char *block;
61
int
argc;
62
char
**argv;
63
{
64
int
count;
65
66
if
(
istar
(block)) {
67
if
(
opened
) {
68
printf(
"--- premature end\n"
);
69
close(
f
);
70
opened
= 0;
71
}
72
if
(
match
(block, argc, argv)) {
73
f
= creat(block, 0666);
74
if
(
f
< 0)
75
printf(
"--- unable to create %s\n"
, block);
76
else
{
77
opened
= 1;
78
sscanf(block+
NAMSIZ
+24,
"%lo"
, &
nwrite
);
79
printf(
"--- reading %s %ld\n"
, block,
nwrite
);
80
if
(
nwrite
<= 0) {
81
close(
f
);
82
opened
= 0;
83
printf(
"--- done\n"
);
84
}
85
}
86
}
87
}
else
{
88
if
(
opened
) {
89
count = (
nwrite
> 512) ? 512 : (
int
)
nwrite
;
90
write(
f
, block, count);
91
nwrite
-= count;
92
if
(
nwrite
<= 0) {
93
opened
= 0;
94
close(
f
);
95
printf(
"--- done\n"
);
96
}
97
}
98
}
99
}
100
101
int
102
match
(s, argc, argv)
103
char *s;
104
int
argc;
105
char
**argv;
106
{
107
int
i;
108
int
c;
109
110
for
(i = 1; i < argc; i++) {
111
if
(strncmp(s, argv[i], strlen(argv[i])) == 0) {
112
c = s[strlen(argv[i])];
113
if
(c ==
'\0'
|| c ==
'/'
)
114
return
(1);
115
}
116
}
117
return
(0);
118
}
119
120
char
*
121
readblock
(desc)
122
int desc;
123
{
124
int
count;
125
126
if
(
nleft
> 0) {
127
whichnow
++;
128
nleft
--;
129
return
(
buf
+
whichnow
*512);
130
}
131
132
count = read(desc,
buf
, (
int
)
sizeof
(
buf
));
133
if
(count <= 0 || count%512 != 0) {
134
if
(count == 0)
135
printf(
"---apparent EOF\n"
);
136
else
137
printf(
"---error\n"
);
138
if
(
bad
> 20)
139
exit(1);
140
bad
++;
141
return
(NULL);
142
}
143
bad
= 0;
144
whichnow
= 0;
145
nleft
= count/512 - 1;
146
return
(
buf
);
147
}
tarfix-1.0
tar_aids
targ.c
Generated by
1.8.3.1-20130402