… | |
… | |
8 | * this list of conditions and the following disclaimer. |
8 | * this list of conditions and the following disclaimer. |
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 | * |
|
|
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 | * |
13 | * |
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- |
… | |
… | |
321 | |
318 | |
322 | if (force) |
319 | if (force) |
323 | m = 0; |
320 | m = 0; |
324 | |
321 | |
325 | fd = open (name, O_CREAT | O_WRONLY | O_TRUNC | m, 600); |
322 | fd = open (name, O_CREAT | O_WRONLY | O_TRUNC | m, 600); |
|
|
323 | #if defined(__MINGW32__) |
|
|
324 | _setmode(fd, _O_BINARY); |
|
|
325 | #endif |
326 | return fd; |
326 | return fd; |
327 | } |
327 | } |
328 | |
328 | |
329 | static int |
329 | static int |
330 | compose_name (const char *fname, char *oname) |
330 | compose_name (const char *fname, char *oname) |
… | |
… | |
374 | |
374 | |
375 | if (mode != lzcat) |
375 | if (mode != lzcat) |
376 | if (compose_name (fname, oname)) |
376 | if (compose_name (fname, oname)) |
377 | return -1; |
377 | return -1; |
378 | |
378 | |
|
|
379 | #if !defined(__MINGW32__) |
379 | rc = lstat (fname, &mystat); |
380 | rc = lstat (fname, &mystat); |
|
|
381 | #else |
|
|
382 | rc = stat (fname, &mystat); |
|
|
383 | #endif |
380 | fd = open (fname, O_RDONLY); |
384 | fd = open (fname, O_RDONLY); |
|
|
385 | #if defined(__MINGW32__) |
|
|
386 | _setmode(fd, _O_BINARY); |
|
|
387 | #endif |
381 | if (rc || fd == -1) |
388 | if (rc || fd == -1) |
382 | { |
389 | { |
383 | fprintf (stderr, "%s: %s: ", imagename, fname); |
390 | fprintf (stderr, "%s: %s: ", imagename, fname); |
384 | perror (""); |
391 | perror (""); |
385 | return -1; |
392 | return -1; |
… | |
… | |
421 | if (!rc && verbose) |
428 | if (!rc && verbose) |
422 | fprintf (stderr, "%s: %5.1f%% -- replaced with %s\n", |
429 | 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); |
430 | fname, nr_written == 0 ? 0 : 100.0 - nr_read / ((double) nr_written / 100.0), oname); |
424 | } |
431 | } |
425 | |
432 | |
|
|
433 | #if !defined(__MINGW32__) |
426 | fchmod (fd2, mystat.st_mode); |
434 | fchmod (fd2, mystat.st_mode); |
|
|
435 | #else |
|
|
436 | chmod (oname, mystat.st_mode); |
|
|
437 | #endif |
427 | close (fd); |
438 | close (fd); |
428 | close (fd2); |
439 | close (fd2); |
429 | |
440 | |
430 | if (!rc) |
441 | if (!rc) |
431 | unlink (fname); |
442 | unlink (fname); |