summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2006-12-11 18:54:39 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2006-12-11 18:54:39 +0000
commitc7ed171116c0d28bcca95438a8402542e136ad23 (patch)
treeb7e5d309cd1db528a40138e6770606fa12f581a9 /util.c
parent49e229553e9b28549f808fc6904811234946f8a9 (diff)
downloadgzip-c7ed171116c0d28bcca95438a8402542e136ad23.tar.gz
The SSIZE_MAX fix didn't work on NSK, so fix it in a more-reliable
(albeit more-complicated) way. Problem reported by Matthew Woehlke. * gzip.h (read_buffer): New decl. * unlzw.c (unlzw): Use read_buffer rather than read. * zip.c (file_read): Likewise. * util.c (copy, fill_inbuf): Likewise. (read_buffer, write_buffer): New functions. (write_buf): Use write_buffer rather than write. Undo the previous SSIZE_MAX-related change; it didn't work. * gzip.c: Include <limits.h>. * util.c: Likewise. * gzip.h: Don't include <limits.h>. (INBUFSIZ): Don't worry about SSIZE_MAX here.
Diffstat (limited to 'util.c')
-rw-r--r--util.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/util.c b/util.c
index 32e24e7..434b376 100644
--- a/util.c
+++ b/util.c
@@ -28,6 +28,9 @@ static char rcsid[] = "$Id$";
#include "tailor.h"
+#ifdef HAVE_LIMITS_H
+# include <limits.h>
+#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
@@ -49,6 +52,8 @@ static char rcsid[] = "$Id$";
# define CHAR_BIT 8
#endif
+static int write_buffer OF((int, voidp, unsigned int));
+
extern ulg crc_32_tab[]; /* crc table, defined below */
/* ===========================================================================
@@ -62,7 +67,7 @@ int copy(in, out)
while (insize != 0 && (int)insize != -1) {
write_buf(out, (char*)inbuf, insize);
bytes_out += insize;
- insize = read(in, (char*)inbuf, INBUFSIZ);
+ insize = read_buffer (in, (char *) inbuf, INBUFSIZ);
}
if ((int)insize == -1) {
read_error();
@@ -117,7 +122,7 @@ int fill_inbuf(eof_ok)
/* Read as much as possible */
insize = 0;
do {
- len = read(ifd, (char*)inbuf+insize, INBUFSIZ-insize);
+ len = read_buffer (ifd, (char *) inbuf + insize, INBUFSIZ - insize);
if (len == 0) break;
if (len == -1) {
read_error();
@@ -137,6 +142,35 @@ int fill_inbuf(eof_ok)
return inbuf[0];
}
+/* Like the standard read function, except do not attempt to read more
+ than SSIZE_MAX bytes at a time. */
+int
+read_buffer (fd, buf, cnt)
+ int fd;
+ voidp buf;
+ unsigned int cnt;
+{
+#ifdef SSIZE_MAX
+ if (SSIZE_MAX < cnt)
+ cnt = SSIZE_MAX;
+#endif
+ return read (fd, buf, cnt);
+}
+
+/* Likewise for 'write'. */
+static int
+write_buffer (fd, buf, cnt)
+ int fd;
+ voidp buf;
+ unsigned int cnt;
+{
+#ifdef SSIZE_MAX
+ if (SSIZE_MAX < cnt)
+ cnt = SSIZE_MAX;
+#endif
+ return write (fd, buf, cnt);
+}
+
/* ===========================================================================
* Write the output buffer outbuf[0..outcnt-1] and update bytes_out.
* (used for the compressed data only)
@@ -177,7 +211,7 @@ void write_buf(fd, buf, cnt)
{
unsigned n;
- while ((n = write(fd, buf, cnt)) != cnt) {
+ while ((n = write_buffer (fd, buf, cnt)) != cnt) {
if (n == (unsigned)(-1)) {
write_error();
}