diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2016-12-31 10:03:09 -0800 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2016-12-31 10:06:40 -0800 |
commit | cca27e95cf2bf057b2bbea93702135da3ca7be45 (patch) | |
tree | 10eac4a38123691dfcfaf6026a7d32a702f9067e /gzread.c | |
parent | b7fbee215674c3399212dffba1e71323056931d9 (diff) | |
download | zlib-cca27e95cf2bf057b2bbea93702135da3ca7be45.tar.gz zlib-cca27e95cf2bf057b2bbea93702135da3ca7be45.tar.bz2 zlib-cca27e95cf2bf057b2bbea93702135da3ca7be45.zip |
Avoid the need for ssize_t.
Limit read() and write() requests to sizes that fit in an int.
This allows storing the return value in an int, and avoiding the
need to use or construct an ssize_t type. This is required for
Microsoft C, whose _read and _write functions take an unsigned
request and return an int.
Diffstat (limited to 'gzread.c')
-rw-r--r-- | gzread.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -24,11 +24,15 @@ local int gz_load(state, buf, len, have) | |||
24 | unsigned len; | 24 | unsigned len; |
25 | unsigned *have; | 25 | unsigned *have; |
26 | { | 26 | { |
27 | z_ssize_t ret; | 27 | int ret; |
28 | unsigned get, max = ((unsigned)-1 >> 2) + 1; | ||
28 | 29 | ||
29 | *have = 0; | 30 | *have = 0; |
30 | do { | 31 | do { |
31 | ret = read(state->fd, buf + *have, len - *have); | 32 | get = len - *have; |
33 | if (get > max) | ||
34 | get = max; | ||
35 | ret = read(state->fd, buf + *have, get); | ||
32 | if (ret <= 0) | 36 | if (ret <= 0) |
33 | break; | 37 | break; |
34 | *have += (unsigned)ret; | 38 | *have += (unsigned)ret; |