libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
Zip

Data Structures

struct  zip_t
 

Macros

#define ZIP_DEFAULT_COMPRESSION_LEVEL   6
 
#define ZIP_ENOINIT   -1
 
#define ZIP_EINVENTNAME   -2
 
#define ZIP_ENOENT   -3
 
#define ZIP_EINVMODE   -4
 
#define ZIP_EINVLVL   -5
 
#define ZIP_ENOSUP64   -6
 
#define ZIP_EMEMSET   -7
 
#define ZIP_EWRTENT   -8
 
#define ZIP_ETDEFLINIT   -9
 
#define ZIP_EINVIDX   -10
 
#define ZIP_ENOHDR   -11
 
#define ZIP_ETDEFLBUF   -12
 
#define ZIP_ECRTHDR   -13
 
#define ZIP_EWRTHDR   -14
 
#define ZIP_EWRTDIR   -15
 
#define ZIP_EOPNFILE   -16
 
#define ZIP_EINVENTTYPE   -17
 
#define ZIP_EMEMNOALLOC   -18
 
#define ZIP_ENOFILE   -19
 
#define ZIP_ENOPERM   -20
 
#define ZIP_EOOMEM   -21
 
#define ZIP_EINVZIPNAME   -22
 
#define ZIP_EMKDIR   -23
 
#define ZIP_ESYMLINK   -24
 
#define ZIP_ECLSZIP   -25
 
#define ZIP_ECAPSIZE   -26
 
#define ZIP_EFSEEK   -27
 
#define ZIP_EFREAD   -28
 
#define ZIP_EFWRITE   -29
 
#define ZIP_ERINIT   -30
 
#define ZIP_EWINIT   -31
 
#define ZIP_EWRINIT   -32
 

Functions

const char * zip_strerror (int errnum)
 
struct zip_tzip_open (const char *zipname, int level, char mode)
 
struct zip_tzip_openwitherror (const char *zipname, int level, char mode, int *errnum)
 
void zip_close (struct zip_t *zip)
 
int zip_is64 (struct zip_t *zip)
 
int zip_offset (struct zip_t *zip, uint64_t *offset)
 
int zip_entry_open (struct zip_t *zip, const char *entryname)
 
int zip_entry_opencasesensitive (struct zip_t *zip, const char *entryname)
 
int zip_entry_openbyindex (struct zip_t *zip, size_t index)
 
int zip_entry_close (struct zip_t *zip)
 
const char * zip_entry_name (struct zip_t *zip)
 
ssize_t zip_entry_index (struct zip_t *zip)
 
int zip_entry_isdir (struct zip_t *zip)
 
unsigned long long zip_entry_size (struct zip_t *zip)
 
unsigned long long zip_entry_uncomp_size (struct zip_t *zip)
 
unsigned long long zip_entry_comp_size (struct zip_t *zip)
 
unsigned int zip_entry_crc32 (struct zip_t *zip)
 
unsigned long long zip_entry_dir_offset (struct zip_t *zip)
 
unsigned long long zip_entry_header_offset (struct zip_t *zip)
 
int zip_entry_write (struct zip_t *zip, const void *buf, size_t bufsize)
 
int zip_entry_fwrite (struct zip_t *zip, const char *filename)
 
ssize_t zip_entry_read (struct zip_t *zip, void **buf, size_t *bufsize)
 
ssize_t zip_entry_noallocread (struct zip_t *zip, void *buf, size_t bufsize)
 
int zip_entry_fread (struct zip_t *zip, const char *filename)
 
int zip_entry_extract (struct zip_t *zip, size_t(*on_extract)(void *arg, uint64_t offset, const void *data, size_t size), void *arg)
 
ssize_t zip_entries_total (struct zip_t *zip)
 
ssize_t zip_entries_delete (struct zip_t *zip, char *const entries[], size_t len)
 
ssize_t zip_entries_deletebyindex (struct zip_t *zip, size_t entries[], size_t len)
 
int zip_stream_extract (const char *stream, size_t size, const char *dir, int(*on_extract)(const char *filename, void *arg), void *arg)
 
struct zip_tzip_stream_open (const char *stream, size_t size, int level, char mode)
 
