zzip_fopen(3)

NAME
zzip_fopen, zzip_freopen - start usage.

SYNOPSIS

#include <zzip/lib.h>

b'ZZIP_FILE *\fInzzip_fopen(zzip_char_t * filename, zzip_char_t * mode)
b'ZZIP_FILE *\fInzzip_freopen(zzip_char_t * filename, zzip_char_t * mode, ZZIP_FILE * stream)n'

DESCRIPTION
b' The zzip_fopen function will fopen(3) a real/zipped file.

b'It has some magic functionality builtin - it will first try to openthe given <emphasis>filename</emphasis> as a normal file. If it does notexist, the given path to the filename (if any) is split intoits directory-part and the file-part. A ".zip" extension isthen added to the directory-part to create the name of azip-archive. That zip-archive (if it exists) is being searchedfor the file-part, and if found a zzip-handle is returned.

b'Note that if the file is found in the normal fs-directory thereturned structure is mostly empty and the zzip_read call willuse the libc read(2) to obtain data. Otherwise a zzip_file_openis performed and any error mapped to errno(3).

b'unlike the posix-wrapper zzip_open the mode-argument isa string which allows for more freedom to support the extrazzip modes called ZZIP_CASEINSENSITIVE and ZZIP_IGNOREPATH.Currently, this zzip_fopen call will convert the followingcharacters in the mode-string into their corrsponding mode-bits:

b' "r" : O_RDONLY : read-only

b' "b" : O_BINARY : binary (win32 specific)

b' "f" : O_NOCTTY : no char device (unix)

b' "i" : ZZIP_CASELESS : inside zip file

b' "*" : ZZIP_NOPATHS : inside zip file only

b' all other modes will be ignored for zip-contained entriesbut they are transferred for compatibility and portability,including these extra sugar bits:

b' "x" : O_EXCL : fail if file did exist

b' "s" : O_SYNC : synchronized access

b' "n" : O_NONBLOCK : nonblocking access

b' "z#" : compression level : for zlib

b' "g#" : group access : unix access bits

b' "u#" : owner access : unix access bits

b' "o#" : world access : unix access bits

b' ... the access bits are in traditional unix bit formatwith 7 = read/write/execute, 6 = read/write, 4 = read-only.

b'The default access mode is 0664, and the compression levelis ignored since the lib can not yet write zip files, otherwiseit would be the initialisation value for the zlib deflateInitwhere 0 = no-compression, 1 = best-speed, 9 = best-compression.

b'The zzip_fopen function returns a new zzip-handle (use zzip_close to returnit). On error the zzip_fopen function will return null setting errno(3).n'

b'The zzip_freopen function receives an additional argument pointing toa ZZIP_FILE* being already in use. If this extra argument isnull then the zzip_freopen function is identical with calling zzip_fopen

b'Per default, the old file stream is closed and only the internalstructures associated with it are kept. These internal structuresmay be reused for the return value, and this is a lot quicker whenthe filename matches a zipped file that is incidentally in the verysame zip arch as the old filename wrapped in the stream struct.

b'That's simply because the zip arch's central directory does notneed to be read again. As an extension for the zzip_freopen function, if themode-string contains a "q" then the old stream is not closed butleft untouched, instead it is only given as a hint that a newfile handle may share/copy the zip arch structures of the old filehandle if that is possible, i.e when they are in the same zip arch.

b'The zzip_freopen function returns a new zzip-handle (use zzip_close to returnit). On error the zzip_freopen function will return null setting errno(3).n

AUTHOR
b'Guido Draheim <guidod@gmx.de>Tomi Ollila <Tomi.Ollila@iki.fi>

COPYRIGHT
b'Copyright (c) Guido Draheim, use under copyleft (LGPL,MPL)n'

SEE ALSO
b' fopen(2)