]> git.sesse.net Git - vlc/blob - modules/gui/skins2/unzip/ioapi.c
7f20c182f98f794eb8170d78e4fac5949371ac16
[vlc] / modules / gui / skins2 / unzip / ioapi.c
1 /* ioapi.c -- IO base function header for compress/uncompress .zip\r
2    files using zlib + zip or unzip API\r
3 \r
4    Version 1.01e, February 12th, 2005\r
5 \r
6    Copyright (C) 1998-2005 Gilles Vollant\r
7 */\r
8 \r
9 #include <stdio.h>\r
10 #include <stdlib.h>\r
11 #include <string.h>\r
12 \r
13 #include "zlib.h"\r
14 #include "ioapi.h"\r
15 \r
16 \r
17 \r
18 /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */\r
19 \r
20 #ifndef SEEK_CUR\r
21 #define SEEK_CUR    1\r
22 #endif\r
23 \r
24 #ifndef SEEK_END\r
25 #define SEEK_END    2\r
26 #endif\r
27 \r
28 #ifndef SEEK_SET\r
29 #define SEEK_SET    0\r
30 #endif\r
31 \r
32 voidpf ZCALLBACK fopen_file_func OF((\r
33    voidpf opaque,\r
34    const char* filename,\r
35    int mode));\r
36 \r
37 uLong ZCALLBACK fread_file_func OF((\r
38    voidpf opaque,\r
39    voidpf stream,\r
40    void* buf,\r
41    uLong size));\r
42 \r
43 uLong ZCALLBACK fwrite_file_func OF((\r
44    voidpf opaque,\r
45    voidpf stream,\r
46    const void* buf,\r
47    uLong size));\r
48 \r
49 long ZCALLBACK ftell_file_func OF((\r
50    voidpf opaque,\r
51    voidpf stream));\r
52 \r
53 long ZCALLBACK fseek_file_func OF((\r
54    voidpf opaque,\r
55    voidpf stream,\r
56    uLong offset,\r
57    int origin));\r
58 \r
59 int ZCALLBACK fclose_file_func OF((\r
60    voidpf opaque,\r
61    voidpf stream));\r
62 \r
63 int ZCALLBACK ferror_file_func OF((\r
64    voidpf opaque,\r
65    voidpf stream));\r
66 \r
67 \r
68 voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)\r
69    voidpf opaque;\r
70    const char* filename;\r
71    int mode;\r
72 {\r
73     FILE* file = NULL;\r
74     const char* mode_fopen = NULL;\r
75     if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)\r
76         mode_fopen = "rb";\r
77     else\r
78     if (mode & ZLIB_FILEFUNC_MODE_EXISTING)\r
79         mode_fopen = "r+b";\r
80     else\r
81     if (mode & ZLIB_FILEFUNC_MODE_CREATE)\r
82         mode_fopen = "wb";\r
83 \r
84     if ((filename!=NULL) && (mode_fopen != NULL))\r
85         file = fopen(filename, mode_fopen);\r
86     return file;\r
87 }\r
88 \r
89 \r
90 uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)\r
91    voidpf opaque;\r
92    voidpf stream;\r
93    void* buf;\r
94    uLong size;\r
95 {\r
96     uLong ret;\r
97     ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);\r
98     return ret;\r
99 }\r
100 \r
101 \r
102 uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)\r
103    voidpf opaque;\r
104    voidpf stream;\r
105    const void* buf;\r
106    uLong size;\r
107 {\r
108     uLong ret;\r
109     ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);\r
110     return ret;\r
111 }\r
112 \r
113 long ZCALLBACK ftell_file_func (opaque, stream)\r
114    voidpf opaque;\r
115    voidpf stream;\r
116 {\r
117     long ret;\r
118     ret = ftell((FILE *)stream);\r
119     return ret;\r
120 }\r
121 \r
122 long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)\r
123    voidpf opaque;\r
124    voidpf stream;\r
125    uLong offset;\r
126    int origin;\r
127 {\r
128     int fseek_origin=0;\r
129     long ret;\r
130     switch (origin)\r
131     {\r
132     case ZLIB_FILEFUNC_SEEK_CUR :\r
133         fseek_origin = SEEK_CUR;\r
134         break;\r
135     case ZLIB_FILEFUNC_SEEK_END :\r
136         fseek_origin = SEEK_END;\r
137         break;\r
138     case ZLIB_FILEFUNC_SEEK_SET :\r
139         fseek_origin = SEEK_SET;\r
140         break;\r
141     default: return -1;\r
142     }\r
143     ret = 0;\r
144     fseek((FILE *)stream, offset, fseek_origin);\r
145     return ret;\r
146 }\r
147 \r
148 int ZCALLBACK fclose_file_func (opaque, stream)\r
149    voidpf opaque;\r
150    voidpf stream;\r
151 {\r
152     int ret;\r
153     ret = fclose((FILE *)stream);\r
154     return ret;\r
155 }\r
156 \r
157 int ZCALLBACK ferror_file_func (opaque, stream)\r
158    voidpf opaque;\r
159    voidpf stream;\r
160 {\r
161     int ret;\r
162     ret = ferror((FILE *)stream);\r
163     return ret;\r
164 }\r
165 \r
166 void fill_fopen_filefunc (pzlib_filefunc_def)\r
167   zlib_filefunc_def* pzlib_filefunc_def;\r
168 {\r
169     pzlib_filefunc_def->zopen_file = fopen_file_func;\r
170     pzlib_filefunc_def->zread_file = fread_file_func;\r
171     pzlib_filefunc_def->zwrite_file = fwrite_file_func;\r
172     pzlib_filefunc_def->ztell_file = ftell_file_func;\r
173     pzlib_filefunc_def->zseek_file = fseek_file_func;\r
174     pzlib_filefunc_def->zclose_file = fclose_file_func;\r
175     pzlib_filefunc_def->zerror_file = ferror_file_func;\r
176     pzlib_filefunc_def->opaque = NULL;\r
177 }\r