… | |
… | |
9 | * |
9 | * |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
12 | * documentation and/or other materials provided with the distribution. |
13 | * |
13 | * |
14 | * 3. The name of the author may not be used to endorse or promote products |
|
|
15 | * derived from this software without specific prior written permission. |
|
|
16 | * |
|
|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- |
15 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- |
19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
16 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- |
17 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- |
21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
18 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
… | |
… | |
24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- |
21 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- |
25 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
22 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
26 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
23 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * |
24 | * |
28 | * Alternatively, the contents of this file may be used under the terms of |
25 | * Alternatively, the contents of this file may be used under the terms of |
29 | * the GNU General Public License version 2 (the "GPL"), in which case the |
26 | * the GNU General Public License ("GPL") version 2 or any later version, |
30 | * provisions of the GPL are applicable instead of the above. If you wish to |
27 | * in which case the provisions of the GPL are applicable instead of |
31 | * allow the use of your version of this file only under the terms of the |
28 | * the above. If you wish to allow the use of your version of this file |
32 | * GPL and not to allow others to use your version of this file under the |
29 | * only under the terms of the GPL and not to allow others to use your |
33 | * BSD license, indicate your decision by deleting the provisions above and |
30 | * version of this file under the BSD license, indicate your decision |
34 | * replace them with the notice and other provisions required by the GPL. If |
31 | * by deleting the provisions above and replace them with the notice |
35 | * you do not delete the provisions above, a recipient may use your version |
32 | * and other provisions required by the GPL. If you do not delete the |
36 | * of this file under either the BSD or the GPL License. |
33 | * provisions above, a recipient may use your version of this file under |
|
|
34 | * either the BSD or the GPL. |
37 | */ |
35 | */ |
38 | |
36 | |
39 | #include "config.h" |
37 | #include "config.h" |
40 | #include <stdio.h> |
38 | #include <stdio.h> |
41 | #include <string.h> |
39 | #include <string.h> |
… | |
… | |
321 | |
319 | |
322 | if (force) |
320 | if (force) |
323 | m = 0; |
321 | m = 0; |
324 | |
322 | |
325 | fd = open (name, O_CREAT | O_WRONLY | O_TRUNC | m, 600); |
323 | fd = open (name, O_CREAT | O_WRONLY | O_TRUNC | m, 600); |
|
|
324 | #if defined(__MINGW32__) |
|
|
325 | _setmode(fd, _O_BINARY); |
|
|
326 | #endif |
326 | return fd; |
327 | return fd; |
327 | } |
328 | } |
328 | |
329 | |
329 | static int |
330 | static int |
330 | compose_name (const char *fname, char *oname) |
331 | compose_name (const char *fname, char *oname) |
… | |
… | |
374 | |
375 | |
375 | if (mode != lzcat) |
376 | if (mode != lzcat) |
376 | if (compose_name (fname, oname)) |
377 | if (compose_name (fname, oname)) |
377 | return -1; |
378 | return -1; |
378 | |
379 | |
|
|
380 | #if !defined(__MINGW32__) |
379 | rc = lstat (fname, &mystat); |
381 | rc = lstat (fname, &mystat); |
|
|
382 | #else |
|
|
383 | rc = stat (fname, &mystat); |
|
|
384 | #endif |
380 | fd = open (fname, O_RDONLY); |
385 | fd = open (fname, O_RDONLY); |
|
|
386 | #if defined(__MINGW32__) |
|
|
387 | _setmode(fd, _O_BINARY); |
|
|
388 | #endif |
381 | if (rc || fd == -1) |
389 | if (rc || fd == -1) |
382 | { |
390 | { |
383 | fprintf (stderr, "%s: %s: ", imagename, fname); |
391 | fprintf (stderr, "%s: %s: ", imagename, fname); |
384 | perror (""); |
392 | perror (""); |
385 | return -1; |
393 | return -1; |
… | |
… | |
421 | if (!rc && verbose) |
429 | if (!rc && verbose) |
422 | fprintf (stderr, "%s: %5.1f%% -- replaced with %s\n", |
430 | fprintf (stderr, "%s: %5.1f%% -- replaced with %s\n", |
423 | fname, nr_written == 0 ? 0 : 100.0 - nr_read / ((double) nr_written / 100.0), oname); |
431 | fname, nr_written == 0 ? 0 : 100.0 - nr_read / ((double) nr_written / 100.0), oname); |
424 | } |
432 | } |
425 | |
433 | |
|
|
434 | #if !defined(__MINGW32__) |
426 | fchmod (fd2, mystat.st_mode); |
435 | fchmod (fd2, mystat.st_mode); |
|
|
436 | #else |
|
|
437 | chmod (oname, mystat.st_mode); |
|
|
438 | #endif |
427 | close (fd); |
439 | close (fd); |
428 | close (fd2); |
440 | close (fd2); |
429 | |
441 | |
430 | if (!rc) |
442 | if (!rc) |
431 | unlink (fname); |
443 | unlink (fname); |