#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
#include <zzip.h>
#include <zzip-io.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdlib.h>
#ifdef DEBUG
#include <stdio.h>
#endif
#include <zzip-file.h>
#include <zzipformat.h>
zzip_off_t
zzip_filesize(int fd)
{
struct stat st;
if (fstat(fd, &st) < 0)
return -1;
# ifdef DEBUG
if (! st.st_size && st.st_blocks > 1)
fprintf(stderr, "broken fstat(2) ?? st_size=%ld st_blocks=%ld\n",
(long) st.st_size, (long) st.st_blocks);
# endif
return st.st_size;
}
#if defined ZZIP_WRAPWRAP
int zzip_wrap_read(int fd, void* p, unsigned int len)
{ return _zzip_read (fd, p, len); }
zzip_off_t zzip_wrap_lseek(int fd, zzip_off_t offset, int whence)
{ return _zzip_lseek (fd, offset, whence); }
#else
#define zzip_wrap_read _zzip_read
#define zzip_wrap_lseek _zzip_lseek
#endif
static const struct zzip_plugin_io default_io =
{
&open,
&close,
&zzip_wrap_read,
&zzip_wrap_lseek,
&zzip_filesize,
1
};
zzip_plugin_io_t
zzip_get_default_io()
{
return &default_io;
}
int zzip_init_io(struct zzip_plugin_io* io, int flags)
{
if (!io) {
return ZZIP_ERROR;
}
memcpy(io, &default_io, sizeof(default_io));
io->use_mmap = flags;
return 0;
}