1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-31 11:41:32 +01:00

2002-06-05 Timo Schulz <ts@winpt.org>

* fileutil.c (is_file_compressed): Corrected the magic values
        for bzip2 and gzip. Noted by David.
This commit is contained in:
Timo Schulz 2002-06-05 09:23:51 +00:00
parent fd08b13528
commit 098a5229d1
2 changed files with 35 additions and 22 deletions

View File

@ -1,3 +1,8 @@
2002-06-05 Timo Schulz <ts@winpt.org>
* fileutil.c (is_file_compressed): Corrected the magic values
for bzip2 and gzip. Noted by David.
2002-05-22 Werner Koch <wk@gnupg.org> 2002-05-22 Werner Koch <wk@gnupg.org>
* fileutil.c (compare_filenames): Replaced stricmp by strcasecmp. * fileutil.c (compare_filenames): Replaced stricmp by strcasecmp.

View File

@ -184,47 +184,55 @@ print_fname_stdin( const char *s )
return s; return s;
} }
/** /****************
* Check if the file is compressed. * Check if the file is compressed.
**/ **/
int int
is_file_compressed(const char *s, int *r_status) is_file_compressed( const char *s, int *ret_rc )
{ {
IOBUF a; IOBUF a;
int i, rc = 0;
byte buf[4]; byte buf[4];
int i, rc = 0;
const byte sigs[4][4] = { struct magic_compress_s {
{0x42, 0x5a, 0x68, 0x39}, /* bzip2 */ size_t len;
{0x1f, 0x8b, 0x08, 0x08}, /* gzip */ byte magic[4];
{0x50, 0x4b, 0x03, 0x04} /* (pk)zip */ } magic[] = {
{ 3, { 0x42, 0x5a, 0x68, 0x00 } }, /* bzip2 */
{ 3, { 0x1f, 0x8b, 0x08, 0x00 } }, /* gzip */
{ 4, { 0x50, 0x4b, 0x03, 0x04 } }, /* (pk)zip */
}; };
if (!s || *s == '-' || !r_status) if ( !s || *s == '-' || !ret_rc )
return 0; /* We can't check stdin or no file was given */ return 0; /* We can't check stdin or no file was given */
if ( (a = iobuf_open(s)) == NULL ) { a = iobuf_open( s );
*r_status = G10ERR_OPEN_FILE; if ( a == NULL ) {
*ret_rc = G10ERR_OPEN_FILE;
return 0; return 0;
} }
if (iobuf_get_filelength(a) < 4) { if ( iobuf_get_filelength( a ) < 4 ) {
*r_status = 0; *ret_rc = 0;
goto leave; goto leave;
} }
iobuf_read(a, buf, 4); if ( iobuf_read( a, buf, 4 ) == -1 ) {
*ret_rc = G10ERR_READ_FILE;
for (i=0; i<DIM(sigs); i++) { goto leave;
if (!memcmp(buf, sigs[i], 4)) { }
*r_status = 0;
for ( i = 0; i < DIM( magic ); i++ ) {
if ( !memcmp( buf, magic[i].magic, magic[i].len ) ) {
*ret_rc = 0;
rc = 1; rc = 1;
break; break;
} }
} }
leave: leave:
iobuf_close(a); iobuf_close( a );
return rc; return rc;
} }