zziplib -0.10.27

uint32_t __zzip_get32(unsigned char * s)
uint16_t __zzip_get16(unsigned char * s)
int zzip_find_disk_trailer(int fd, int filesize, struct zzip_disk_trailer * trailer)
int zzip_parse_root_directory(int fd, struct zzip_disk_trailer * trailer, struct zzip_dir_hdr ** hdr_return)
ZZIP_DIR* zzip_dir_alloc (const char** fileext)
int zzip_dir_free(ZZIP_DIR * dir)
int zzip_dir_close(ZZIP_DIR * dir)
ZZIP_DIR * zzip_dir_fdopen(int fd, zzip_error_t * errcode_p)
int __zzip_open_zip(const char* filename, int filemode)
ZZIP_DIR* zzip_dir_open(const char* filename, zzip_error_t* e)
int zzip_dir_read(ZZIP_DIR * dir, ZZIP_DIRENT * d )
void zzip_file_close(ZZIP_FILE * fp)
ZZIP_FILE * zzip_file_open(ZZIP_DIR * dir, const char * name, int flags)
static int zzip_inflate_init(ZZIP_FILE * fp, struct zzip_dir_hdr* hdr)
void zzip_close(ZZIP_FILE * fp)
int zzip_file_read(ZZIP_FILE * fp, char * buf, int len)
int zzip_read(ZZIP_FILE * fp, char * buf, int len)
ZZIP_FILE* zzip_open(const char* filename, int flags)
int zzip_rewind(ZZIP_FILE *fp)
int zzip_seek(ZZIP_FILE * fp, int offset, int whence)
int zzip_tell(ZZIP_FILE * fp)
void zzip_rewinddir(ZZIP_DIR * dir)
ZZIP_DIRENT* zzip_readdir(ZZIP_DIR * dir)
ZZIP_off_t zzip_telldir(ZZIP_DIR* dir)
void zzip_seekdir(ZZIP_DIR* dir, ZZIP_off_t offset)
ZZIP_DIR* zzip_opendir(const char* filename)
int zzip_closedir(ZZIP_DIR* dir)
int zzip_dir_stat(ZZIP_DIR * dir, const char * name, ZZIP_STAT * zs, int flags)
int zzip_error(ZZIP_DIR * dir)
void zzip_seterror(ZZIP_DIR * dir, int errcode)
ZZIP_DIR * zzip_dirhandle(ZZIP_FILE * fp)
int zzip_dirfd(ZZIP_DIR* dir)
const char* zzip_compr_str(int compr)
int zzip_dir_real(ZZIP_DIR* dir)
int zzip_file_real(ZZIP_FILE* fp)
void* zzip_realdir(ZZIP_DIR* dir)
int zzip_realfd(ZZIP_FILE* fp)
const char* zzip_strerror(int errcode)
const char* zzip_strerror_of(ZZIP_DIR* dir)
int zzip_errno(int errcode)

Documentation

uint32_t
__zzip_get32  (unsigned char * s)

Make 32 bit value in host byteorder from little-endian mapped octet-data
(works also on machines which SIGBUS on misaligned data access (eg. 68000))

(zzip-zip.c)

uint16_t
__zzip_get16  (unsigned char * s)

Make 16 bit value in host byteorder from little-endian mapped octet-data
(works also on machines which SIGBUS on misaligned data access (eg. 68000))

(zzip-zip.c)

int
zzip_find_disk_trailer  (int fd, int filesize, struct zzip_disk_trailer * trailer)

the function for use by
zzip_file_open. Tries to find
the zip's central directory info that is usually a few
bytes off the end of the file.

(zzip-zip.c)

int
zzip_parse_root_directory  (int fd, struct zzip_disk_trailer * trailer, struct zzip_dir_hdr ** hdr_return)

the function for use by
zzip_file_open, it is usually called after
zzip_find_disk_trailer. It will parse the zip's central directory
information and create a zziplib private directory table in
memory.

(zzip-zip.c)

ZZIP_DIR*
zzip_dir_alloc  (const char** fileext)

allocate a new ZZIP_DIR handle and do basic
initializations before usage by
zzip_dir_fdopen
zzip_dir_open zzip_file_open or through
zzip_open
(fileext null flags uses { ".zip" , ".ZIP" } )

(zzip-zip.c)

int
zzip_dir_free  (ZZIP_DIR * dir)

will free the zzip_dir handle unless there are still
zzip_files attached (that may use its cache buffer).
This is the inverse of
zzip_dir_alloc , and both
are helper functions used implicitly in other zzipcalls
e.g. zzip_dir_close = zzip_close

returns zero on sucess
returns the refcount when files are attached.

