-- see zlib.h -- */
| 343 | |
| 344 | /* -- see zlib.h -- */ |
| 345 | int ZEXPORT gzread(gzFile file, voidp buf, unsigned len) { |
| 346 | gz_statep state; |
| 347 | |
| 348 | /* get internal structure */ |
| 349 | if (file == NULL) |
| 350 | return -1; |
| 351 | state = (gz_statep)file; |
| 352 | |
| 353 | /* check that we're reading and that there's no (serious) error */ |
| 354 | if (state->mode != GZ_READ || |
| 355 | (state->err != Z_OK && state->err != Z_BUF_ERROR)) |
| 356 | return -1; |
| 357 | |
| 358 | /* since an int is returned, make sure len fits in one, otherwise return |
| 359 | with an error (this avoids a flaw in the interface) */ |
| 360 | if ((int)len < 0) { |
| 361 | gz_error(state, Z_STREAM_ERROR, "request does not fit in an int"); |
| 362 | return -1; |
| 363 | } |
| 364 | |
| 365 | /* read len or fewer bytes to buf */ |
| 366 | len = (unsigned)gz_read(state, buf, len); |
| 367 | |
| 368 | /* check for an error */ |
| 369 | if (len == 0 && state->err != Z_OK && state->err != Z_BUF_ERROR) |
| 370 | return -1; |
| 371 | |
| 372 | /* return the number of bytes read (this is assured to fit in an int) */ |
| 373 | return (int)len; |
| 374 | } |
| 375 | |
| 376 | /* -- see zlib.h -- */ |
| 377 | z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, gzFile file) { |