summaryrefslogtreecommitdiff
path: root/gzread.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2016-12-31 10:03:09 -0800
committerMark Adler <madler@alumni.caltech.edu>2016-12-31 10:06:40 -0800
commitcca27e95cf2bf057b2bbea93702135da3ca7be45 (patch)
tree10eac4a38123691dfcfaf6026a7d32a702f9067e /gzread.c
parentb7fbee215674c3399212dffba1e71323056931d9 (diff)
downloadzlib-cca27e95cf2bf057b2bbea93702135da3ca7be45.tar.gz
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.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/gzread.c b/gzread.c
index 3811157..deea79b 100644
--- a/gzread.c
+++ b/gzread.c
@@ -24,11 +24,15 @@ local int gz_load(state, buf, len, have)
unsigned len;
unsigned *have;
{
- z_ssize_t ret;
+ int ret;
+ unsigned get, max = ((unsigned)-1 >> 2) + 1;
*have = 0;
do {
- ret = read(state->fd, buf + *have, len - *have);
+ get = len - *have;
+ if (get > max)
+ get = max;
+ ret = read(state->fd, buf + *have, get);
if (ret <= 0)
break;
*have += (unsigned)ret;