/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1998-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* partitioned fixed record zip implementation
*/
#include "pzlib.h"
#include <ls.h>
/*
* print message and fail on VM_BADADDR,VM_NOMEM
*/
static int
{
switch (type)
{
case VM_BADADDR:
(*pz->disc->errorf)(pz, pz->disc, ERROR_SYSTEM|2, "invalid pointer %p passed to free or realloc", obj);
return -1;
case VM_NOMEM:
{
(*pz->disc->errorf)(pz, pz->disc, ERROR_SYSTEM|2, "storage allocator out of space on %lu byte request ( region %lu segments %lu busy %lu:%lu:%lu free %lu:%lu:%lu )", (size_t)obj, st.extent, st.n_seg, st.n_busy, st.s_busy, st.m_busy, st.n_free, st.s_free, st.m_free);
}
return -1;
}
return 0;
}
/*
* find and open file with optional suffix and sfio mode
*/
{
{
{
(*pz->disc->errorf)(pz, pz->disc, ERROR_SYSTEM|2, "%s: cannot find %s file", file, suffix ? suffix : "data");
return 0;
}
{
return 0;
}
}
return sp;
}
/*
* open a new pz stream
*/
Pz_t*
{
{
}
else
{
return 0;
if (!(pz = vmnewof(vm, 0, Pz_t, 1, 0)) || !(pz->tmp = sfstropen()) || !(pz->str = sfstropen()) || (flags & PZ_WRITE) && !(pz->det = sfstropen()))
goto bad;
goto bad;
if (!path)
{
{
{
goto bad;
}
}
{
goto bad;
}
else
}
{
}
else if (!(pz->io = strneq(path, "pipe://", 7) ? sfpopen(NiL, path + 7, "r") : sfopen(NiL, path, "r")))
{
goto bad;
}
goto bad;
/*
* without this large .pz and .gz terminate short of EOF
*/
/*
* there is an sfio discipline bug (probably usage,
* not implementation) for piped input; the S_ISFIFO
* test avoids the bug until the root problem is fixed
*/
else if (!(pz->flags & PZ_POP) && (!(pz->flags & PZ_WRITE) && sfdcgzip(pz->io, (pz->flags & PZ_CRC) ? 0 : SFGZ_NOCRC) > 0 || (pz->flags & (PZ_PUSHED|PZ_WRITE)) == PZ_WRITE && sfdcpzip((Sfio_t*)pz, pz->path, pz->flags|PZ_FORCE|PZ_PUSHED|PZ_HANDLE, disc) > 0))
else
goto bad;
if (disc->options && (!(pz->options = vmstrdup(pz->vm, disc->options)) || pzoptions(pz, NiL, pz->options, 0) < 0))
goto bad;
}
{
if (pzheadread(pz))
goto bad;
goto bad;
goto bad;
}
else
{
goto bad;
{
}
goto bad;
{
goto bad;
}
}
/*
* ready to process
*/
if (pz->disc->eventf && (*pz->disc->eventf)(pz, (flags & PZ_AGAIN) ? PZ_REOPEN : PZ_OPEN, NiL, 0, pz->disc) < 0)
goto bad;
(*pz->disc->errorf)(pz, pz->disc, -1, "%s: pzopen: flags=%08x win=(%I*u:%I*u) row=(%I*u:%I*u) buf=%p wrk=%p", pz->path, pz->flags, sizeof(pz->win), pz->win, sizeof(pz->mwin), pz->mwin, sizeof(pz->row), pz->row, sizeof(pz->mrow), pz->mrow, pz->buf, pz->wrk);
return pz;
bad:
return 0;
}
/*
* close an open pz stream
*/
int
{
int r;
unsigned long e;
Sfoff_t p;
if (!pz)
return -1;
{
/*
* finish up the pzwrite() stream
*/
{
}
{
return -1;
}
{
return -1;
}
}
if ((pz->flags & PZ_WRITE) && (pz->flags & (PZ_DUMP|PZ_VERBOSE|PZ_SUMMARY)) && pz->disc->errorf && pz->count.records)
{
{
{
}
}
e = 100;
else
{
if (!(e = ((unsigned long)now.tv_sec - (unsigned long)pz->start.tv_sec) * 100 + ((long)now.tv_nsec - (long)pz->start.tv_nsec) / 10000000L))
e = 1;
}
, fmtelapsed(e, 100)
);
);
);
);
);
);
);
);
}
{
{
{
{
r = -1;
}
}
}
{
{
(*pz->disc->errorf)(pz, pz->disc, ERROR_SYSTEM|2, (pz->flags & PZ_WRITE) ? "write error" : "read error");
}
}
}
r = -1;
return r;
}
/*
* common out of space message
*/
int
{
return -1;
}