| 1 | /* mz_strm_split.c -- Stream for split files |
| 2 | part of the minizip-ng project |
| 3 | |
| 4 | Copyright (C) Nathan Moinvaziri |
| 5 | https://github.com/zlib-ng/minizip-ng |
| 6 | |
| 7 | This program is distributed under the terms of the same license as zlib. |
| 8 | See the accompanying LICENSE file for the full text of the license. |
| 9 | */ |
| 10 | |
| 11 | #include "mz.h"cxx . . $ `<file>/mz.h`/ |
| 12 | #include "mz_os.h"cxx . . $ `<file>/mz_os.h`/ |
| 13 | #include "mz_strm.h"cxx . . $ `<file>/mz_strm.h`/ |
| 14 | #include "mz_strm_split.h"cxx . . $ `<file>/mz_strm_split.h`/ |
| 15 | |
| 16 | #include <stdio.h> /* snprintf */ |
| 17 | #include <string.h> |
| 18 | |
| 19 | #if defined(_MSC_VER) && (_MSC_VER < 1900) |
| 20 | # define snprintf _snprintf |
| 21 | #endif |
| 22 | |
| 23 | /***************************************************************************/ |
| 24 | |
| 25 | #define MZ_ZIP_MAGIC_DISKHEADERcxx . . $ `mz_strm_split.c:25:9`! (0x08074b50) |
| 26 | |
| 27 | /***************************************************************************/ |
| 28 | |
| 29 | static mz_stream_vtblcxx . . $ mz_stream_vtbl# mz_stream_split_vtblcxx . . $ mz_stream_split_vtbl. = { |
| 30 | mz_stream_split_opencxx . . $ mz_stream_split_open(7083a8984c0735e8)., mz_stream_split_is_opencxx . . $ mz_stream_split_is_open(dedf1e9b1c614a07)., mz_stream_split_readcxx . . $ mz_stream_split_read(8bc41909eac9e5d8)., mz_stream_split_writecxx . . $ mz_stream_split_write(91e54fd90adbb21)., |
| 31 | mz_stream_split_tellcxx . . $ mz_stream_split_tell(72c1818a5177f981)., mz_stream_split_seekcxx . . $ mz_stream_split_seek(8bc0ff128761c75d)., mz_stream_split_closecxx . . $ mz_stream_split_close(dedf1e9b1c614a07)., mz_stream_split_errorcxx . . $ mz_stream_split_error(dedf1e9b1c614a07)., |
| 32 | mz_stream_split_createcxx . . $ mz_stream_split_create(50c7df7de5344ebb)., mz_stream_split_deletecxx . . $ mz_stream_split_delete(539e082cf00e1f43)., mz_stream_split_get_prop_int64cxx . . $ mz_stream_split_get_prop_int64(280df70541557ec8)., mz_stream_split_set_prop_int64cxx . . $ mz_stream_split_set_prop_int64(5f4b2ff0df22ef2b).}; |
| 33 | |
| 34 | /***************************************************************************/ |
| 35 | |
| 36 | typedef struct mz_stream_split_scxx . . $ mz_stream_split_s# { |
| 37 | mz_streamcxx . . $ mz_stream# streamcxx . . $ mz_stream_split_s#stream.; |
| 38 | int64_tcxx . . $ int64_t# disk_sizecxx . . $ mz_stream_split_s#disk_size.; |
| 39 | int64_tcxx . . $ int64_t# total_incxx . . $ mz_stream_split_s#total_in.; |
| 40 | int64_tcxx . . $ int64_t# total_in_diskcxx . . $ mz_stream_split_s#total_in_disk.; |
| 41 | int64_tcxx . . $ int64_t# total_outcxx . . $ mz_stream_split_s#total_out.; |
| 42 | int64_tcxx . . $ int64_t# total_out_diskcxx . . $ mz_stream_split_s#total_out_disk.; |
| 43 | int32_tcxx . . $ int32_t# is_opencxx . . $ mz_stream_split_s#is_open.; |
| 44 | int32_tcxx . . $ int32_t# modecxx . . $ mz_stream_split_s#mode.; |
| 45 | char *path_cdcxx . . $ mz_stream_split_s#path_cd.; |
| 46 | char *path_diskcxx . . $ mz_stream_split_s#path_disk.; |
| 47 | uint32_tcxx . . $ uint32_t# path_disk_sizecxx . . $ mz_stream_split_s#path_disk_size.; |
| 48 | int32_tcxx . . $ int32_t# number_diskcxx . . $ mz_stream_split_s#number_disk.; |
| 49 | int64_tcxx . . $ int64_t# current_disk_sizecxx . . $ mz_stream_split_s#current_disk_size.; |
| 50 | int32_tcxx . . $ int32_t# current_diskcxx . . $ mz_stream_split_s#current_disk.; |
| 51 | int32_tcxx . . $ int32_t# reached_endcxx . . $ mz_stream_split_s#reached_end.; |
| 52 | } mz_stream_splitcxx . . $ mz_stream_split#; |
| 53 | |
| 54 | /***************************************************************************/ |
| 55 | |
| 56 | #if 0 |
| 57 | # define mz_stream_split_print printf |
| 58 | #else |
| 59 | # define mz_stream_split_printcxx . . $ `mz_strm_split.c:59:11`!(fmt, ...) |
| 60 | #endif |
| 61 | |
| 62 | /***************************************************************************/ |
| 63 | |
| 64 | static int32_tcxx . . $ int32_t# mz_stream_split_open_diskcxx . . $ mz_stream_split_open_disk(7fb3b8e28157cebd).(void *stream, int32_tcxx . . $ int32_t# number_disk) { |
| 65 | mz_stream_splitcxx . . $ mz_stream_split# *split = (mz_stream_splitcxx . . $ mz_stream_split# *)stream; |
| 66 | uint32_tcxx . . $ uint32_t# magic = 0; |
| 67 | int64_tcxx . . $ int64_t# position = 0; |
| 68 | int32_tcxx . . $ int32_t# i = 0; |
| 69 | int32_tcxx . . $ int32_t# err = MZ_OKcxx . . $ `mz.h:21:9`!; |
| 70 | int16_tcxx . . $ int16_t# disk_part = 0; |
| 71 | |
| 72 | /* Check if we are reading or writing a disk part or the cd disk */ |
| 73 | if (number_disk >= 0) { |
| 74 | if ((split->modecxx . . $ mz_stream_split_s#mode. & MZ_OPEN_MODE_WRITEcxx . . $ `mz.h:51:9`!) == 0) |
| 75 | disk_part = MZ_OPEN_MODE_READcxx . . $ `mz.h:50:9`!; |
| 76 | else if (split->disk_sizecxx . . $ mz_stream_split_s#disk_size. > 0) |
| 77 | disk_part = MZ_OPEN_MODE_WRITEcxx . . $ `mz.h:51:9`!; |
| 78 | } |
| 79 | |
| 80 | /* Construct disk path */ |
| 81 | if (disk_part > 0) { |
| 82 | for (i = (int32_tcxx . . $ int32_t#)strlencxx . . $ strlen(751346f8406fd082).(split->path_diskcxx . . $ mz_stream_split_s#path_disk.) - 1; i >= 0; i -= 1) { |
| 83 | if (split->path_diskcxx . . $ mz_stream_split_s#path_disk.[i] != '.') |
| 84 | continue; |
| 85 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(&split->path_diskcxx . . $ mz_stream_split_s#path_disk.[i], split->path_disk_sizecxx . . $ mz_stream_split_s#path_disk_size. - (uint32_tcxx . . $ uint32_t#)i, ".z%02" PRId32cxx . . $ `<external>/15933738808807975373/inttypes.h:56:10`!, number_disk + 1); |
| 86 | break; |
| 87 | } |
| 88 | } else { |
| 89 | strncpycxx . . $ strncpy(255158a415b673b0).(split->path_diskcxx . . $ mz_stream_split_s#path_disk., split->path_cdcxx . . $ mz_stream_split_s#path_cd., split->path_disk_sizecxx . . $ mz_stream_split_s#path_disk_size. - 1); |
| 90 | split->path_diskcxx . . $ mz_stream_split_s#path_disk.[split->path_disk_sizecxx . . $ mz_stream_split_s#path_disk_size. - 1] = 0; |
| 91 | } |
| 92 | |
| 93 | mz_stream_split_printcxx . . $ `mz_strm_split.c:59:11`!("Split - Goto disk - %s (disk %" PRId32 ")\n", split->path_disk, number_disk); |
| 94 | |
| 95 | /* If disk part doesn't exist during reading then return MZ_EXIST_ERROR */ |
| 96 | if (disk_part == MZ_OPEN_MODE_READcxx . . $ `mz.h:50:9`!) { |
| 97 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(split->path_diskcxx . . $ mz_stream_split_s#path_disk., split->path_cdcxx . . $ mz_stream_split_s#path_cd.) == 0) { |
| 98 | err = MZ_EXIST_ERRORcxx . . $ `mz.h:36:9`!; |
| 99 | } else { |
| 100 | err = mz_os_file_existscxx . . $ mz_os_file_exists(5c4306d8553b3696).(split->path_diskcxx . . $ mz_stream_split_s#path_disk.); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | if (err == MZ_OKcxx . . $ `mz.h:21:9`!) |
| 105 | err = mz_stream_opencxx . . $ mz_stream_open(7083a8984c0735e8).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base., split->path_diskcxx . . $ mz_stream_split_s#path_disk., split->modecxx . . $ mz_stream_split_s#mode.); |
| 106 | |
| 107 | if (err == MZ_OKcxx . . $ `mz.h:21:9`!) { |
| 108 | split->total_in_diskcxx . . $ mz_stream_split_s#total_in_disk. = 0; |
| 109 | split->total_out_diskcxx . . $ mz_stream_split_s#total_out_disk. = 0; |
| 110 | split->current_diskcxx . . $ mz_stream_split_s#current_disk. = number_disk; |
| 111 | |
| 112 | if (split->modecxx . . $ mz_stream_split_s#mode. & MZ_OPEN_MODE_WRITEcxx . . $ `mz.h:51:9`!) { |
| 113 | if ((split->current_diskcxx . . $ mz_stream_split_s#current_disk. == 0) && (split->disk_sizecxx . . $ mz_stream_split_s#disk_size. > 0)) { |
| 114 | err = mz_stream_write_uint32cxx . . $ mz_stream_write_uint32(6fe7d876f9648735).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base., MZ_ZIP_MAGIC_DISKHEADERcxx . . $ `mz_strm_split.c:25:9`!); |
| 115 | |
| 116 | split->total_out_diskcxx . . $ mz_stream_split_s#total_out_disk. += 4; |
| 117 | split->total_outcxx . . $ mz_stream_split_s#total_out. += split->total_out_diskcxx . . $ mz_stream_split_s#total_out_disk.; |
| 118 | } |
| 119 | } else if (split->modecxx . . $ mz_stream_split_s#mode. & MZ_OPEN_MODE_READcxx . . $ `mz.h:50:9`!) { |
| 120 | if (split->current_diskcxx . . $ mz_stream_split_s#current_disk. == 0) { |
| 121 | err = mz_stream_read_uint32cxx . . $ mz_stream_read_uint32(3569d74970a1d1f9).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base., &magic); |
| 122 | if (magic != MZ_ZIP_MAGIC_DISKHEADERcxx . . $ `mz_strm_split.c:25:9`!) |
| 123 | err = MZ_FORMAT_ERRORcxx . . $ `mz.h:32:9`!; |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | if (err == MZ_OKcxx . . $ `mz.h:21:9`!) { |
| 129 | /* Get the size of the current disk we are on */ |
| 130 | position = mz_stream_tellcxx . . $ mz_stream_tell(72c1818a5177f981).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base.); |
| 131 | mz_stream_seekcxx . . $ mz_stream_seek(8bc0ff128761c75d).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base., 0, MZ_SEEK_ENDcxx . . $ `mz.h:60:9`!); |
| 132 | split->current_disk_sizecxx . . $ mz_stream_split_s#current_disk_size. = mz_stream_tellcxx . . $ mz_stream_tell(72c1818a5177f981).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base.); |
| 133 | mz_stream_seekcxx . . $ mz_stream_seek(8bc0ff128761c75d).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base., position, MZ_SEEK_SETcxx . . $ `mz.h:58:9`!); |
| 134 | |
| 135 | split->is_opencxx . . $ mz_stream_split_s#is_open. = 1; |
| 136 | } |
| 137 | |
| 138 | return err; |
| 139 | } |
| 140 | |
| 141 | static int32_tcxx . . $ int32_t# mz_stream_split_close_diskcxx . . $ mz_stream_split_close_disk(dedf1e9b1c614a07).(void *stream) { |
| 142 | mz_stream_splitcxx . . $ mz_stream_split# *split = (mz_stream_splitcxx . . $ mz_stream_split# *)stream; |
| 143 | |
| 144 | if (mz_stream_is_opencxx . . $ mz_stream_is_open(dedf1e9b1c614a07).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base.) != MZ_OKcxx . . $ `mz.h:21:9`!) |
| 145 | return MZ_OKcxx . . $ `mz.h:21:9`!; |
| 146 | |
| 147 | mz_stream_split_printcxx . . $ `mz_strm_split.c:59:11`!("Split - Close disk\n"); |
| 148 | return mz_stream_closecxx . . $ mz_stream_close(dedf1e9b1c614a07).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base.); |
| 149 | } |
| 150 | |
| 151 | static int32_tcxx . . $ int32_t# mz_stream_split_goto_diskcxx . . $ mz_stream_split_goto_disk(7fb3b8e28157cebd).(void *stream, int32_tcxx . . $ int32_t# number_disk) { |
| 152 | mz_stream_splitcxx . . $ mz_stream_split# *split = (mz_stream_splitcxx . . $ mz_stream_split# *)stream; |
| 153 | int32_tcxx . . $ int32_t# err = MZ_OKcxx . . $ `mz.h:21:9`!; |
| 154 | int32_tcxx . . $ int32_t# err_is_open = MZ_OKcxx . . $ `mz.h:21:9`!; |
| 155 | |
| 156 | err_is_open = mz_stream_is_opencxx . . $ mz_stream_is_open(dedf1e9b1c614a07).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base.); |
| 157 | |
| 158 | if ((split->disk_sizecxx . . $ mz_stream_split_s#disk_size. == 0) && (split->modecxx . . $ mz_stream_split_s#mode. & MZ_OPEN_MODE_WRITEcxx . . $ `mz.h:51:9`!)) { |
| 159 | if (err_is_open != MZ_OKcxx . . $ `mz.h:21:9`!) |
| 160 | err = mz_stream_split_open_diskcxx . . $ mz_stream_split_open_disk(7fb3b8e28157cebd).(stream, number_disk); |
| 161 | } else if ((number_disk != split->current_diskcxx . . $ mz_stream_split_s#current_disk.) || (err_is_open != MZ_OKcxx . . $ `mz.h:21:9`!)) { |
| 162 | err = mz_stream_split_close_diskcxx . . $ mz_stream_split_close_disk(dedf1e9b1c614a07).(stream); |
| 163 | if (err == MZ_OKcxx . . $ `mz.h:21:9`!) { |
| 164 | err = mz_stream_split_open_diskcxx . . $ mz_stream_split_open_disk(7fb3b8e28157cebd).(stream, number_disk); |
| 165 | if (err == MZ_OKcxx . . $ `mz.h:21:9`!) |
| 166 | split->number_diskcxx . . $ mz_stream_split_s#number_disk. = number_disk; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | return err; |
| 171 | } |
| 172 | |
| 173 | int32_tcxx . . $ int32_t# mz_stream_split_opencxx . . $ mz_stream_split_open(7083a8984c0735e8).(void *stream, const char *path, int32_tcxx . . $ int32_t# mode) { |
| 174 | mz_stream_splitcxx . . $ mz_stream_split# *split = (mz_stream_splitcxx . . $ mz_stream_split# *)stream; |
| 175 | int32_tcxx . . $ int32_t# number_disk = 0; |
| 176 | |
| 177 | split->modecxx . . $ mz_stream_split_s#mode. = mode; |
| 178 | split->path_cdcxx . . $ mz_stream_split_s#path_cd. = strdupcxx . . $ strdup(a8b8e32347182212).(path); |
| 179 | |
| 180 | if (!split->path_cdcxx . . $ mz_stream_split_s#path_cd.) |
| 181 | return MZ_MEM_ERRORcxx . . $ `mz.h:24:9`!; |
| 182 | |
| 183 | mz_stream_split_printcxx . . $ `mz_strm_split.c:59:11`!("Split - Open - %s (disk %" PRId32 ")\n", split->path_cd, number_disk); |
| 184 | |
| 185 | split->path_disk_sizecxx . . $ mz_stream_split_s#path_disk_size. = (uint32_tcxx . . $ uint32_t#)strlencxx . . $ strlen(751346f8406fd082).(path) + 10; |
| 186 | split->path_diskcxx . . $ mz_stream_split_s#path_disk. = (char *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(split->path_disk_sizecxx . . $ mz_stream_split_s#path_disk_size.); |
| 187 | |
| 188 | if (!split->path_diskcxx . . $ mz_stream_split_s#path_disk.) { |
| 189 | freecxx . . $ free(5d22bdacc48458e8).(split->path_cdcxx . . $ mz_stream_split_s#path_cd.); |
| 190 | return MZ_MEM_ERRORcxx . . $ `mz.h:24:9`!; |
| 191 | } |
| 192 | |
| 193 | strncpycxx . . $ strncpy(255158a415b673b0).(split->path_diskcxx . . $ mz_stream_split_s#path_disk., path, split->path_disk_sizecxx . . $ mz_stream_split_s#path_disk_size. - 1); |
| 194 | split->path_diskcxx . . $ mz_stream_split_s#path_disk.[split->path_disk_sizecxx . . $ mz_stream_split_s#path_disk_size. - 1] = 0; |
| 195 | |
| 196 | if ((mode & MZ_OPEN_MODE_WRITEcxx . . $ `mz.h:51:9`!) && ((mode & MZ_OPEN_MODE_APPENDcxx . . $ `mz.h:53:9`!) == 0)) { |
| 197 | number_disk = 0; |
| 198 | split->current_diskcxx . . $ mz_stream_split_s#current_disk. = -1; |
| 199 | } else { |
| 200 | number_disk = -1; |
| 201 | split->current_diskcxx . . $ mz_stream_split_s#current_disk. = 0; |
| 202 | } |
| 203 | |
| 204 | return mz_stream_split_goto_diskcxx . . $ mz_stream_split_goto_disk(7fb3b8e28157cebd).(stream, number_disk); |
| 205 | } |
| 206 | |
| 207 | int32_tcxx . . $ int32_t# mz_stream_split_is_opencxx . . $ mz_stream_split_is_open(dedf1e9b1c614a07).(void *stream) { |
| 208 | mz_stream_splitcxx . . $ mz_stream_split# *split = (mz_stream_splitcxx . . $ mz_stream_split# *)stream; |
| 209 | if (split->is_opencxx . . $ mz_stream_split_s#is_open. != 1) |
| 210 | return MZ_OPEN_ERRORcxx . . $ `mz.h:40:9`!; |
| 211 | return MZ_OKcxx . . $ `mz.h:21:9`!; |
| 212 | } |
| 213 | |
| 214 | int32_tcxx . . $ int32_t# mz_stream_split_readcxx . . $ mz_stream_split_read(8bc41909eac9e5d8).(void *stream, void *buf, int32_tcxx . . $ int32_t# size) { |
| 215 | mz_stream_splitcxx . . $ mz_stream_split# *split = (mz_stream_splitcxx . . $ mz_stream_split# *)stream; |
| 216 | int32_tcxx . . $ int32_t# bytes_left = size; |
| 217 | int32_tcxx . . $ int32_t# read = 0; |
| 218 | int32_tcxx . . $ int32_t# err = MZ_OKcxx . . $ `mz.h:21:9`!; |
| 219 | uint8_tcxx . . $ uint8_t# *buf_ptr = (uint8_tcxx . . $ uint8_t# *)buf; |
| 220 | |
| 221 | err = mz_stream_split_goto_diskcxx . . $ mz_stream_split_goto_disk(7fb3b8e28157cebd).(stream, split->number_diskcxx . . $ mz_stream_split_s#number_disk.); |
| 222 | if (err != MZ_OKcxx . . $ `mz.h:21:9`!) |
| 223 | return err; |
| 224 | |
| 225 | while (bytes_left > 0) { |
| 226 | read = mz_stream_readcxx . . $ mz_stream_read(8bc41909eac9e5d8).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base., buf_ptr, bytes_left); |
| 227 | |
| 228 | mz_stream_split_printcxx . . $ `mz_strm_split.c:59:11`!("Split - Read disk - %" PRId32 "\n", read); |
| 229 | |
| 230 | if (read < 0) |
| 231 | return read; |
| 232 | if (read == 0) { |
| 233 | if (split->current_diskcxx . . $ mz_stream_split_s#current_disk. < 0) /* No more disks to goto */ |
| 234 | break; |
| 235 | if (size != bytes_left) /* Report read from previous disk before switching */ |
| 236 | break; |
| 237 | err = mz_stream_split_goto_diskcxx . . $ mz_stream_split_goto_disk(7fb3b8e28157cebd).(stream, split->current_diskcxx . . $ mz_stream_split_s#current_disk. + 1); |
| 238 | if (err == MZ_EXIST_ERRORcxx . . $ `mz.h:36:9`!) |
| 239 | split->current_diskcxx . . $ mz_stream_split_s#current_disk. = -1; |
| 240 | if (err != MZ_OKcxx . . $ `mz.h:21:9`!) |
| 241 | return err; |
| 242 | } |
| 243 | |
| 244 | bytes_left -= read; |
| 245 | buf_ptr += read; |
| 246 | split->total_incxx . . $ mz_stream_split_s#total_in. += read; |
| 247 | split->total_in_diskcxx . . $ mz_stream_split_s#total_in_disk. += read; |
| 248 | } |
| 249 | return size - bytes_left; |
| 250 | } |
| 251 | |
| 252 | int32_tcxx . . $ int32_t# mz_stream_split_writecxx . . $ mz_stream_split_write(91e54fd90adbb21).(void *stream, const void *buf, int32_tcxx . . $ int32_t# size) { |
| 253 | mz_stream_splitcxx . . $ mz_stream_split# *split = (mz_stream_splitcxx . . $ mz_stream_split# *)stream; |
| 254 | int64_tcxx . . $ int64_t# position = 0; |
| 255 | int32_tcxx . . $ int32_t# written = 0; |
| 256 | int32_tcxx . . $ int32_t# bytes_left = size; |
| 257 | int32_tcxx . . $ int32_t# bytes_to_write = 0; |
| 258 | int32_tcxx . . $ int32_t# bytes_avail = 0; |
| 259 | int32_tcxx . . $ int32_t# number_disk = -1; |
| 260 | int32_tcxx . . $ int32_t# err = MZ_OKcxx . . $ `mz.h:21:9`!; |
| 261 | const uint8_tcxx . . $ uint8_t# *buf_ptr = (const uint8_tcxx . . $ uint8_t# *)buf; |
| 262 | |
| 263 | position = mz_stream_tellcxx . . $ mz_stream_tell(72c1818a5177f981).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base.); |
| 264 | |
| 265 | while (bytes_left > 0) { |
| 266 | bytes_to_write = bytes_left; |
| 267 | |
| 268 | if (split->disk_sizecxx . . $ mz_stream_split_s#disk_size. > 0) { |
| 269 | if ((split->total_out_diskcxx . . $ mz_stream_split_s#total_out_disk. == split->disk_sizecxx . . $ mz_stream_split_s#disk_size. && split->total_outcxx . . $ mz_stream_split_s#total_out. > 0) || |
| 270 | (split->number_diskcxx . . $ mz_stream_split_s#number_disk. == -1 && split->number_diskcxx . . $ mz_stream_split_s#number_disk. != split->current_diskcxx . . $ mz_stream_split_s#current_disk.)) { |
| 271 | if (split->number_diskcxx . . $ mz_stream_split_s#number_disk. != -1) |
| 272 | number_disk = split->current_diskcxx . . $ mz_stream_split_s#current_disk. + 1; |
| 273 | |
| 274 | err = mz_stream_split_goto_diskcxx . . $ mz_stream_split_goto_disk(7fb3b8e28157cebd).(stream, number_disk); |
| 275 | if (err != MZ_OKcxx . . $ `mz.h:21:9`!) |
| 276 | return err; |
| 277 | |
| 278 | position = 0; |
| 279 | } |
| 280 | |
| 281 | if (split->number_diskcxx . . $ mz_stream_split_s#number_disk. != -1) { |
| 282 | bytes_avail = (int32_tcxx . . $ int32_t#)(split->disk_sizecxx . . $ mz_stream_split_s#disk_size. - split->total_out_diskcxx . . $ mz_stream_split_s#total_out_disk.); |
| 283 | if (bytes_to_write > bytes_avail) |
| 284 | bytes_to_write = bytes_avail; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | written = mz_stream_writecxx . . $ mz_stream_write(91e54fd90adbb21).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base., buf_ptr, bytes_to_write); |
| 289 | if (written != bytes_to_write) |
| 290 | return MZ_WRITE_ERRORcxx . . $ `mz.h:45:9`!; |
| 291 | |
| 292 | mz_stream_split_printcxx . . $ `mz_strm_split.c:59:11`!("Split - Write disk - %" PRId32 "\n", written); |
| 293 | |
| 294 | bytes_left -= written; |
| 295 | buf_ptr += written; |
| 296 | |
| 297 | split->total_outcxx . . $ mz_stream_split_s#total_out. += written; |
| 298 | split->total_out_diskcxx . . $ mz_stream_split_s#total_out_disk. += written; |
| 299 | |
| 300 | position += written; |
| 301 | if (position > split->current_disk_sizecxx . . $ mz_stream_split_s#current_disk_size.) |
| 302 | split->current_disk_sizecxx . . $ mz_stream_split_s#current_disk_size. = position; |
| 303 | } |
| 304 | |
| 305 | return size - bytes_left; |
| 306 | } |
| 307 | |
| 308 | int64_tcxx . . $ int64_t# mz_stream_split_tellcxx . . $ mz_stream_split_tell(72c1818a5177f981).(void *stream) { |
| 309 | mz_stream_splitcxx . . $ mz_stream_split# *split = (mz_stream_splitcxx . . $ mz_stream_split# *)stream; |
| 310 | int32_tcxx . . $ int32_t# err = MZ_OKcxx . . $ `mz.h:21:9`!; |
| 311 | err = mz_stream_split_goto_diskcxx . . $ mz_stream_split_goto_disk(7fb3b8e28157cebd).(stream, split->number_diskcxx . . $ mz_stream_split_s#number_disk.); |
| 312 | if (err != MZ_OKcxx . . $ `mz.h:21:9`!) |
| 313 | return err; |
| 314 | return mz_stream_tellcxx . . $ mz_stream_tell(72c1818a5177f981).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base.); |
| 315 | } |
| 316 | |
| 317 | int32_tcxx . . $ int32_t# mz_stream_split_seekcxx . . $ mz_stream_split_seek(8bc0ff128761c75d).(void *stream, int64_tcxx . . $ int64_t# offset, int32_tcxx . . $ int32_t# origin) { |
| 318 | mz_stream_splitcxx . . $ mz_stream_split# *split = (mz_stream_splitcxx . . $ mz_stream_split# *)stream; |
| 319 | int64_tcxx . . $ int64_t# disk_left = 0; |
| 320 | int64_tcxx . . $ int64_t# position = 0; |
| 321 | int32_tcxx . . $ int32_t# err = MZ_OKcxx . . $ `mz.h:21:9`!; |
| 322 | |
| 323 | err = mz_stream_split_goto_diskcxx . . $ mz_stream_split_goto_disk(7fb3b8e28157cebd).(stream, split->number_diskcxx . . $ mz_stream_split_s#number_disk.); |
| 324 | |
| 325 | if (err != MZ_OKcxx . . $ `mz.h:21:9`!) |
| 326 | return err; |
| 327 | |
| 328 | mz_stream_split_printcxx . . $ `mz_strm_split.c:59:11`!("Split - Seek disk - %" PRId64 " (origin %" PRId32 ")\n", offset, origin); |
| 329 | |
| 330 | if ((origin == MZ_SEEK_CURcxx . . $ `mz.h:59:9`!) && (split->number_diskcxx . . $ mz_stream_split_s#number_disk. != -1)) { |
| 331 | position = mz_stream_tellcxx . . $ mz_stream_tell(72c1818a5177f981).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base.); |
| 332 | disk_left = split->current_disk_sizecxx . . $ mz_stream_split_s#current_disk_size. - position; |
| 333 | |
| 334 | while (offset > disk_left) { |
| 335 | err = mz_stream_split_goto_diskcxx . . $ mz_stream_split_goto_disk(7fb3b8e28157cebd).(stream, split->current_diskcxx . . $ mz_stream_split_s#current_disk. + 1); |
| 336 | if (err != MZ_OKcxx . . $ `mz.h:21:9`!) |
| 337 | return err; |
| 338 | |
| 339 | offset -= disk_left; |
| 340 | disk_left = split->current_disk_sizecxx . . $ mz_stream_split_s#current_disk_size.; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | return mz_stream_seekcxx . . $ mz_stream_seek(8bc0ff128761c75d).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base., offset, origin); |
| 345 | } |
| 346 | |
| 347 | int32_tcxx . . $ int32_t# mz_stream_split_closecxx . . $ mz_stream_split_close(dedf1e9b1c614a07).(void *stream) { |
| 348 | mz_stream_splitcxx . . $ mz_stream_split# *split = (mz_stream_splitcxx . . $ mz_stream_split# *)stream; |
| 349 | int32_tcxx . . $ int32_t# err = MZ_OKcxx . . $ `mz.h:21:9`!; |
| 350 | |
| 351 | err = mz_stream_split_close_diskcxx . . $ mz_stream_split_close_disk(dedf1e9b1c614a07).(stream); |
| 352 | split->is_opencxx . . $ mz_stream_split_s#is_open. = 0; |
| 353 | return err; |
| 354 | } |
| 355 | |
| 356 | int32_tcxx . . $ int32_t# mz_stream_split_errorcxx . . $ mz_stream_split_error(dedf1e9b1c614a07).(void *stream) { |
| 357 | mz_stream_splitcxx . . $ mz_stream_split# *split = (mz_stream_splitcxx . . $ mz_stream_split# *)stream; |
| 358 | return mz_stream_errorcxx . . $ mz_stream_error(dedf1e9b1c614a07).(split->streamcxx . . $ mz_stream_split_s#stream..basecxx . . $ mz_stream_s#base.); |
| 359 | } |
| 360 | |
| 361 | int32_tcxx . . $ int32_t# mz_stream_split_get_prop_int64cxx . . $ mz_stream_split_get_prop_int64(280df70541557ec8).(void *stream, int32_tcxx . . $ int32_t# prop, int64_tcxx . . $ int64_t# *value) { |
| 362 | mz_stream_splitcxx . . $ mz_stream_split# *split = (mz_stream_splitcxx . . $ mz_stream_split# *)stream; |
| 363 | switch (prop) { |
| 364 | case MZ_STREAM_PROP_TOTAL_OUTcxx . . $ `mz_strm.h:22:9`!: |
| 365 | *value = split->total_outcxx . . $ mz_stream_split_s#total_out.; |
| 366 | break; |
| 367 | case MZ_STREAM_PROP_DISK_NUMBERcxx . . $ `mz_strm.h:27:9`!: |
| 368 | *value = split->number_diskcxx . . $ mz_stream_split_s#number_disk.; |
| 369 | break; |
| 370 | case MZ_STREAM_PROP_DISK_SIZEcxx . . $ `mz_strm.h:26:9`!: |
| 371 | *value = split->disk_sizecxx . . $ mz_stream_split_s#disk_size.; |
| 372 | break; |
| 373 | default: |
| 374 | return MZ_EXIST_ERRORcxx . . $ `mz.h:36:9`!; |
| 375 | } |
| 376 | return MZ_OKcxx . . $ `mz.h:21:9`!; |
| 377 | } |
| 378 | |
| 379 | int32_tcxx . . $ int32_t# mz_stream_split_set_prop_int64cxx . . $ mz_stream_split_set_prop_int64(5f4b2ff0df22ef2b).(void *stream, int32_tcxx . . $ int32_t# prop, int64_tcxx . . $ int64_t# value) { |
| 380 | mz_stream_splitcxx . . $ mz_stream_split# *split = (mz_stream_splitcxx . . $ mz_stream_split# *)stream; |
| 381 | switch (prop) { |
| 382 | case MZ_STREAM_PROP_DISK_NUMBERcxx . . $ `mz_strm.h:27:9`!: |
| 383 | split->number_diskcxx . . $ mz_stream_split_s#number_disk. = (int32_tcxx . . $ int32_t#)value; |
| 384 | break; |
| 385 | case MZ_STREAM_PROP_DISK_SIZEcxx . . $ `mz_strm.h:26:9`!: |
| 386 | split->disk_sizecxx . . $ mz_stream_split_s#disk_size. = value; |
| 387 | break; |
| 388 | default: |
| 389 | return MZ_EXIST_ERRORcxx . . $ `mz.h:36:9`!; |
| 390 | } |
| 391 | return MZ_OKcxx . . $ `mz.h:21:9`!; |
| 392 | } |
| 393 | |
| 394 | void *mz_stream_split_createcxx . . $ mz_stream_split_create(50c7df7de5344ebb).(void) { |
| 395 | mz_stream_splitcxx . . $ mz_stream_split# *split = (mz_stream_splitcxx . . $ mz_stream_split# *)calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(mz_stream_splitcxx . . $ mz_stream_split#)); |
| 396 | if (split) |
| 397 | split->streamcxx . . $ mz_stream_split_s#stream..vtblcxx . . $ mz_stream_s#vtbl. = &mz_stream_split_vtblcxx . . $ mz_stream_split_vtbl.; |
| 398 | return split; |
| 399 | } |
| 400 | |
| 401 | void mz_stream_split_deletecxx . . $ mz_stream_split_delete(539e082cf00e1f43).(void **stream) { |
| 402 | mz_stream_splitcxx . . $ mz_stream_split# *split = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 403 | if (!stream) |
| 404 | return; |
| 405 | split = (mz_stream_splitcxx . . $ mz_stream_split# *)*stream; |
| 406 | if (split) { |
| 407 | freecxx . . $ free(5d22bdacc48458e8).(split->path_cdcxx . . $ mz_stream_split_s#path_cd.); |
| 408 | freecxx . . $ free(5d22bdacc48458e8).(split->path_diskcxx . . $ mz_stream_split_s#path_disk.); |
| 409 | freecxx . . $ free(5d22bdacc48458e8).(split); |
| 410 | } |
| 411 | *stream = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 412 | } |
| 413 | |
| 414 | void *mz_stream_split_get_interfacecxx . . $ mz_stream_split_get_interface(50c7df7de5344ebb).(void) { |
| 415 | return (void *)&mz_stream_split_vtblcxx . . $ mz_stream_split_vtbl.; |
| 416 | } |