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