| 1 |
#ifndef _ZZIP_FSEEKO_H_ |
| 2 |
#define _ZZIP_FSEEKO_H_ |
| 3 |
/* |
| 4 |
* NOTE: this is part of libzzipfseeko (i.e. it is not libzzip). |
| 5 |
* |
| 6 |
* simplified zip disk access using fseeko on a stdio FILE handle |
| 7 |
* |
| 8 |
* Author: |
| 9 |
* Guido Draheim <[email protected]> |
| 10 |
* |
| 11 |
* Copyright (c) Guido Draheim, use under copyleft (LGPL,MPL) |
| 12 |
*/ |
| 13 |
|
| 14 |
|
| 15 |
#include <zzip/types.h> |
| 16 |
#include <stdio.h> |
| 17 |
|
| 18 |
#ifdef _ZZIP_ENTRY_STRUCT |
| 19 |
#include <zlib.h> |
| 20 |
#include <zzip/format.h> |
| 21 |
#endif |
| 22 |
|
| 23 |
#ifdef __cplusplus |
| 24 |
extern "C" { |
| 25 |
#endif |
| 26 |
|
| 27 |
typedef struct zzip_entry ZZIP_ENTRY; |
| 28 |
typedef struct zzip_entry_file ZZIP_ENTRY_FILE; |
| 29 |
|
| 30 |
typedef int (*zzip_strcmp_fn_t)(char*, char*); |
| 31 |
typedef int (*zzip_fnmatch_fn_t)(char*, char*, int); |
| 32 |
|
| 33 |
#ifndef zzip_entry_extern |
| 34 |
#define zzip_entry_extern extern |
| 35 |
#endif |
| 36 |
|
| 37 |
zzip_entry_extern zzip_off_t |
| 38 |
zzip_entry_data_offset(ZZIP_ENTRY* entry); |
| 39 |
|
| 40 |
zzip__new__ |
| 41 |
zzip_entry_extern ZZIP_ENTRY* |
| 42 |
zzip_entry_findfirst(FILE* file); |
| 43 |
|
| 44 |
zzip__new__ |
| 45 |
zzip_entry_extern ZZIP_ENTRY* |
| 46 |
zzip_entry_findnext(ZZIP_ENTRY* _zzip_restrict entry); |
| 47 |
|
| 48 |
#define zzip_entry_findlast zzip_entry_free |
| 49 |
#define zzip_entry_findlastfile zzip_entry_free |
| 50 |
#define zzip_entry_findlastmatch zzip_entry_free |
| 51 |
|
| 52 |
zzip_entry_extern int |
| 53 |
zzip_entry_free(ZZIP_ENTRY* entry); |
| 54 |
|
| 55 |
zzip__new__ |
| 56 |
zzip_entry_extern char* |
| 57 |
zzip_entry_strdup_name(ZZIP_ENTRY* entry); |
| 58 |
zzip_entry_extern char* |
| 59 |
zzip_entry_to_data(ZZIP_ENTRY* entry); |
| 60 |
|
| 61 |
zzip__new__ |
| 62 |
zzip_entry_extern ZZIP_ENTRY* |
| 63 |
zzip_entry_findfile(FILE* disk, char* filename, |
| 64 |
ZZIP_ENTRY* _zzip_restrict old, |
| 65 |
zzip_strcmp_fn_t compare); |
| 66 |
zzip__new__ |
| 67 |
zzip_entry_extern ZZIP_ENTRY* |
| 68 |
zzip_entry_findmatch(FILE* disk, char* filespec, |
| 69 |
ZZIP_ENTRY* _zzip_restrict old, |
| 70 |
zzip_fnmatch_fn_t compare, int flags); |
| 71 |
zzip__new__ |
| 72 |
zzip_entry_extern ZZIP_ENTRY_FILE* |
| 73 |
zzip_entry_fopen (ZZIP_ENTRY* entry, int takeover); |
| 74 |
|
| 75 |
zzip__new__ |
| 76 |
zzip_entry_extern ZZIP_ENTRY_FILE* |
| 77 |
zzip_entry_ffile (FILE* disk, char* filename); |
| 78 |
|
| 79 |
zzip_entry_extern _zzip_size_t |
| 80 |
zzip_entry_fread (void* ptr, _zzip_size_t size, _zzip_size_t nmemb, |
| 81 |
ZZIP_ENTRY_FILE* file); |
| 82 |
zzip_entry_extern int |
| 83 |
zzip_entry_fclose (ZZIP_ENTRY_FILE* file); |
| 84 |
int |
| 85 |
zzip_entry_feof (ZZIP_ENTRY_FILE* file); |
| 86 |
|
| 87 |
# ifdef _ZZIP_ENTRY_STRUCT |
| 88 |
# ifdef __cplusplus |
| 89 |
# define __zzip_entry_extends_zzip_disk_entry |
| 90 |
struct zzip_entry : public struct zzip_disk_entry |
| 91 |
{ |
| 92 |
char* _zzip_restrict tail; |
| 93 |
zzip_off_t tailalloc; /* the allocated size of tail */ |
| 94 |
FILE* diskfile; /* a file reference */ |
| 95 |
zzip_off_t disksize; /* the size of the file */ |
| 96 |
zzip_off_t headseek; /* the offset within the file */ |
| 97 |
zzip_off_t zz_usize; |
| 98 |
zzip_off_t zz_csize; /* items scanned from header */ |
| 99 |
zzip_off_t zz_offset; /* or zip64 extension block */ |
| 100 |
int zz_diskstart; |
| 101 |
}; |
| 102 |
# define zzip_entry_d(_p) (_p) |
| 103 |
# else |
| 104 |
struct zzip_entry /* : struct zzip_disk_entry */ |
| 105 |
{ |
| 106 |
struct zzip_disk_entry head; |
| 107 |
char* _zzip_restrict tail; |
| 108 |
zzip_off_t tailalloc; /* the allocated size of tail */ |
| 109 |
FILE* diskfile; /* a file reference */ |
| 110 |
zzip_off_t disksize; /* the size of the file */ |
| 111 |
zzip_off_t headseek; /* the offset within the file */ |
| 112 |
zzip_off_t zz_usize; |
| 113 |
zzip_off_t zz_csize; /* items scanned from header */ |
| 114 |
zzip_off_t zz_offset; /* or zip64 extension block */ |
| 115 |
int zz_diskstart; |
| 116 |
}; |
| 117 |
# define zzip_entry_d(_p) (&(_p)->head) |
| 118 |
# endif /* __cplusplus */ |
| 119 |
# endif /* _ZZIP_MEM_ENTRY_PRIVATE */ |
| 120 |
|
| 121 |
#ifdef _ZZIP_ENTRY_STRUCT |
| 122 |
/* zzip_entry is-a zip_disk_entry => fetch.h */ |
| 123 |
#define zzip_entry_csize(__p) ((zzip_size_t) \ |
| 124 |
zzip_disk_entry_get_csize(zzip_entry_d(__p))) |
| 125 |
#define zzip_entry_usize(__p) ((zzip_size_t) \ |
| 126 |
zzip_disk_entry_get_usize(zzip_entry_d(__p))) |
| 127 |
#define zzip_entry_compr(__p) ( \ |
| 128 |
zzip_disk_entry_get_compr(zzip_entry_d(__p))) |
| 129 |
#define zzip_entry_flags(__p) ( \ |
| 130 |
zzip_disk_entry_get_flags(zzip_entry_d(__p))) |
| 131 |
#define zzip_entry_namlen(__p) ((zzip_size_t) \ |
| 132 |
zzip_disk_entry_get_namlen(zzip_entry_d(__p))) |
| 133 |
#define zzip_entry_extras(__p) ((zzip_size_t) \ |
| 134 |
zzip_disk_entry_get_extras(zzip_entry_d(__p))) |
| 135 |
#define zzip_entry_comment(__p) ((zzip_size_t) \ |
| 136 |
zzip_disk_entry_get_comment(zzip_entry_d(__p))) |
| 137 |
#define zzip_entry_diskstart(__p) ((int) \ |
| 138 |
zzip_disk_entry_get_diskstart(zzip_entry_d(__p))) |
| 139 |
#define zzip_entry_filetype(__p) ((int) \ |
| 140 |
zzip_disk_entry_get_filetype(zzip_entry_d(__p))) |
| 141 |
#define zzip_entry_filemode(__p) ((int) \ |
| 142 |
zzip_disk_entry_get_filemode(zzip_entry_d(__p))) |
| 143 |
#define zzip_entry_fileoffset(__p) ((zzip_off_t) \ |
| 144 |
zzip_disk_entry_get_offset(zzip_entry_d(__p))) |
| 145 |
#define zzip_entry_sizeof_tail(__p) ((zzip_size_t) \ |
| 146 |
zzip_disk_entry_sizeof_tails(zzip_entry_d(__p))) |
| 147 |
#endif |
| 148 |
|
| 149 |
#ifdef __cplusplus |
| 150 |
extern "C" { |
| 151 |
} |
| 152 |
#endif |
| 153 |
#endif |
| 154 |
|