(zzip-zip.c)

int
zzip_dir_close  (ZZIP_DIR * dir)

It will also free(2) the ZZIP_DIR-handle given.
the counterpart for
zzip_dir_open
see also zzip_dir_free

(zzip-zip.c)

ZZIP_DIR *
zzip_dir_fdopen  (int fd, zzip_error_t * errcode_p)

used by the
zzip_dir_open and zzip_opendir(2) call. Opens the
zip-archive as specified with the fd which points to an
already openend file. This function then search and parse
the zip's central directory.


NOTE: refcount is zero, so an _open/_close pair will also delete
this _dirhandle

(zzip-zip.c)

int
__zzip_open_zip  (const char* filename, int filemode)

will attach a .zip extension and tries to open it
the with open(2). This is a helper function for
zzip_dir_open, zzip_opendir and zzip_open.

(zzip-zip.c)

ZZIP_DIR*
zzip_dir_open  (const char* filename, zzip_error_t* e)

Opens the zip-archive (if available).

(zzip-zip.c)

int
zzip_dir_read  (ZZIP_DIR * dir, ZZIP_DIRENT * d )

fills the dirent-argument with the values and
increments the read-pointer of the dir-argument.


returns 0 if there no entry (anymore).

(zzip-zip.c)

void
zzip_file_close  (ZZIP_FILE * fp)

the direct function of
zzip_close(fp). it will cleanup the
inflate-portion of zlib and free the structure given.


it is called quite from the error-cleanup parts
of the various _open functions.


the .refcount is decreased and if zero the fp->dir is closed just as well.

(zzip-file.c)

ZZIP_FILE *
zzip_file_open  (ZZIP_DIR * dir, const char * name, int flags)

open an ZZIP_FILE from an already open ZZIP_DIR handle. Since
we have a chance to reuse a cached buf32k and ZZIP_FILE memchunk
this is the best choice to unpack multiple files.


Note: the zlib supports 2..15 bit windowsize, hence we provide a 32k
memchunk here... just to be safe.

(zzip-file.c)

static int
zzip_inflate_init  (ZZIP_FILE * fp, struct zzip_dir_hdr* hdr)

call inflateInit and setup fp's iterator variables,
used by lowlevel _open functions.

(zzip-file.c)

void
zzip_close  (ZZIP_FILE * fp)

close an ZZIP_FILE handle. If the ZZIP_FILE wraps a normal stat'fd then it
is just that int'fd that is being closed and the otherwise empty ZZIP_FILE
gets freed.

(zzip-file.c)

int
zzip_file_read  (ZZIP_FILE * fp, char * buf, int len)

works like read(2), it will fill the given buffer with bytes from
the opened file. It will return the number of bytes read, so if the EOF
is encountered you will be prompted with the number of bytes actually read.


This is the routines that needs the buf32k buffer, and it would have
need for much more polishing but it does already work quite well.


Note: the 32K buffer is rather big. The original inflate-algorithm
required just that but the latest zlib would work just fine with
a smaller buffer.

(zzip-file.c)

int
zzip_read  (ZZIP_FILE * fp, char * buf, int len)

the replacement for read(2), it will fill the given buffer with bytes from
the opened file. It will return the number of bytes read, so if the EOF
is encountered you will be prompted with the number of bytes actually read.


If the file-handle is wrapping a stat'able file then it will actually just
perform a normal read(2)-call, otherwise
zzip_file_read is called
to decompress the data stream and any error is mapped to errno(3).

(zzip-file.c)

ZZIP_FILE*
zzip_open  (const char* filename, int flags)

see open(2).


This functions has some magic builtin - it will first try to open
the given filename as a normal file. If it does not
exist, the given path to the filename (if any) is split into
its directory-part and the file-part. A ".zip" extension is
then added to the directory-part to create the name of a
zip-archive. That zip-archive (if it exists) is being searched
for the file-part, and if found a zzip-handle is returned.


Note that if the file is found in the normal fs-directory the
returned structure is mostly empty and the
zzip_read call will
use the libc read to obtain data. Otherwise a zzip_file_open
is performed and any error mapped to errno(3).

(zzip-file.c)

int
zzip_rewind  (ZZIP_FILE *fp)

Rewind an ZZIP_FILE handle. Seeks to the beginning of this file's
data in the zip, or the beginning of the file for a stat'fd.

(zzip-file.c)

int
zzip_seek  (ZZIP_FILE * fp, int offset, int whence)

the replacement for lseek(2), it will seek to the offset
specified by offset, relative to whence, which is one of
SEEK_SET, SEEK_CUR or SEEK_END.


