PageRenderTime 28ms CodeModel.GetById 16ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/src/zziplib/zzip/memdisk.h

https://bitbucket.org/cabalistic/ogredeps/
C++ Header | 171 lines | 135 code | 26 blank | 10 comment | 9 complexity | d58db38ce5371a5d3ea3b6e571b07d4d MD5 | raw file
  1#ifndef __ZZIP_MEMDISK_H
  2#define __ZZIP_MEMDISK_H
  3
  4/* NOTE: this is part of libzzipmmapped (i.e. it is not libzzip). */
  5
  6#include <zzip/types.h>
  7#include <zzip/mmapped.h>
  8
  9#ifdef __cplusplus
 10extern "C" {
 11#endif
 12
 13typedef struct _zzip_mem_disk ZZIP_MEM_DISK;
 14typedef struct _zzip_mem_entry ZZIP_MEM_ENTRY;
 15
 16struct _zzip_mem_disk {
 17    ZZIP_DISK* disk;
 18    ZZIP_MEM_ENTRY* list;
 19    ZZIP_MEM_ENTRY* last;
 20};
 21
 22#ifndef zzip_mem_disk_extern
 23#define zzip_mem_disk_extern
 24#endif
 25
 26zzip_mem_disk_extern zzip__new__ ZZIP_MEM_DISK*
 27zzip_mem_disk_new (void);
 28zzip_mem_disk_extern zzip__new__ ZZIP_MEM_DISK*
 29zzip_mem_disk_open (char* filename);
 30zzip_mem_disk_extern zzip__new__ ZZIP_MEM_DISK*
 31zzip_mem_disk_fdopen (int fd);
 32zzip_mem_disk_extern zzip__new__ ZZIP_MEM_DISK *
 33zzip_mem_disk_buffer(char *buffer, size_t buflen);
 34zzip_mem_disk_extern void
 35zzip_mem_disk_close (ZZIP_MEM_DISK* _zzip_restrict dir);
 36
 37zzip_mem_disk_extern long
 38zzip_mem_disk_load (ZZIP_MEM_DISK* dir, ZZIP_DISK* disk);
 39zzip_mem_disk_extern void
 40zzip_mem_disk_unload (ZZIP_MEM_DISK* dir);
 41ZZIP_EXTRA_BLOCK*
 42zzip_mem_entry_extra_block (ZZIP_MEM_ENTRY* entry, short datatype);
 43
 44#ifdef USE_INLINE
 45_zzip_inline ZZIP_DISK* zzip_disk (ZZIP_MEM_DISK* dir) { return dir->disk; }
 46#else
 47#define zzip_disk(_X_) ((_X_)->disk)
 48#endif
 49
 50
 51/* these functions are much faster than the orgiinal zzip_disk_ functions */
 52
 53/* zzip_mem_entry <is similar to> zzip_disk_entry */
 54struct _zzip_mem_entry {
 55    struct _zzip_mem_entry* zz_next;
 56    char*            zz_name;      /* zero-terminated (from "filename") */
 57    zzip_byte_t*     zz_data;      /* compressed content start (mmap addr) */
 58    int              zz_flags;     /* (from "z_flags") */
 59    int              zz_compr;     /* (from "z_compr") */
 60    long             zz_mktime;    /* (from "z_dostime") */
 61    long             zz_crc32;     /* (from "z_crc32") */
 62    zzip_off_t       zz_csize;     /* (from "z_csize")  overridden by zip64 */
 63    zzip_off_t       zz_usize;     /* (from "z_usize")  overridden by zip64 */
 64    zzip_off_t       zz_offset;    /* (from "z_offset") overridden by zip64 */
 65    int              zz_diskstart; /* (from "z_diskstart") rridden by zip64 */
 66    int              zz_filetype;  /* (from "z_filetype") */
 67    char*            zz_comment;   /* zero-terminated (from "comment") */
 68    ZZIP_EXTRA_BLOCK* zz_ext[3];   /* terminated by null in z_datatype */
 69};                                 /* the extra blocks are NOT converted */
 70
 71#define _zzip_mem_disk_findfirst(_d_) ((_d_)->list)
 72#define _zzip_mem_disk_findnext(_d_,_e_) (!(_e_)?(_d_)->list:(_e_)->zz_next)
 73#define _zzip_mem_entry_findnext(_e_) ((_e_)->zz_next)
 74
 75#ifndef USE_INLINE
 76#define zzip_mem_disk_findfirst _zzip_mem_disk_findfirst
 77#define zzip_mem_disk_findnext _zzip_mem_disk_findnext
 78#define zzip_mem_entry_findnext _zzip_mem_entry_findnext
 79#else
 80
 81_zzip_inline ZZIP_MEM_ENTRY*
 82zzip_mem_disk_findfirst(ZZIP_MEM_DISK* dir) {
 83    if (! dir) return 0;
 84    return _zzip_mem_disk_findfirst(dir); }
 85_zzip_inline ZZIP_MEM_ENTRY*
 86zzip_mem_disk_findnext(ZZIP_MEM_DISK* dir, ZZIP_MEM_ENTRY* entry) {
 87    if (! dir) return 0;
 88    return _zzip_mem_disk_findnext(dir, entry); }
 89_zzip_inline ZZIP_MEM_ENTRY*
 90zzip_mem_entry_findnext(ZZIP_MEM_ENTRY* entry) {
 91    if (! entry) return 0;
 92    return _zzip_mem_entry_findnext(entry); }
 93#endif
 94
 95#define _zzip_mem_entry_to_name(_e_) ((_e_)->zz_name)
 96#define _zzip_mem_entry_to_comment(_e_) ((_e_)->zz_comment)
 97#define _zzip_mem_entry_strdup_name(_e_) (strdup((_e_)->zz_name))
 98#define _zzip_mem_entry_to_data(_e_) ((_e_)->zz_data)
 99
100#ifndef USE_INLINE
101#define zzip_mem_entry_to_name _zzip_mem_entry_to_name
102#define zzip_mem_entry_to_comment _zzip_mem_entry_to_comment
103#define zzip_mem_entry_strdup_name _zzip_mem_entry_strdup_name
104#define zzip_mem_entry_to_data _zzip_mem_entry_to_data
105#else
106_zzip_inline char*
107zzip_mem_entry_to_name(ZZIP_MEM_ENTRY* entry) {
108    if (! entry) return 0;
109    return _zzip_mem_entry_to_name(entry); }
110_zzip_inline char*
111zzip_mem_entry_to_comment(ZZIP_MEM_ENTRY* entry) {
112    if (! entry) return 0;
113    return _zzip_mem_entry_to_comment(entry); }
114zzip__new__
115_zzip_inline char*
116zzip_mem_entry_strdup_name(ZZIP_MEM_ENTRY* entry) {
117    if (! entry) return 0;
118    return _zzip_mem_entry_strdup_name(entry); }
119_zzip_inline zzip_byte_t*
120zzip_mem_entry_to_data(ZZIP_MEM_ENTRY* entry) {
121    if (! entry) return 0;
122    return _zzip_mem_entry_to_data(entry); }
123#endif
124
125ZZIP_MEM_ENTRY*
126zzip_mem_disk_findfile(ZZIP_MEM_DISK* dir,
127                       char* filename, ZZIP_MEM_ENTRY* after,
128		       zzip_strcmp_fn_t compare);
129
130ZZIP_MEM_ENTRY*
131zzip_mem_disk_findmatch(ZZIP_MEM_DISK* dir,
132                        char* filespec, ZZIP_MEM_ENTRY* after,
133			zzip_fnmatch_fn_t compare, int flags);
134
135/* named access -------------------------------------------------------- */
136#define zzip_mem_entry_usize(_e_) ((_e_)->zz_usize)
137#define zzip_mem_entry_csize(_e_) ((_e_)->zz_csize)
138#define zzip_mem_entry_data_encrypted(_e_) ZZIP_IS_ENCRYPTED((_e_)->zz_flags)
139#define zzip_mem_entry_data_streamed(_e_) ZZIP_IS_STREAMED((_e_)->zz_flags)
140#define zzip_mem_entry_data_comprlevel(_e_) ((_e_)->zz_compr)
141#define zzip_mem_entry_data_stored(_e_) ((_e_)->zz_compr == ZZIP_IS_STORED)
142#define zzip_mem_entry_data_deflated(_e_) ((_e_)->zz_compr == ZZIP_IS_DEFLATED)
143
144/* zzip_mem_disk_file -------------------------------------------------- */
145
146/* since only the header data is being cached, all the real data
147 * operations are actually the same as in mmapped.h - just fopen makes
148 * access to the header data in memory instead of the zip archive.
149 */
150
151typedef ZZIP_DISK_FILE ZZIP_MEM_DISK_FILE;
152
153zzip__new__ ZZIP_MEM_DISK_FILE*
154zzip_mem_entry_fopen (ZZIP_MEM_DISK* dir, ZZIP_MEM_ENTRY* entry);
155zzip__new__ ZZIP_MEM_DISK_FILE*
156zzip_mem_disk_fopen (ZZIP_MEM_DISK* dir, char* filename);
157_zzip_size_t
158zzip_mem_disk_fread (void* ptr, _zzip_size_t size, _zzip_size_t nmemb,
159                     ZZIP_MEM_DISK_FILE* file);
160int
161zzip_mem_disk_fclose (ZZIP_MEM_DISK_FILE* file);
162int
163zzip_mem_disk_feof (ZZIP_MEM_DISK_FILE* file);
164
165/* convert dostime of entry to unix time_t */
166long zzip_disk_entry_get_mktime(ZZIP_DISK_ENTRY* entry);
167
168#ifdef __cplusplus
169}
170#endif
171#endif