| 222 | |
| 223 | |
| 224 | local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len) |
| 225 | { |
| 226 | linkedlist_datablock_internal* ldi; |
| 227 | const unsigned char* from_copy; |
| 228 | |
| 229 | if (ll == NULL) |
| 230 | return ZIP_INTERNALERROR; |
| 231 | |
| 232 | if (ll->last_block == NULL) |
| 233 | { |
| 234 | ll->first_block = ll->last_block = allocate_new_datablock(); |
| 235 | if (ll->first_block == NULL) |
| 236 | return ZIP_INTERNALERROR; |
| 237 | } |
| 238 | |
| 239 | ldi = ll->last_block; |
| 240 | from_copy = (unsigned char*)buf; |
| 241 | |
| 242 | while (len > 0) |
| 243 | { |
| 244 | uInt copy_this; |
| 245 | uInt i; |
| 246 | unsigned char* to_copy; |
| 247 | |
| 248 | if (ldi->avail_in_this_block == 0) |
| 249 | { |
| 250 | ldi->next_datablock = allocate_new_datablock(); |
| 251 | if (ldi->next_datablock == NULL) |
| 252 | return ZIP_INTERNALERROR; |
| 253 | ldi = ldi->next_datablock; |
| 254 | ll->last_block = ldi; |
| 255 | } |
| 256 | |
| 257 | if (ldi->avail_in_this_block < len) |
| 258 | copy_this = (uInt)ldi->avail_in_this_block; |
| 259 | else |
| 260 | copy_this = (uInt)len; |
| 261 | |
| 262 | to_copy = &(ldi->data[ldi->filled_in_this_block]); |
| 263 | |
| 264 | for (i = 0; i < copy_this; i++) |
| 265 | *(to_copy + i) = *(from_copy + i); |
| 266 | |
| 267 | ldi->filled_in_this_block += copy_this; |
| 268 | ldi->avail_in_this_block -= copy_this; |
| 269 | from_copy += copy_this; |
| 270 | len -= copy_this; |
| 271 | } |
| 272 | return ZIP_OK; |
| 273 | } |
| 274 | |
| 275 | |
| 276 | /****************************************************************************/ |
no test coverage detected