struct zip_tzip_stream_openwitherror (const char *stream, size_t size, int level, char mode, int *errnum)
 
ssize_t zip_stream_copy (struct zip_t *zip, void **buf, size_t *bufsize)
 
void zip_stream_close (struct zip_t *zip)
 
struct zip_tzip_cstream_open (FILE *stream, int level, char mode)
 
struct zip_tzip_cstream_openwitherror (FILE *stream, int level, char mode, int *errnum)
 
void zip_cstream_close (struct zip_t *zip)
 
int zip_create (const char *zipname, const char *filenames[], size_t len)
 
int zip_extract (const char *zipname, const char *dir, int(*on_extract_entry)(const char *filename, void *arg), void *arg)
 

Detailed Description

Macro Definition Documentation

◆ ZIP_DEFAULT_COMPRESSION_LEVEL

#define ZIP_DEFAULT_COMPRESSION_LEVEL   6

Default zip compression level.

Definition at line 62 of file zip.h.

◆ ZIP_ECAPSIZE

#define ZIP_ECAPSIZE   -26

Definition at line 92 of file zip.h.

◆ ZIP_ECLSZIP

#define ZIP_ECLSZIP   -25

Definition at line 91 of file zip.h.

◆ ZIP_ECRTHDR

#define ZIP_ECRTHDR   -13

Definition at line 79 of file zip.h.

◆ ZIP_EFREAD

#define ZIP_EFREAD   -28

Definition at line 94 of file zip.h.

◆ ZIP_EFSEEK

#define ZIP_EFSEEK   -27

Definition at line 93 of file zip.h.

◆ ZIP_EFWRITE

#define ZIP_EFWRITE   -29

Definition at line 95 of file zip.h.

◆ ZIP_EINVENTNAME

#define ZIP_EINVENTNAME   -2

Definition at line 68 of file zip.h.

◆ ZIP_EINVENTTYPE

#define ZIP_EINVENTTYPE   -17

Definition at line 83 of file zip.h.

◆ ZIP_EINVIDX

#define ZIP_EINVIDX   -10

Definition at line 76 of file zip.h.

◆ ZIP_EINVLVL

#define ZIP_EINVLVL   -5

Definition at line 71 of file zip.h.

◆ ZIP_EINVMODE

#define ZIP_EINVMODE   -4

Definition at line 70 of file zip.h.

◆ ZIP_EINVZIPNAME

#define ZIP_EINVZIPNAME   -22

Definition at line 88 of file zip.h.

◆ ZIP_EMEMNOALLOC

#define ZIP_EMEMNOALLOC   -18

Definition at line 84 of file zip.h.

◆ ZIP_EMEMSET

#define ZIP_EMEMSET   -7

Definition at line 73 of file zip.h.

◆ ZIP_EMKDIR

#define ZIP_EMKDIR   -23

Definition at line 89 of file zip.h.

◆ ZIP_ENOENT

#define ZIP_ENOENT   -3

Definition at line 69 of file zip.h.

◆ ZIP_ENOFILE

#define ZIP_ENOFILE   -19

Definition at line 85 of file zip.h.

◆ ZIP_ENOHDR

#define ZIP_ENOHDR   -11

Definition at line 77 of file zip.h.

◆ ZIP_ENOINIT

#define ZIP_ENOINIT   -1

Error codes

Definition at line 67 of file zip.h.

◆ ZIP_ENOPERM

#define ZIP_ENOPERM   -20

Definition at line 86 of file zip.h.

◆ ZIP_ENOSUP64

#define ZIP_ENOSUP64   -6

Definition at line 72 of file zip.h.

◆ ZIP_EOOMEM

#define ZIP_EOOMEM   -21

Definition at line 87 of file zip.h.

◆ ZIP_EOPNFILE

#define ZIP_EOPNFILE   -16

Definition at line 82 of file zip.h.

◆ ZIP_ERINIT

#define ZIP_ERINIT   -30

Definition at line 96 of file zip.h.

◆ ZIP_ESYMLINK

#define ZIP_ESYMLINK   -24

Definition at line 90 of file zip.h.

◆ ZIP_ETDEFLBUF

#define ZIP_ETDEFLBUF   -12

Definition at line 78 of file zip.h.

