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.
This commit is contained in:
Mark Adler
2016-12-31 10:03:09 -08:00
parent b7fbee2156
commit cca27e95cf
6 changed files with 19 additions and 67 deletions

View File

@@ -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;