internal int inflateSync(ZStream z)
{
int n; // number of bytes to look at
int p; // pointer to bytes
int m; // number of marker bytes found in a row
long r, w; // temporaries to save total_in and total_out
// set up
if (z == null || z.istate == null)
return Z_STREAM_ERROR;
if (z.istate.mode != BAD)
{
z.istate.mode = BAD;
z.istate.marker = 0;
}
if ((n = z.avail_in) == 0)
return Z_BUF_ERROR;
p = z.next_in_index;
m = z.istate.marker;
// search
while (n != 0 && m < 4)
{
if (z.next_in[p] == mark[m])
{
m++;
}
else if (z.next_in[p] != 0)
{
m = 0;
}
else
{
m = 4 - m;
}
p++; n--;
}
// restore
z.total_in += p - z.next_in_index;
z.next_in_index = p;
z.avail_in = n;
z.istate.marker = m;
// return no joy or set up to restart on a new block
if (m != 4)
{
return Z_DATA_ERROR;
}
r = z.total_in; w = z.total_out;
inflateReset(z);
z.total_in = r; z.total_out = w;
z.istate.mode = BLOCKS;
return Z_OK;
}