annotate lwar/replace.c @ 188:bb2665c7005c

Added --extract and --replace to lwar
author lost
date Sun, 22 Mar 2009 06:51:48 +0000
parents
children bae1e3ecdce1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
188
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
1 /*
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
2 replace.c
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
4
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
5 This file is part of LWAR.
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
6
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
7 LWAR is free software: you can redistribute it and/or modify it under the
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
10 version.
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
11
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
15 more details.
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
16
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
19
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
20 */
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
21
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
22 #ifdef HAVE_CONFIG_H
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
23 #include "config.h"
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
24 #endif
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
25
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
26 #include <errno.h>
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
27 #include <stdio.h>
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
28 #include <stdlib.h>
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
29 #include <string.h>
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
30
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
31 #include "lwar.h"
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
32
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
33 void do_replace(void)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
34 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
35 FILE *f;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
36 FILE *nf;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
37 unsigned char buf[8];
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
38 long l;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
39 int c;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
40 FILE *f2;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
41 int i;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
42 char fnbuf[1024];
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
43 char fnbuf2[1024];
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
44
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
45 sprintf(fnbuf, "%s.tmp", archive_file);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
46
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
47 f = fopen(archive_file, "r+");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
48 if (!f)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
49 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
50 if (errno == ENOENT)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
51 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
52 nf = fopen(fnbuf, "w");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
53 if (nf)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
54 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
55 fputs("LWAR1V", nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
56 goto doadd;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
57 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
58 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
59 perror("Cannot open archive file");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
60 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
61
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
62 fread(buf, 1, 6, f);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
63 if (memcmp("LWAR1V", buf, 6))
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
64 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
65 fprintf(stderr, "%s is not a valid archive file.\n", archive_file);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
66 exit(1);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
67 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
68
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
69 nf = fopen(fnbuf, "w");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
70 if (!nf)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
71 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
72 perror("Cannot create temp archive file");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
73 exit(1);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
74 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
75
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
76 fputs("LWAR1V", nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
77
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
78 for (;;)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
79 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
80 c = fgetc(f);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
81 if (c == EOF && ferror(f))
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
82 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
83 perror("Reading archive file");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
84 exit(1);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
85 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
86 if (c == EOF)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
87 goto doadd;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
88
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
89 if (!c)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
90 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
91 goto doadd;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
92 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
93
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
94 // find the end of the file name
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
95 i = 0;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
96 while (c)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
97 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
98 fnbuf2[i++] = c;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
99 c = fgetc(f);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
100 if (c == EOF || ferror(f))
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
101 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
102 fprintf(stderr, "Bad archive file\n");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
103 exit(1);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
104 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
105 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
106 fnbuf2[i] = 0;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
107
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
108 // get length of archive member
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
109 l = 0;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
110 c = fgetc(f);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
111 l = c << 24;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
112 c = fgetc(f);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
113 l |= c << 16;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
114 c = fgetc(f);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
115 l |= c << 8;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
116 c = fgetc(f);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
117 l |= c;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
118
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
119 // is it a file we are replacing? if so, do not copy it
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
120 for (i = 0; i < nfiles; i++)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
121 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
122 if (!strcmp(files[i], fnbuf2))
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
123 break;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
124 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
125 if (i < nfiles)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
126 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
127 fseek(f, l, SEEK_CUR);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
128 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
129 else
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
130 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
131 // otherwise, copy it
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
132 fprintf(nf, "%s", fnbuf2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
133 fputc(0, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
134 fputc(l >> 24, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
135 fputc((l >> 16) & 0xff, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
136 fputc((l >> 8) & 0xff, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
137 fputc(l & 0xff, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
138 while (l)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
139 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
140 c = fgetc(f);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
141 fputc(c, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
142 l--;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
143 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
144 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
145 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
146
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
147 // done with the original file
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
148 fclose(f);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
149 doadd:
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
150 for (i = 0; i < nfiles; i++)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
151 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
152 f2 = fopen(files[i], "r");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
153 if (!f2)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
154 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
155 fprintf(stderr, "Cannot open file %s:", files[i]);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
156 perror("");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
157 exit(1);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
158 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
159 fread(buf, 1, 6, f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
160 if (mergeflag && !memcmp("LWAR1V", buf, 6))
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
161 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
162 // add archive contents...
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
163 for (;;)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
164 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
165 c = fgetc(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
166 if (c == EOF || ferror(f2))
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
167 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
168 perror("Reading input archive file");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
169 exit(1);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
170 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
171 if (c == EOF)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
172 break;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
173
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
174 if (!c)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
175 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
176 break;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
177 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
178
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
179 // find the end of the file name
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
180 while (c)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
181 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
182 fputc(c, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
183 c = fgetc(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
184 if (c == EOF || ferror(f))
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
185 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
186 fprintf(stderr, "Bad input archive file\n");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
187 exit(1);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
188 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
189 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
190 fputc(0, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
191
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
192 // get length of archive member
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
193 l = 0;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
194 c = fgetc(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
195 fputc(c, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
196 l = c << 24;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
197 c = fgetc(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
198 fputc(c, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
199 l |= c << 16;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
200 c = fgetc(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
201 fputc(c, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
202 l |= c << 8;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
203 c = fgetc(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
204 fputc(c, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
205 l |= c;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
206
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
207 while (l)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
208 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
209 c = fgetc(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
210 fputc(c, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
211 l--;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
212 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
213 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
214
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
215 fclose(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
216 continue;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
217 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
218 fseek(f2, 0, SEEK_END);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
219 l = ftell(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
220 fseek(f2, 0, SEEK_SET);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
221 fputs(files[i], nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
222 fputc(0, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
223 fputc(l >> 24, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
224 fputc((l >> 16) & 0xff, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
225 fputc((l >> 8) & 0xff, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
226 fputc(l & 0xff, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
227 while (l)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
228 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
229 c = fgetc(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
230 fputc(c, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
231 l--;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
232 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
233 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
234
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
235 // flag end of file
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
236 fputc(0, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
237
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
238 fclose(nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
239
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
240 if (rename(fnbuf, archive_file) < 0)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
241 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
242 perror("Cannot replace old archive file");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
243 unlink(fnbuf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
244 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
245 }