◆ ZIP_ETDEFLINIT

#define ZIP_ETDEFLINIT   -9

Definition at line 75 of file zip.h.

◆ ZIP_EWINIT

#define ZIP_EWINIT   -31

Definition at line 97 of file zip.h.

◆ ZIP_EWRINIT

#define ZIP_EWRINIT   -32

Definition at line 98 of file zip.h.

◆ ZIP_EWRTDIR

#define ZIP_EWRTDIR   -15

Definition at line 81 of file zip.h.

◆ ZIP_EWRTENT

#define ZIP_EWRTENT   -8

Definition at line 74 of file zip.h.

◆ ZIP_EWRTHDR

#define ZIP_EWRTHDR   -14

Definition at line 80 of file zip.h.

Function Documentation

◆ zip_close()

void zip_close ( struct zip_t zip)
extern

Closes the zip archive, releases resources - always finalize.

Parameters
zipzip archive handler.

Definition at line 1032 of file zip.c.

◆ zip_create()

int zip_create ( const char *  zipname,
const char *  filenames[],
size_t  len 
)
extern

Creates a new archive and puts files into a single zip archive.

Parameters
zipnamezip archive file.
filenamesinput files.
lennumber of input files.
Returns
the return code - 0 on success, negative number (< 0) on error.

Definition at line 1992 of file zip.c.

◆ zip_cstream_close()

void zip_cstream_close ( struct zip_t zip)
extern

Closes the zip archive, releases resources - always finalize. This function is an alias for zip_close function.

Parameters
zipzip archive handler.

Definition at line 1990 of file zip.c.

◆ zip_cstream_open()

struct zip_t * zip_cstream_open ( FILE *  stream,
int  level,
char  mode 
)
extern

Opens zip archive from existing FILE stream with compression level using the given mode. The stream will not be closed when calling zip_close.

Parameters
streamC FILE stream.
levelcompression level (0-9 are the standard zlib-style levels).
modefile access mode. This mode should be equivalent to the mode provided when opening the file.
  • 'r': opens a file for reading/extracting (the file must exists).
  • 'w': creates an empty file for writing.
  • 'a': appends to an existing archive.
Returns
the zip archive handler or NULL on error

Definition at line 1906 of file zip.c.

◆ zip_cstream_openwitherror()

struct zip_t * zip_cstream_openwitherror ( FILE *  stream,
int  level,
char  mode,
int *  errnum 
)
extern

Opens zip archive from existing FILE stream with compression level using the given mode. The function additionally returns

Parameters
errnum- The stream will not be closed when calling zip_close.
streamC FILE stream.
levelcompression level (0-9 are the standard zlib-style levels).
modefile access mode.
  • 'r': opens a file for reading/extracting (the file must exists).
  • 'w': creates an empty file for writing.
  • 'a': appends to an existing archive.
errnum0 on success, negative number (< 0) on error.
Returns
the zip archive handler or NULL on error

Definition at line 1911 of file zip.c.

◆ zip_entries_delete()

ssize_t zip_entries_delete ( struct zip_t zip,
char *const  entries[],
size_t  len 
)
extern

Deletes zip archive entries.

Parameters
zipzip archive handler.
entriesarray of zip archive entries to be deleted.
lenthe number of entries to be deleted.
Returns
the number of deleted entries, or negative number (< 0) on error.

Definition at line 1739 of file zip.c.

◆ zip_entries_deletebyindex()

ssize_t zip_entries_deletebyindex ( struct zip_t zip,
size_t  entries[],
size_t  len 
)
extern

Deletes zip archive entries.

Parameters
zipzip archive handler.
entriesarray of zip archive entries indices to be deleted.
lenthe number of entries to be deleted.
Returns
the number of deleted entries, or negative number (< 0) on error.

Definition at line 1774 of file zip.c.

◆ zip_entries_total()

ssize_t zip_entries_total ( struct zip_t zip)
extern

Returns the number of all entries (files and directories) in the zip archive.

Parameters
zipzip archive handler.
Returns
the return code - the number of entries on success, negative number (< 0) on error.

Definition at line 1730 of file zip.c.

◆ zip_entry_close()

int zip_entry_close ( struct zip_t zip)
extern

