X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=razip.c;h=825e73268114736530e35415f19f47af23dac03e;hb=70c740facc966321754c6bfcc6d61ea056480638;hp=0b67c6c50cf62f4ccb12948fdf96dbc813633b87;hpb=f93dae0d03856955f9424e8b2aaf261304ca647e;p=samtools.git diff --git a/razip.c b/razip.c index 0b67c6c..825e732 100644 --- a/razip.c +++ b/razip.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include "razf.h" #define WINDOW_SIZE 4096 @@ -25,7 +27,7 @@ static int write_open(const char *fn, int is_forced) int fd = -1; char c; if (!is_forced) { - if ((fd = open(fn, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0644)) < 0 && errno == EEXIST) { + if ((fd = open(fn, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0666)) < 0 && errno == EEXIST) { printf("razip: %s already exists; do you wish to overwrite (y or n)? ", fn); scanf("%c", &c); if (c != 'Y' && c != 'y') { @@ -35,7 +37,7 @@ static int write_open(const char *fn, int is_forced) } } if (fd < 0) { - if ((fd = open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) { + if ((fd = open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) { fprintf(stderr, "razip: %s: Fail to write\n", fn); exit(1); } @@ -92,7 +94,7 @@ int main(int argc, char **argv) buffer = malloc(WINDOW_SIZE); while((c = read(f_src, buffer, WINDOW_SIZE)) > 0) razf_write(rz, buffer, c); razf_close(rz); // f_dst will be closed here - if (argc > optind) unlink(argv[optind]); + if (argc > optind && !pstdout) unlink(argv[optind]); free(buffer); close(f_src); return 0;