~ubuntu-branches/ubuntu/warty/zziplib/warty

« back to all changes in this revision

Viewing changes to zzip/format.h

  • Committer: Bazaar Package Importer
  • Author(s): Aurelien Jarno
  • Date: 2004-03-29 12:41:28 UTC
  • Revision ID: james.westby@ubuntu.com-20040329124128-hf9y5elywpavuh5y
Tags: upstream-0.10.82
ImportĀ upstreamĀ versionĀ 0.10.82

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Author: 
 
3
 *      Guido Draheim <guidod@gmx.de>
 
4
 *
 
5
 *      Copyright (c) 2000,2001 Guido Draheim
 
6
 *          All rights reserved
 
7
 *          use under the restrictions of the
 
8
 *          Lesser GNU General Public License
 
9
 *
 
10
 *  The information was taken from appnote-981119-iz.zip
 
11
 *  at http://www.freesoftware.com/pub/infozip/doc/
 
12
 *  which in turn is based on PKWARE's appnote.txt
 
13
 */
 
14
#ifndef _ZZIP_FORMAT_H /* zzipformat.h */
 
15
#define _ZZIP_FORMAT_H
 
16
 
 
17
#include <zzip/lib.h>
 
18
/* we have ICO C 9X types defined */
 
19
 
 
20
/* 
 
21
 * Overall zipfile format 
 
22
 *  [local file header + file data + data descriptr] ... [central directory] [EOD record] 
 
23
 */
 
24
 
 
25
# ifdef _MSC_VER
 
26
# pragma pack(push, 1)
 
27
# endif
 
28
 
 
29
struct zzip_version 
 
30
 
31
    char   version[1]; 
 
32
    char   ostype[1]; 
 
33
} __attribute__((packed));
 
34
 
 
35
struct zzip_dostime 
 
36
 
37
    char   time[2]; 
 
38
    char   date[2]; 
 
39
} __attribute__((packed)); 
 
40
 
 
41
#define ZZIP_CHECKMAGIC(__p,__A,__B,__C,__D) \
 
42
    ( (((char*)(__p))[0]==(__A)) && \
 
43
      (((char*)(__p))[1]==(__B)) && \
 
44
      (((char*)(__p))[2]==(__C)) && \
 
45
      (((char*)(__p))[3]==(__D)) )
 
46
 
 
47
/* A. Local file header */
 
48
struct zzip_file_header
 
49
{
 
50
#   define ZZIP_FILE_HEADER_MAGIC 0x04034b50
 
51
#   define ZZIP_FILE_HEADER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\3','\4')
 
52
    char   z_magic[4]; /* local file header signature (0x04034b50) */
 
53
    struct zzip_version z_extract; /* version needed to extract */
 
54
    char   z_flags[2]; /* general purpose bit flag */
 
55
    char   z_compr[2]; /* compression method */
 
56
    struct zzip_dostime z_dostime; /* last mod file time (dos format) */
 
57
    char   z_crc32[4]; /* crc-32 */
 
58
    char   z_csize[4]; /* compressed size */
 
59
    char   z_usize[4]; /* uncompressed size */
 
60
    char   z_namlen[2]; /* filename length (null if stdin) */
 
61
    char   z_extras[2]; /* extra field length */
 
62
    /* followed by filename (of variable size) */
 
63
    /* followed by extra field (of variable size) */
 
64
} __attribute__((packed));
 
65
 
 
66
/* B. data descriptor 
 
67
 * the data descriptor exists only if bit 3 of z_flags is set. It is byte aligned
 
68
 * and immediately follows the last byte of compressed data. It is only used if
 
69
 * the output media of the compressor was not seekable, eg. standard output.
 
70
 */
 
71
struct zzip_file_trailer
 
72
{
 
73
#   define ZZIP_FILE_TRAILER_MAGIC 0x08074B50
 
74
#   define ZZIP_FILE_TRAILER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\7','\8')
 
75
    uint32_t z_magic; /* data descriptor signature (0x08074b50) */
 
76
    uint32_t z_crc32; /* crc-32 */
 
77
    uint32_t z_csize; /* compressed size */
 
78
    uint32_t z_usize; /* uncompressed size */
 
79
} __attribute__((packed));
 
