-- see zlib.h -- */
(file, buf, len)
| 385 | |
| 386 | /* -- see zlib.h -- */ |
| 387 | int ZEXPORT gzread(file, buf, len) |
| 388 | gzFile file; |
| 389 | voidp buf; |
| 390 | unsigned len; |
| 391 | { |
| 392 | gz_statep state; |
| 393 | |
| 394 | /* get internal structure */ |
| 395 | if (file == NULL) |
| 396 | return -1; |
| 397 | state.file = file; |
| 398 | |
| 399 | /* check that we're reading and that there's no (serious) error */ |
| 400 | if (state.state->mode != GZ_READ || |
| 401 | (state.state->err != Z_OK && state.state->err != Z_BUF_ERROR)) |
| 402 | return -1; |
| 403 | |
| 404 | /* since an int is returned, make sure len fits in one, otherwise return |
| 405 | with an error (this avoids a flaw in the interface) */ |
| 406 | if ((int)len < 0) { |
| 407 | gz_error(state, Z_STREAM_ERROR, "request does not fit in an int"); |
| 408 | return -1; |
| 409 | } |
| 410 | |
| 411 | /* read len or fewer bytes to buf */ |
| 412 | len = (unsigned)gz_read(state, buf, len); |
| 413 | |
| 414 | /* check for an error */ |
| 415 | if (len == 0 && state.state->err != Z_OK && state.state->err != Z_BUF_ERROR) |
| 416 | return -1; |
| 417 | |
| 418 | /* return the number of bytes read (this is assured to fit in an int) */ |
| 419 | return (int)len; |
| 420 | } |
| 421 | |
| 422 | /* -- see zlib.h -- */ |
| 423 | z_size_t ZEXPORT gzfread(buf, size, nitems, file) |