annotate lwar/replace.c @ 286:701132971855 2.3

Fixed regression related to force linking a library file
author lost
date Sat, 25 Apr 2009 02:18:06 +0000
parents bae1e3ecdce1
children
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
212
bae1e3ecdce1 More preparation for gnulib integration
lost
parents: 188
diff changeset
22 #include <config.h>
188
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
23
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
24 #include <errno.h>
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
25 #include <stdio.h>
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
26 #include <stdlib.h>
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
27 #include <string.h>
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
28
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
29 #include "lwar.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 void do_replace(void)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
32 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
33 FILE *f;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
34 FILE *nf;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
35 unsigned char buf[8];
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
36 long l;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
37 int c;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
38 FILE *f2;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
39 int i;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
40 char fnbuf[1024];
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
41 char fnbuf2[1024];
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
42
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
43 sprintf(fnbuf, "%s.tmp", archive_file);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
44
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
45 f = fopen(archive_file, "r+");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
46 if (!f)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
47 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
48 if (errno == ENOENT)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
49 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
50 nf = fopen(fnbuf, "w");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
51 if (nf)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
52 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
53 fputs("LWAR1V", nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
54 goto doadd;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
55 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
56 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
57 perror("Cannot open archive file");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
58 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
59
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
60 fread(buf, 1, 6, f);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
61 if (memcmp("LWAR1V", buf, 6))
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
62 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
63 fprintf(stderr, "%s is not a valid archive file.\n", archive_file);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
64 exit(1);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
65 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
66
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
67 nf = fopen(fnbuf, "w");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
68 if (!nf)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
69 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
70 perror("Cannot create temp archive file");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
71 exit(1);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
72 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
73
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
74 fputs("LWAR1V", nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
75
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
76 for (;;)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
77 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
78 c = fgetc(f);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
79 if (c == EOF && ferror(f))
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
80 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
81 perror("Reading archive file");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
82 exit(1);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
83 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
84 if (c == EOF)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
85 goto doadd;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
86
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
87 if (!c)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
88 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
89 goto doadd;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
90 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
91
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
92 // find the end of the file name
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
93 i = 0;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
94 while (c)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
95 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
96 fnbuf2[i++] = c;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
97 c = fgetc(f);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
98 if (c == EOF || ferror(f))
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
99 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
100 fprintf(stderr, "Bad archive file\n");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
101 exit(1);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
102 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
103 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
104 fnbuf2[i] = 0;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
105
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
106 // get length of archive member
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
107 l = 0;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
108 c = fgetc(f);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
109 l = c << 24;
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 << 16;
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 << 8;
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;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
116
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
117 // is it a file we are replacing? if so, do not copy it
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
118 for (i = 0; i < nfiles; i++)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
119 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
120 if (!strcmp(files[i], fnbuf2))
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
121 break;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
122 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
123 if (i < nfiles)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
124 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
125 fseek(f, l, SEEK_CUR);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
126 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
127 else
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
128 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
129 // otherwise, copy it
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
130 fprintf(nf, "%s", fnbuf2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
131 fputc(0, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
132 fputc(l >> 24, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
133 fputc((l >> 16) & 0xff, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
134 fputc((l >> 8) & 0xff, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
135 fputc(l & 0xff, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
136 while (l)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
137 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
138 c = fgetc(f);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
139 fputc(c, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
140 l--;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
141 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
142 }
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 // done with the original file
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
146 fclose(f);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
147 doadd:
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
148 for (i = 0; i < nfiles; i++)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
149 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
150 f2 = fopen(files[i], "r");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
151 if (!f2)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
152 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
153 fprintf(stderr, "Cannot open file %s:", files[i]);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
154 perror("");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
155 exit(1);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
156 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
157 fread(buf, 1, 6, f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
158 if (mergeflag && !memcmp("LWAR1V", buf, 6))
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
159 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
160 // add archive contents...
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
161 for (;;)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
162 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
163 c = fgetc(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
164 if (c == EOF || ferror(f2))
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
165 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
166 perror("Reading input archive file");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
167 exit(1);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
168 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
169 if (c == EOF)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
170 break;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
171
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
172 if (!c)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
173 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
174 break;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
175 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
176
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
177 // find the end of the file name
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
178 while (c)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
179 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
180 fputc(c, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
181 c = fgetc(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
182 if (c == EOF || ferror(f))
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
183 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
184 fprintf(stderr, "Bad input archive file\n");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
185 exit(1);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
186 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
187 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
188 fputc(0, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
189
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
190 // get length of archive member
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
191 l = 0;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
192 c = fgetc(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
193 fputc(c, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
194 l = c << 24;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
195 c = fgetc(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
196 fputc(c, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
197 l |= c << 16;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
198 c = fgetc(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
199 fputc(c, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
200 l |= c << 8;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
201 c = fgetc(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
202 fputc(c, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
203 l |= c;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
204
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
205 while (l)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
206 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
207 c = fgetc(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
208 fputc(c, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
209 l--;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
210 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
211 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
212
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
213 fclose(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
214 continue;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
215 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
216 fseek(f2, 0, SEEK_END);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
217 l = ftell(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
218 fseek(f2, 0, SEEK_SET);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
219 fputs(files[i], nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
220 fputc(0, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
221 fputc(l >> 24, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
222 fputc((l >> 16) & 0xff, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
223 fputc((l >> 8) & 0xff, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
224 fputc(l & 0xff, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
225 while (l)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
226 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
227 c = fgetc(f2);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
228 fputc(c, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
229 l--;
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
230 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
231 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
232
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
233 // flag end of file
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
234 fputc(0, nf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
235
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
236 fclose(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 if (rename(fnbuf, archive_file) < 0)
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
239 {
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
240 perror("Cannot replace old archive file");
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
241 unlink(fnbuf);
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
242 }
bb2665c7005c Added --extract and --replace to lwar
lost
parents:
diff changeset
243 }