Closes a zip entry, flushes buffer and releases resources.

Parameters
zipzip archive handler.
Returns
the return code - 0 on success, negative number (< 0) on error.

Definition at line 1348 of file zip.c.

◆ zip_entry_comp_size()

unsigned long long zip_entry_comp_size ( struct zip_t zip)
extern

Returns the compressed size of the current zip entry.

Parameters
zipzip archive handler.
Returns
the compressed size in bytes.

Definition at line 1485 of file zip.c.

◆ zip_entry_crc32()

unsigned int zip_entry_crc32 ( struct zip_t zip)
extern

Returns CRC-32 checksum of the current zip entry.

Parameters
zipzip archive handler.
Returns
the CRC-32 checksum.

Definition at line 1489 of file zip.c.

◆ zip_entry_dir_offset()

unsigned long long zip_entry_dir_offset ( struct zip_t zip)
extern

Returns byte offset of the current zip entry in the archive's central directory.

Parameters
zipzip archive handler.
Returns
the offset in bytes.

Definition at line 1493 of file zip.c.

◆ zip_entry_extract()

int zip_entry_extract ( struct zip_t zip,
size_t(*)(void *arg, uint64_t offset, const void *data, size_t size)  on_extract,
void *  arg 
)
extern

Extracts the current zip entry using a callback function (on_extract).

Parameters
zipzip archive handler.
on_extractcallback function.
argopaque pointer (optional argument, which you can pass to the on_extract callback)
Returns
the return code - 0 on success, negative number (< 0) on error.

◆ zip_entry_fread()

int zip_entry_fread ( struct zip_t zip,
const char *  filename 
)
extern

Extracts the current zip entry into output file.

Parameters
zipzip archive handler.
filenameoutput file.
Returns
the return code - 0 on success, negative number (< 0) on error.

Definition at line 1657 of file zip.c.

◆ zip_entry_fwrite()

int zip_entry_fwrite ( struct zip_t zip,
const char *  filename 
)
extern

Compresses a file for the current zip entry.

Parameters
zipzip archive handler.
filenameinput file.
Returns
the return code - 0 on success, negative number (< 0) on error.

Definition at line 1539 of file zip.c.

◆ zip_entry_header_offset()

unsigned long long zip_entry_header_offset ( struct zip_t zip)
extern

Returns the current zip entry's local header file offset in bytes.

Parameters
zipzip archive handler.
Returns
the entry's local header file offset in bytes.

Definition at line 1497 of file zip.c.

◆ zip_entry_index()

ssize_t zip_entry_index ( struct zip_t zip)
extern

Returns an index of the current zip entry.

Parameters
zipzip archive handler.
Returns
the index on success, negative number (< 0) on error.

Definition at line 1452 of file zip.c.

◆ zip_entry_isdir()

int zip_entry_isdir ( struct zip_t zip)
extern

Determines if the current zip entry is a directory entry.

Parameters
zipzip archive handler.
Returns
the return code - 1 (true), 0 (false), negative number (< 0) on error.

Definition at line 1461 of file zip.c.

◆ zip_entry_name()

const char * zip_entry_name ( struct zip_t zip)
extern

Returns a local name of the current zip entry.

The main difference between user's entry name and local entry name is optional relative path. Following .ZIP File Format Specification - the path stored MUST not contain a drive or device letter, or a leading slash. All slashes MUST be forward slashes '/' as opposed to backwards slashes '\' for compatibility with Amiga and UNIX file systems etc.

Parameters
zipzip archive handler.
Returns
the pointer to the current zip entry name, or NULL on error.

Definition at line 1444 of file zip.c.

◆ zip_entry_noallocread()

ssize_t zip_entry_noallocread ( struct zip_t zip,
void *  buf,
size_t  bufsize 
)
extern

Extracts the current zip entry into a memory buffer using no memory allocation.

Parameters
zipzip archive handler.
bufpreallocated output buffer.
bufsizeoutput buffer size (in bytes).
Note
ensure supplied output buffer is large enough. zip_entry_size function (returns uncompressed size for the current entry) can be handy to estimate how big buffer is needed. For large entries, please take a look at zip_entry_extract function.
Returns
the return code - the number of bytes actually read on success. Otherwise a negative number (< 0) on error (e.g. bufsize is not large enough).

