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