-- see zlib.h -- */
(file, buf, len)
| 412 | |
| 413 | /* -- see zlib.h -- */ |
| 414 | int ZEXPORT gzread(file, buf, len) |
| 415 | gzFile file; |
| 416 | voidp buf; |
| 417 | |
| 418 | unsigned len; |
| 419 | { |
| 420 | gz_statep state; |
| 421 | |
| 422 | /* get internal structure */ |
| 423 | if (file == NULL) |
| 424 | return -1; |
| 425 | state = (gz_statep)file; |
| 426 | |
| 427 | /* check that we're reading and that there's no (serious) error */ |
| 428 | if (state->mode != GZ_READ || |
| 429 | (state->err != Z_OK && state->err != Z_BUF_ERROR)) |
| 430 | return -1; |
| 431 | |
| 432 | /* since an int is returned, make sure len fits in one, otherwise return |
| 433 | with an error (this avoids a flaw in the interface) */ |
| 434 | if ((int)len < 0) |
| 435 | { |
| 436 | gz_error(state, Z_STREAM_ERROR, "request does not fit in an int"); |
| 437 | return -1; |
| 438 | } |
| 439 | |
| 440 | /* read len or fewer bytes to buf */ |
| 441 | len = gz_read(state, buf, len); |
| 442 | |
| 443 | /* check for an error */ |
| 444 | if (len == 0 && state->err != Z_OK && state->err != Z_BUF_ERROR) |
| 445 | return -1; |
| 446 | |
| 447 | /* return the number of bytes read (this is assured to fit in an int) */ |
| 448 | return (int)len; |
| 449 | } |
| 450 | |
| 451 | /* -- see zlib.h -- */ |
| 452 | z_size_t ZEXPORT gzfread(buf, size, nitems, file) |