/*-
* Copyright(c) 1996, 2001, 2004 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matthias Drochner. and UCHIYAMA Yasushi.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
uint32_t
FileManager::_get_long()
{
uint32_t x = static_cast<uint32_t>(_get_byte());
int c;
x +=(static_cast<uint32_t>(_get_byte())) << 8;
x +=(static_cast<uint32_t>(_get_byte())) << 16;
c = _get_byte();
if (c == EOF)
_z_err = Z_DATA_ERROR;
x +=(static_cast<uint32_t>(c)) << 24;
return x;
}
void
FileManager::_check_header()
{
int method; /* method byte */
int flags; /* flags byte */
unsigned int len;
int c;
/* Check the gzip magic header */
for (len = 0; len < 2; len++) {
c = _get_byte();
if (c == _gz_magic[len])
continue;
if ((c == EOF) &&(len == 0)) {
/*
* We must not change _compressed if we are at EOF;
* we may have come to the end of a gzipped file and be
* check to see if another gzipped file is concatenated
* to this one. If one isn't, we still need to be able
* to lseek on this file as a compressed file.
*/
return;
}
_compressed = 0;
if (c != EOF) {
_stream->avail_in++;
_stream->next_in--;
}
_z_err = _stream->avail_in != 0 ? Z_OK : Z_STREAM_END;
return;
}
_compressed = 1;
method = _get_byte();
flags = _get_byte();
if (method != Z_DEFLATED ||(flags & RESERVED) != 0) {
_z_err = Z_DATA_ERROR;
return;
}
/* Discard time, xflags and OS code: */
for (len = 0; len < 6; len++)
(void)_get_byte();
if ((flags & EXTRA_FIELD) != 0) {
/* skip the extra field */
len = (unsigned int)_get_byte();
len +=((unsigned int)_get_byte()) << 8;
/* len is garbage if EOF but the loop below will quit anyway */
while (len-- != 0 && _get_byte() != EOF) /*void*/;
}
if ((flags & ORIG_NAME) != 0) {
/* skip the original file name */
while ((c = _get_byte()) != 0 && c != EOF) /*void*/;
}
if ((flags & COMMENT) != 0) {
/* skip the .gz file comment */
while ((c = _get_byte()) != 0 && c != EOF) /*void*/;
}
if ((flags & HEAD_CRC) != 0) { /* skip the header crc */
for (len = 0; len < 2; len++)
(void)_get_byte();
}
_z_err = _z_eof ? Z_DATA_ERROR : Z_OK;
}