gzip, bzip2, and lzma use the same command-line syntax. Factor out a compress_cmd() function that can be used to invoke any one of these commands.
Signed-off-by: Jonathan Nieder <[email protected]> --- lib/dpkg/compression.c | 32 ++++++++++++++------------------ 1 files changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/dpkg/compression.c b/lib/dpkg/compression.c index f901867..914ba1d 100644 --- a/lib/dpkg/compression.c +++ b/lib/dpkg/compression.c @@ -95,6 +95,17 @@ fd_fd_filter(int fd_in, int fd_out, exit(0); \ } while(0) +static void +compress_cmd(int fd_in, int fd_out, const char *path, + const char *cmd, char compression, + const char *desc) +{ + char combuf[6]; + strncpy(combuf, "-9c", sizeof(combuf)); + combuf[1] = compression; + fd_fd_filter(fd_in, fd_out, path, cmd, combuf, desc); +} + void decompress_cat(enum compress_type type, int fd_in, int fd_out, char *desc, ...) { va_list al; struct varbuf v = VARBUF_INIT; @@ -147,12 +158,7 @@ void compress_cat(enum compress_type type, int fd_in, int fd_out, const char *co COMPRESS("gzip", gzFile, gzdopen, gzwrite, gzclose, gzerror, Z_ERRNO, fd_in, fd_out, *compression, v.buf); #else - { - char combuf[6]; - strncpy(combuf, "-9c", sizeof(combuf)); - combuf[1]= *compression; - fd_fd_filter(fd_in, fd_out, GZIP, "gzip", combuf, v.buf); - } + compress_cmd(fd_in, fd_out, GZIP, "gzip", *compression, v.buf); #endif case compress_type_bzip2: #ifdef WITH_BZ2 @@ -160,20 +166,10 @@ void compress_cat(enum compress_type type, int fd_in, int fd_out, const char *co BZ2_bzerror, BZ_IO_ERROR, fd_in, fd_out, *compression, v.buf); #else - { - char combuf[6]; - strncpy(combuf, "-9c", sizeof(combuf)); - combuf[1]= *compression; - fd_fd_filter(fd_in, fd_out, BZIP2, "bzip2", combuf, v.buf); - } + compress_cmd(fd_in, fd_out, BZIP2, "bzip2", *compression, v.buf); #endif case compress_type_lzma: - { - char combuf[6]; - strncpy(combuf, "-9c", sizeof(combuf)); - combuf[1] = *compression; - fd_fd_filter(fd_in, fd_out, LZMA, "lzma", combuf, v.buf); - } + compress_cmd(fd_in, fd_out, LZMA, "lzma", *compression, v.buf); case compress_type_cat: fd_fd_copy(fd_in, fd_out, -1, _("%s: compression"), v.buf); exit(0); -- 1.6.5.rc1.199.g596ec -- To UNSUBSCRIBE, email to [email protected] with a subject of "unsubscribe". Trouble? Contact [email protected]

