diff --git a/programs/benchmark.c b/programs/benchmark.c index cb852a7..d0629bb 100644 --- a/programs/benchmark.c +++ b/programs/benchmark.c @@ -503,7 +503,7 @@ tmain(int argc, tchar *argv[]) int i; int ret; - program_invocation_name = get_filename(argv[0]); + begin_program(argv); while ((opt_char = tgetopt(argc, argv, optstring)) != -1) { switch (opt_char) { diff --git a/programs/checksum.c b/programs/checksum.c index bd3c40d..6c0133d 100644 --- a/programs/checksum.c +++ b/programs/checksum.c @@ -115,7 +115,7 @@ tmain(int argc, tchar *argv[]) int i; int ret; - program_invocation_name = get_filename(argv[0]); + begin_program(argv); while ((opt_char = tgetopt(argc, argv, optstring)) != -1) { switch (opt_char) { diff --git a/programs/gzip.c b/programs/gzip.c index 258babc..546f969 100644 --- a/programs/gzip.c +++ b/programs/gzip.c @@ -528,7 +528,7 @@ tmain(int argc, tchar *argv[]) int i; int ret; - program_invocation_name = get_filename(argv[0]); + begin_program(argv); options.to_stdout = false; options.decompress = is_gunzip(); diff --git a/programs/prog_util.c b/programs/prog_util.c index 7cc3bc6..06d3d46 100644 --- a/programs/prog_util.c +++ b/programs/prog_util.c @@ -112,7 +112,7 @@ xmalloc(size_t size) * properly for directories, since a path to a directory might have trailing * slashes. */ -const tchar * +static const tchar * get_filename(const tchar *path) { const tchar *slash = tstrrchr(path, '/'); @@ -126,6 +126,12 @@ get_filename(const tchar *path) return path; } +void +begin_program(tchar *argv[]) +{ + program_invocation_name = get_filename(argv[0]); +} + /* Create a copy of 'path' surrounded by double quotes */ static tchar * quote_path(const tchar *path) diff --git a/programs/prog_util.h b/programs/prog_util.h index 7bacf1a..71f7160 100644 --- a/programs/prog_util.h +++ b/programs/prog_util.h @@ -119,7 +119,7 @@ void _printf(1, 2) msg_errno(const char *fmt, ...); void *xmalloc(size_t size); -const tchar *get_filename(const tchar *path); +void begin_program(tchar *argv[]); struct file_stream { int fd; diff --git a/programs/test_checksums.c b/programs/test_checksums.c index 686fafb..99fad7d 100644 --- a/programs/test_checksums.c +++ b/programs/test_checksums.c @@ -151,7 +151,7 @@ tmain(int argc, tchar *argv[]) u8 *buffer = xmalloc(32768); u8 *guarded_buf_start, *guarded_buf_end; - program_invocation_name = get_filename(argv[0]); + begin_program(argv); alloc_guarded_buffer(32768, &guarded_buf_start, &guarded_buf_end); diff --git a/programs/test_incomplete_codes.c b/programs/test_incomplete_codes.c index 436cd9b..4e441bc 100644 --- a/programs/test_incomplete_codes.c +++ b/programs/test_incomplete_codes.c @@ -374,7 +374,7 @@ test_singleton_offset_code_notsymzero(void) int tmain(int argc, tchar *argv[]) { - program_invocation_name = get_filename(argv[0]); + begin_program(argv); test_empty_offset_code(); test_singleton_litrunlen_code(); diff --git a/programs/test_slow_decompression.c b/programs/test_slow_decompression.c index f691960..d5ac262 100644 --- a/programs/test_slow_decompression.c +++ b/programs/test_slow_decompression.c @@ -430,7 +430,7 @@ tmain(int argc, tchar *argv[]) u8 out[10000]; u64 t, tz; - program_invocation_name = get_filename(argv[0]); + begin_program(argv); begin_performance_test(); diff --git a/programs/test_trailing_bytes.c b/programs/test_trailing_bytes.c index ca23378..bf33793 100644 --- a/programs/test_trailing_bytes.c +++ b/programs/test_trailing_bytes.c @@ -65,7 +65,7 @@ tmain(int argc, tchar *argv[]) size_t actual_compressed_nbytes; size_t actual_decompressed_nbytes; - program_invocation_name = get_filename(argv[0]); + begin_program(argv); ASSERT(compressed_nbytes_avail < compressed_nbytes_total);