Definition at line 1634 of file zip.c.

◆ zip_entry_open()

int zip_entry_open ( struct zip_t zip,
const char *  entryname 
)
extern

Opens an entry by name in the zip archive.

For zip archive opened in 'w' or 'a' mode the function will append a new entry. In readonly mode the function tries to locate the entry in global dictionary.

Parameters
zipzip archive handler.
entrynamean entry name in local dictionary.
Returns
the return code - 0 on success, negative number (< 0) on error.

Definition at line 1277 of file zip.c.

◆ zip_entry_openbyindex()

int zip_entry_openbyindex ( struct zip_t zip,
size_t  index 
)
extern

Opens a new entry by index in the zip archive.

This function is only valid if zip archive was opened in 'r' (readonly) mode.

Parameters
zipzip archive handler.
indexindex in local dictionary.
Returns
the return code - 0 on success, negative number (< 0) on error.

Definition at line 1285 of file zip.c.

◆ zip_entry_opencasesensitive()

int zip_entry_opencasesensitive ( struct zip_t zip,
const char *  entryname 
)
extern

Opens an entry by name in the zip archive.

For zip archive opened in 'w' or 'a' mode the function will append a new entry. In readonly mode the function tries to locate the entry in global dictionary (case sensitive).

Parameters
zipzip archive handler.
entrynamean entry name in local dictionary (case sensitive).
Returns
the return code - 0 on success, negative number (< 0) on error.

Definition at line 1281 of file zip.c.

◆ zip_entry_read()

ssize_t zip_entry_read ( struct zip_t zip,
void **  buf,
size_t *  bufsize 
)
extern

Extracts the current zip entry into output buffer.

The function allocates sufficient memory for a output buffer.

Parameters
zipzip archive handler.
bufoutput buffer.
bufsizeoutput buffer size (in bytes).
Note
remember to release memory allocated for a output buffer. for large entries, please take a look at zip_entry_extract function.
Returns
the return code - the number of bytes actually read on success. Otherwise a negative number (< 0) on error.

Definition at line 1604 of file zip.c.

◆ zip_entry_size()

unsigned long long zip_entry_size ( struct zip_t zip)
extern

Returns the uncompressed size of the current zip entry. Alias for zip_entry_uncomp_size (for backward compatibility).

Parameters
zipzip archive handler.
Returns
the uncompressed size in bytes.

Definition at line 1477 of file zip.c.

◆ zip_entry_uncomp_size()

unsigned long long zip_entry_uncomp_size ( struct zip_t zip)
extern

Returns the uncompressed size of the current zip entry.

Parameters
zipzip archive handler.
Returns
the uncompressed size in bytes.

Definition at line 1481 of file zip.c.

◆ zip_entry_write()

int zip_entry_write ( struct zip_t zip,
const void *  buf,
size_t  bufsize 
)
extern

Compresses an input buffer for the current zip entry.

Parameters
zipzip archive handler.
bufinput buffer.
bufsizeinput buffer size (in bytes).
Returns
the return code - 0 on success, negative number (< 0) on error.

Definition at line 1501 of file zip.c.

◆ zip_extract()

int zip_extract ( const char *  zipname,
const char *  dir,
int(*)(const char *filename, void *arg)  on_extract_entry,
void *  arg 
)
extern

Extracts a zip archive file into directory.

If on_extract_entry is not NULL, the callback will be called after successfully extracted each zip entry. Returning a negative value from the callback will cause abort and return an error. The last argument (void *arg) is optional, which you can use to pass data to the on_extract_entry callback.

Parameters
zipnamezip archive file.
diroutput directory.
on_extract_entryon extract callback.
argopaque pointer.
Returns
the return code - 0 on success, negative number (< 0) on error.

Definition at line 2074 of file zip.c.

◆ zip_is64()

int zip_is64 ( struct zip_t zip)
extern

Determines if the archive has a zip64 end of central directory headers.

Parameters
zipzip archive handler.
Returns
the return code - 1 (true), 0 (false), negative number (< 0) on error.

Definition at line 1054 of file zip.c.

◆ zip_offset()

