(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.
+2006-12-11 Paul Eggert <eggert@cs.ucla.edu>
+
+ 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.
+
2006-12-08 Paul Eggert <eggert@cs.ucla.edu>
* NEWS, configure.ac (AC_INIT):
# include <fcntl.h>
#endif
+#ifdef HAVE_LIMITS_H
+# include <limits.h>
+#endif
+
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
# define memzero(s, n) bzero((s), (n))
#endif
-#ifdef HAVE_LIMITS_H
-# include <limits.h>
-#endif
-
#ifndef RETSIGTYPE
# define RETSIGTYPE void
#endif
# else
# define INBUFSIZ 0x8000 /* input buffer size */
# endif
-# if defined SSIZE_MAX && SSIZE_MAX < INBUFSIZ
-# undef INBUFSIZ
-# define INBUFSIZ SSIZE_MAX
-# endif
#endif
#define INBUF_EXTRA 64 /* required by unlzw() */
extern void flush_outbuf OF((void));
extern void flush_window OF((void));
extern void write_buf OF((int fd, voidp buf, unsigned cnt));
+extern int read_buffer OF((int fd, voidp buf, unsigned int cnt));
extern char *strlwr OF((char *s));
extern char *gzip_base_name OF((char *fname));
extern int xunlink OF((char *fname));
posbits = 0;
if (insize < INBUF_EXTRA) {
- if ((rsize = read(in, (char*)inbuf+insize, INBUFSIZ)) == -1) {
+ rsize = read_buffer (in, (char *) inbuf + insize, INBUFSIZ);
+ if (rsize == -1) {
read_error();
}
insize += rsize;
#include "tailor.h"
+#ifdef HAVE_LIMITS_H
+# include <limits.h>
+#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
# define CHAR_BIT 8
#endif
+static int write_buffer OF((int, voidp, unsigned int));
+
extern ulg crc_32_tab[]; /* crc table, defined below */
/* ===========================================================================
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();
/* 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();
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)
{
unsigned n;
- while ((n = write(fd, buf, cnt)) != cnt) {
+ while ((n = write_buffer (fd, buf, cnt)) != cnt) {
if (n == (unsigned)(-1)) {
write_error();
}
Assert(insize == 0, "inbuf not empty");
- len = read(ifd, buf, size);
+ len = read_buffer (ifd, buf, size);
if (len == 0) return (int)len;
if (len == (unsigned)-1) {
read_error();