| 272 | ****************************************************************************/ |
| 273 | |
| 274 | char *sim_deviceimage(void) |
| 275 | { |
| 276 | char *pbuffer; |
| 277 | int bufsize = 1024 * 1024; |
| 278 | int offset = 0; |
| 279 | z_stream strm; |
| 280 | int ret; |
| 281 | |
| 282 | /* Initialize inflate state */ |
| 283 | |
| 284 | strm.zalloc = Z_NULL; |
| 285 | strm.zfree = Z_NULL; |
| 286 | strm.opaque = Z_NULL; |
| 287 | strm.avail_in = 0; |
| 288 | strm.next_in = Z_NULL; |
| 289 | ret = inflateInit(&strm); |
| 290 | if (ret != Z_OK) |
| 291 | { |
| 292 | serr("ERROR: inflateInit FAILED: ret=%d msg=\"%s\"\n", |
| 293 | ret, strm.msg ? strm.msg : "No message"); |
| 294 | return NULL; |
| 295 | } |
| 296 | |
| 297 | /* Allocate a buffer to hold the decompressed buffer. We may have to |
| 298 | * reallocate this a few times to get the size right. |
| 299 | */ |
| 300 | |
| 301 | pbuffer = kmm_malloc(bufsize); |
| 302 | |
| 303 | /* Set up the input buffer */ |
| 304 | |
| 305 | strm.avail_in = sizeof(g_vfatdata); |
| 306 | strm.next_in = (Bytef *)g_vfatdata; |
| 307 | |
| 308 | /* Run inflate() on input until output buffer not full */ |
| 309 | |
| 310 | do |
| 311 | { |
| 312 | /* Set up to catch the next output chunk in the output buffer */ |
| 313 | |
| 314 | strm.avail_out = bufsize - offset; |
| 315 | strm.next_out = (Bytef *)&pbuffer[offset]; |
| 316 | |
| 317 | /* inflate */ |
| 318 | |
| 319 | ret = inflate(&strm, Z_NO_FLUSH); |
| 320 | |
| 321 | /* Handle inflate() error return values */ |
| 322 | |
| 323 | switch (ret) |
| 324 | { |
| 325 | case Z_NEED_DICT: |
| 326 | case Z_DATA_ERROR: |
| 327 | case Z_MEM_ERROR: |
| 328 | case Z_STREAM_ERROR: |
| 329 | serr("ERROR: inflate FAILED: ret=%d msg=\"%s\"\n", |
| 330 | ret, strm.msg ? strm.msg : "No message"); |
| 331 | inflateEnd(&strm); |
no test coverage detected