diff --git a/programs/benchmark.c b/programs/benchmark.c index 886f7d8..440a4c8 100644 --- a/programs/benchmark.c +++ b/programs/benchmark.c @@ -532,7 +532,7 @@ tmain(int argc, tchar *argv[]) for (i = 0; i < argc; i++) { struct file_stream in; - ret = xopen_for_read(argv[i], &in); + ret = xopen_for_read(argv[i], true, &in); if (ret != 0) goto out2; diff --git a/programs/checksum.c b/programs/checksum.c index 1c42fd3..3e52ca4 100644 --- a/programs/checksum.c +++ b/programs/checksum.c @@ -168,7 +168,7 @@ tmain(int argc, tchar *argv[]) u64 size = 0; u64 elapsed = 0; - ret = xopen_for_read(argv[i], &in); + ret = xopen_for_read(argv[i], true, &in); if (ret != 0) goto out; diff --git a/programs/gzip.c b/programs/gzip.c index 5599d07..8253c24 100644 --- a/programs/gzip.c +++ b/programs/gzip.c @@ -361,7 +361,8 @@ decompress_file(struct libdeflate_decompressor *decompressor, const tchar *path, } } - ret = xopen_for_read(oldpath, &in); + ret = xopen_for_read(oldpath, options->force || options->to_stdout, + &in); if (ret != 0) goto out_free_paths; @@ -432,7 +433,7 @@ compress_file(struct libdeflate_compressor *compressor, const tchar *path, return -1; } - ret = xopen_for_read(path, &in); + ret = xopen_for_read(path, options->force || options->to_stdout, &in); if (ret != 0) goto out_free_newpath; diff --git a/programs/prog_util.c b/programs/prog_util.c index 6966fc9..12c10dd 100644 --- a/programs/prog_util.c +++ b/programs/prog_util.c @@ -196,7 +196,7 @@ quote_path(const tchar *path) /* Open a file for reading, or set up standard input for reading */ int -xopen_for_read(const tchar *path, struct file_stream *strm) +xopen_for_read(const tchar *path, bool symlink_ok, struct file_stream *strm) { strm->mmap_mem = NULL; @@ -216,7 +216,8 @@ xopen_for_read(const tchar *path, struct file_stream *strm) if (strm->name == NULL) return -1; - strm->fd = topen(path, O_RDONLY | O_BINARY | O_NOFOLLOW | O_SEQUENTIAL); + strm->fd = topen(path, O_RDONLY | O_BINARY | + (symlink_ok ? 0 : O_NOFOLLOW) | O_SEQUENTIAL); if (strm->fd < 0) { msg_errno("Can't open %"TS" for reading", strm->name); free(strm->name); diff --git a/programs/prog_util.h b/programs/prog_util.h index ec0c22b..0dcad01 100644 --- a/programs/prog_util.h +++ b/programs/prog_util.h @@ -136,7 +136,8 @@ struct file_stream { size_t mmap_size; }; -extern int xopen_for_read(const tchar *path, struct file_stream *strm); +extern int xopen_for_read(const tchar *path, bool symlink_ok, + struct file_stream *strm); extern int xopen_for_write(const tchar *path, bool force, struct file_stream *strm); extern int map_file_contents(struct file_stream *strm, u64 size);