summaryrefslogtreecommitdiffstats
path: root/zutils.h
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-08 04:24:49 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-08 04:24:49 +0000
commit76b7c56bde408e57424f1832d12c691ca35ea0a4 (patch)
tree508afbb311412ed15d98a00266954754dc7ed98d /zutils.h
parentAdding debian version 0.9-7. (diff)
downloadzutils-76b7c56bde408e57424f1832d12c691ca35ea0a4.tar.xz
zutils-76b7c56bde408e57424f1832d12c691ca35ea0a4.zip
Merging upstream version 1.0~rc6.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to '')
-rw-r--r--zutils.h70
1 files changed, 47 insertions, 23 deletions
diff --git a/zutils.h b/zutils.h
index 5f5809c..778daa3 100644
--- a/zutils.h
+++ b/zutils.h
@@ -1,5 +1,5 @@
/* Zutils - Utilities dealing with compressed files
- Copyright (C) 2009, 2010, 2011 Antonio Diaz Diaz.
+ Copyright (C) 2009, 2010, 2011, 2012, 2013 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -17,42 +17,66 @@
const char * const Program_name = "Zutils";
const char * const program_name = "zutils";
-const char * const program_year = "2011";
+const char * const program_year = "2013";
extern const char * invocation_name;
extern const char * util_name;
extern int verbosity;
-const char * const simple_extensions[] = { ".gz", ".lz", ".bz2", ".xz", 0 };
+enum { fmt_bz2, fmt_gz, fmt_lz, fmt_xz, num_formats };
+const char * const format_names[num_formats] = { "bz2", "gz", "lz", "xz" };
+const char * const simple_extensions[num_formats] =
+ { ".bz2", ".gz", ".lz", ".xz" };
+const char * const decompressor_names[num_formats] =
+ { "bzip2", "gzip", "lzip", "xz" };
+const int8_t format_order[num_formats] =
+ { fmt_gz, fmt_lz, fmt_bz2, fmt_xz }; // search order
-enum { bzip2_magic_size = 3 };
-enum { gzip_magic_size = 2 };
-enum { lzip_magic_size = 4 };
-enum { xz_magic_size = 5 };
-const uint8_t bzip2_magic[bzip2_magic_size] = { 'B', 'Z', 'h' };
-const uint8_t gzip_magic[ gzip_magic_size] = { '\x1F', '\x8B' };
-const uint8_t lzip_magic[ lzip_magic_size] = { 'L', 'Z', 'I', 'P' };
-const uint8_t xz_magic[ xz_magic_size] = { '\xFD', '7', 'z', 'X', 'Z' };
+// first magic byte must be different among formats
+enum { bzip2_magic_size = 3,
+ gzip_magic_size = 2,
+ lzip_magic_size = 4,
+ xz_magic_size = 5 };
+const uint8_t bzip2_magic[bzip2_magic_size] =
+ { 0x42, 0x5A, 0x68 }; // "BZh"
+const uint8_t gzip_magic[gzip_magic_size] =
+ { 0x1F, 0x8B };
+const uint8_t lzip_magic[lzip_magic_size] =
+ { 0x4C, 0x5A, 0x49, 0x50 }; // "LZIP"
+const uint8_t xz_magic[xz_magic_size] =
+ { 0xFD, 0x37, 0x7A, 0x58, 0x5A }; // 0xFD, "7zXZ"
-int readblock( const int fd, uint8_t * const buf, const int size ) throw();
-int writeblock( const int fd, const uint8_t * const buf, const int size ) throw();
+int get_format_type( const std::string & arg );
+
+int readblock( const int fd, uint8_t * const buf, const int size );
+int writeblock( const int fd, const uint8_t * const buf, const int size );
bool feed_data( const int infd, const int outfd,
const uint8_t * magic_data, const int magic_size );
-bool set_data_feeder( int * const infdp, pid_t * const pidp );
+bool set_data_feeder( int * const infdp, pid_t * const pidp,
+ const int format_type );
-void show_help_addr() throw();
-void show_version( const char * const Util_name = 0 ) throw();
+void show_help_addr();
+void show_version( const char * const Util_name = 0 );
void show_error( const char * const msg, const int errcode = 0,
- const bool help = false ) throw();
-void show_error2( const char * const msg, const char * const name ) throw();
-void show_close_error( const char * const prog_name ) throw();
-void show_exec_error( const char * const prog_name ) throw();
-void show_fork_error( const char * const prog_name ) throw();
+ const bool help = false );
+void show_error2( const char * const msg, const char * const name );
+void show_close_error( const char * const prog_name );
+void show_exec_error( const char * const prog_name );
+void show_fork_error( const char * const prog_name );
void internal_error( const char * const msg );
-bool test_format( const int infd, std::string & file_type,
- const uint8_t ** magic_data, int * magic_sizep );
+const char * test_format( const int infd,
+ const uint8_t ** const magic_datap,
+ int * const magic_sizep );
+// Returns exit status of child process 'pid', or 'eretval' in case of error.
+//
int wait_for_child( const pid_t pid, const char * const name,
const int eretval = 2 );
+
+// Returns -1 if child not terminated, 'eretval' in case of error, or
+// exit status of child process 'pid'.
+//
+int child_status( const pid_t pid, const char * const name,
+ const int eretval = 2 );