If the file-handle is wrapping a stat'able file then it will actually just
perform a normal lseek(2)-call. Otherwise the relative offset
is calculated, negative offsets are transformed into positive ones
by rewinding the file, and then data is read until the offset is
reached. This can make the function terribly slow, but this is
how gzio implements it, so I'm not sure there is a better way
without using the internals of the algorithm.

(zzip-file.c)

int
zzip_tell  (ZZIP_FILE * fp)

the replacement for tell(2), it will return the current offset
in the file, in uncompressed bytes.


If the file-handle is wrapping a stat'able file then it will actually just
perform a normal tell(2)-call, otherwise the offset is
calculated from the amount of data left and the total uncompressed
size;

(zzip-file.c)

void
zzip_rewinddir  (ZZIP_DIR * dir)

see rewinddir(2), rewinds the DIR returned by
zzip_opendir

(zzip-dir.c)

ZZIP_DIRENT*
zzip_readdir  (ZZIP_DIR * dir)

see readdir(2), reads the DIR returned by
zzip_opendir

(zzip-dir.c)

ZZIP_off_t
zzip_telldir  (ZZIP_DIR* dir)

see telldir(2)

(zzip-dir.c)

void
zzip_seekdir  (ZZIP_DIR* dir, ZZIP_off_t offset)

see seekdir(2)

(zzip-dir.c)

ZZIP_DIR*
zzip_opendir  (const char* filename)

see opendir(3).


This function has some magic - if the given argument-path
is a directory, it will wrap a real opendir(3) into the ZZIP_DIR
structure. Otherwise it will divert to
zzip_dir_open which
can also attach a .zip extension if needed to find the archive.


the error-code is mapped to errno(3).

(zzip-dir.c)

int
zzip_closedir  (ZZIP_DIR* dir)

see closedir(3).


This function is magic - if the given arg-ZZIP_DIR
is a real directory, it will call the real closedir(3) and then
free the wrapping ZZIP_DIR structure. Otherwise it will divert
to
zzip_dir_close which will free the ZZIP_DIR structure.

(zzip-dir.c)

int
zzip_dir_stat  (ZZIP_DIR * dir, const char * name, ZZIP_STAT * zs, int flags)

obtain information about a filename in a zip-archive without
opening that file first. Mostly used to obtain the uncompressed
size of file inside a zip-archive.

(zzip-stat.c)

int
zzip_error  (ZZIP_DIR * dir)

return dir->errcode

(zzip-info.c)

void
zzip_seterror  (ZZIP_DIR * dir, int errcode)

dir->errcode = errcode

(zzip-info.c)

ZZIP_DIR *
zzip_dirhandle  (ZZIP_FILE * fp)

return fp->dir

(zzip-info.c)

int
zzip_dirfd  (ZZIP_DIR* dir)

return dir->fd

(zzip-info.c)

const char*
zzip_compr_str  (int compr)

return static const string of the known compression methods,
otherwise "zipped" is returned

(zzip-info.c)

int
zzip_dir_real  (ZZIP_DIR* dir)

return if the DIR-handle is wrapping a real directory
or a zip-archive. Returns 1 for a stat'able directory,
and 0 for a handle to zip-archive.

(zzip-info.c)

int
zzip_file_real  (ZZIP_FILE* fp)

return if the FILE-handle is wrapping a real file
or a zip-contained file. Returns 1 for a stat'able file,
and 0 for a file inside a zip-archive.

(zzip-info.c)

void*
zzip_realdir  (ZZIP_DIR* dir)

return the posix DIR* handle (if one exists).
Check before with
zzip_dir_real if the
the ZZIP_DIR points to a real directory.

(zzip-info.c)

int
zzip_realfd  (ZZIP_FILE* fp)

return the posix file descriptor (if one exists).
Check before with
zzip_file_real if the
the ZZIP_FILE points to a real file.

(zzip-info.c)

const char*
zzip_strerror  (int errcode)

returns the static string for the given error code. The
error code can be either a normal system error (a
positive error code will flag this), it can be libz
error code (a small negative error code will flag this)
or it can be an error code from libzzip, which is an
negative value lower than ZZIP_ERROR

(zzip-err.c)

const char*
zzip_strerror_of  (ZZIP_DIR* dir)

read the errorcode from the DIR-handle and run it
through
zzip_strerror to obtain the static string
describing the error.

(zzip-err.c)

int
zzip_errno  (int errcode)

map the error code to a system error code. This is used
for the drop-in replacement functions to return a value
that can be interpreted correctly by code sections that
are unaware of the fact they their open(2) call had been
diverted to a file inside a zip-archive.

(zzip-err.c)