80
 
 
81
/* C. central directory structure:
 
82
    [file header] . . . end of central dir record  
 
83
*/
 
84
 
 
85
/* directory file header 
 
86
 * - a single entry including filename, extras and comment may not exceed 64k.
 
87
 */
 
88
 
 
89
struct zzip_root_dirent
 
90
{
 
91
#   define ZZIP_ROOT_DIRENT_MAGIC 0x02014b50
 
92
#   define ZZIP_ROOT_DIRENT_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\1','\2')
 
93
    char  z_magic[4];  /* central file header signature (0x02014b50) */
 
94
    struct zzip_version z_encoder;  /* version made by */
 
95
    struct zzip_version z_extract;  /* version need to extract */
 
96
    char  z_flags[2];  /* general purpose bit flag */
 
97
    char  z_compr[2];  /* compression method */
 
98
    struct zzip_dostime z_dostime;  /* last mod file time&date (dos format) */
 
99
    char  z_crc32[4];  /* crc-32 */
 
100
    char  z_csize[4];  /* compressed size */
 
101
    char  z_usize[4];  /* uncompressed size */
 
102
    char  z_namlen[2]; /* filename length (null if stdin) */
 
103
    char  z_extras[2];  /* extra field length */
 
104
    char  z_comment[2]; /* file comment length */
 
105
    char  z_diskstart[2]; /* disk number of start (if spanning zip over multiple disks) */
 
106
    char  z_filetype[2];  /* internal file attributes, bit0 = ascii */
 
107
    char  z_filemode[4];  /* extrnal file attributes, eg. msdos attrib byte */
 
108
    char  z_off[4];    /* relative offset of local file header, seekval if singledisk */
 
109
    /* followed by filename (of variable size) */
 
110
    /* followed by extra field (of variable size) */
 
111
    /* followed by file comment (of variable size) */
 
112
} __attribute__((packed)); 
 
113
 
 
114
/* end of central dir record */
 
115
struct zzip_disk_trailer
 
116
{
 
117
#   define ZZIP_DISK_TRAILER_MAGIC 0x06054b50
 
118
#   define ZZIP_DISK_TRAILER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\5','\6')
 
119
    char  z_magic[4]; /* end of central dir signature (0x06054b50) */
 
120
    char  z_disk[2];  /* number of this disk */
 
121
    char  z_finaldisk[2]; /* number of the disk with the start of the central dir */
 
122
    char  z_entries[2]; /* total number of entries in the central dir on this disk */
 
123
    char  z_finalentries[2]; /* total number of entries in the central dir */
 
124
    char  z_rootsize[4]; /* size of the central directory */
 
125
    char  z_rootseek[4]; /* offset of start of central directory with respect to *
 
126
                          * the starting disk number */
 
127
    char  z_comment[2];  /* zipfile comment length */
 
128
    /* followed by zipfile comment (of variable size) */
 
129
} __attribute__((packed));
 
130
 
 
131
/* z_flags */
 
132
#define ZZIP_IS_ENCRYPTED(p)    ((*(unsigned char*)p)&1)
 
133
#define ZZIP_IS_COMPRLEVEL(p)  (((*(unsigned char*)p)>>1)&3)
 
134
#define ZZIP_IS_STREAMED(p)    (((*(unsigned char*)p)>>3)&1)
 
135
 
 
136
/* z_compr */
 
137
#define ZZIP_IS_STORED          0
 
138
#define ZZIP_IS_SHRUNK          1
 
139
#define ZZIP_IS_REDUCEDx1       2
 
140
#define ZZIP_IS_REDUCEDx2       3
 
141
#define ZZIP_IS_REDUCEDx3       4
 
142
#define ZZIP_IS_REDUCEDx4       5
 
143
#define ZZIP_IS_IMPLODED        6
 
144
#define ZZIP_IS_TOKENIZED       7
 
145
#define ZZIP_IS_DEFLATED        8
 
146
#define ZZIP_IS_DEFLATED_BETTER 9
 
147
#define ZZIP_IS_IMPLODED_BETTER 10
 
148
 
 
149
# ifdef _MSC_VER
 
150
# pragma pack(pop)
 
151
# endif
 
152
 
 
153
#endif /* _ZZIPFORMAT_H */
 
154
 
 
155
 
 
156
 
 
157