int zip_offset ( struct zip_t zip,
uint64_t *  offset 
)
extern

Returns the offset in the stream where the zip header is located.

Parameters
zipzip archive handler.
offsetzip header offset.
Returns
the return code - 0 if successful, negative number (< 0) on error.

Definition at line 1063 of file zip.c.

◆ zip_open()

struct zip_t * zip_open ( const char *  zipname,
int  level,
char  mode 
)
extern

Opens zip archive with compression level using the given mode.

Parameters
zipnamezip archive file name.
levelcompression level (0-9 are the standard zlib-style levels).
modefile access mode.
  • 'r': opens a file for reading/extracting (the file must exists).
  • 'w': creates an empty file for writing.
  • 'a': appends to an existing archive.
Returns
the zip archive handler or NULL on error

Definition at line 939 of file zip.c.

◆ zip_openwitherror()

struct zip_t * zip_openwitherror ( const char *  zipname,
int  level,
char  mode,
int *  errnum 
)
extern

Opens zip archive with compression level using the given mode. The function additionally returns

Parameters
errnum-
zipnamezip archive file name.
levelcompression level (0-9 are the standard zlib-style levels).
modefile access mode.
  • 'r': opens a file for reading/extracting (the file must exists).
  • 'w': creates an empty file for writing.
  • 'a': appends to an existing archive.
errnum0 on success, negative number (< 0) on error.
Returns
the zip archive handler or NULL on error

Definition at line 944 of file zip.c.

◆ zip_stream_close()

void zip_stream_close ( struct zip_t zip)
extern

Close zip archive releases resources.

Parameters
zipzip archive handler.
Returns

Definition at line 1898 of file zip.c.

◆ zip_stream_copy()

ssize_t zip_stream_copy ( struct zip_t zip,
void **  buf,
size_t *  bufsize 
)
extern

Copy zip archive stream output buffer.

Parameters
zipzip archive handler.
bufoutput buffer. User should free buf.
bufsizeoutput buffer size (in bytes).
Returns
copy size

Definition at line 1879 of file zip.c.

◆ zip_stream_extract()

int zip_stream_extract ( const char *  stream,
size_t  size,
const char *  dir,
int(*)(const char *filename, void *arg)  on_extract,
void *  arg 
)
extern

Extracts a zip archive stream into directory.

If on_extract is not NULL, the callback will be called after successfully extracted each zip entry. Returning a negative value from the callback will cause abort and return an error. The last argument (void *arg) is optional, which you can use to pass data to the on_extract callback.

Parameters
streamzip archive stream.
sizestream size.
diroutput directory.
on_extracton extract callback.
argopaque pointer.
Returns
the return code - 0 on success, negative number (< 0) on error.

Definition at line 1809 of file zip.c.

◆ zip_stream_open()

struct zip_t * zip_stream_open ( const char *  stream,
size_t  size,
int  level,
char  mode 
)
extern

Opens zip archive stream into memory.

Parameters
streamzip archive stream.
sizestream size.
levelcompression level (0-9 are the standard zlib-style levels).
modefile access mode.
  • 'r': opens a file for reading/extracting (the file must exists).
  • 'w': creates an empty file for writing.
  • 'a': appends to an existing archive.
Returns
the zip archive handler or NULL on error

Definition at line 1829 of file zip.c.

◆ zip_stream_openwitherror()

struct zip_t * zip_stream_openwitherror ( const char *  stream,
size_t  size,
int  level,
char  mode,
int *  errnum 
)
extern

Opens zip archive stream into memory. The function additionally returns

Parameters
errnum-
streamzip archive stream.
sizestream size.*
levelcompression level (0-9 are the standard zlib-style levels).
modefile access mode.
  • 'r': opens a file for reading/extracting (the file must exists).
  • 'w': creates an empty file for writing.
  • 'a': appends to an existing archive.
errnum0 on success, negative number (< 0) on error.
Returns
the zip archive handler or NULL on error

Definition at line 1835 of file zip.c.

◆ zip_strerror()

const char * zip_strerror ( int  errnum)
extern

Looks up the error message string corresponding to an error number.

Parameters
errnumerror number
Returns
error message string corresponding to errnum or NULL if error is not found.

Definition at line 153 of file zip.c.