Description: At least partially use ssize_t for read(2)/write(2)
Bug-Debian: https://bugs.debian.org/1075596
Author: Peter Pentchev <roam@ringlet.net>
Forwarded: no
Last-Update: 2024-07-24

--- a/buffer.c
+++ b/buffer.c
@@ -1,6 +1,6 @@
 #include "buffer.h"
 
-void buffer_init(buffer *s,int (*op)(),int fd,char *buf,unsigned int len)
+void buffer_init(buffer *s,ssize_t(*op)(),int fd,char *buf,unsigned int len)
 {
   s->x = buf;
   s->fd = fd;
--- a/buffer.h
+++ b/buffer.h
@@ -1,19 +1,21 @@
 #ifndef BUFFER_H
 #define BUFFER_H
 
+#include <sys/types.h>
+
 typedef struct buffer {
   char *x;
   unsigned int p;
   unsigned int n;
   int fd;
-  int (*op)();
+  ssize_t (*op)();
 } buffer;
 
 #define BUFFER_INIT(op,fd,buf,len) { (buf), 0, (len), (fd), (op) }
 #define BUFFER_INSIZE 8192
 #define BUFFER_OUTSIZE 8192
 
-extern void buffer_init(buffer *,int (*)(),int,char *,unsigned int);
+extern void buffer_init(buffer *,ssize_t (*)(),int,char *,unsigned int);
 
 extern int buffer_flush(buffer *);
 extern int buffer_put(buffer *,char *,unsigned int);
--- a/buffer_get.c
+++ b/buffer_get.c
@@ -2,7 +2,7 @@
 #include "byte.h"
 #include "error.h"
 
-static int oneread(int (*op)(),int fd,char *buf,unsigned int len)
+static ssize_t oneread(ssize_t (*op)(),int fd,char *buf,unsigned int len)
 {
   int r;
 
@@ -27,7 +27,7 @@
   int r;
 
   if (s->p) return s->p;
-  r = oneread(s->op,s->fd,s->x,s->n);
+  r = (int)oneread(s->op,s->fd,s->x,s->n);
   if (r <= 0) return r;
   s->p = r;
   s->n -= r;
@@ -40,7 +40,7 @@
   int r;
  
   if (s->p > 0) return getthis(s,buf,len);
-  if (s->n <= len) return oneread(s->op,s->fd,buf,s->n);
+  if (s->n <= len) return (int)oneread(s->op,s->fd,buf,s->n);
   r = buffer_feed(s); if (r <= 0) return r;
   return getthis(s,buf,len);
 }
@@ -50,7 +50,7 @@
   int r;
  
   if (s->p > 0) return getthis(s,buf,len);
-  if (s->n <= len) return oneread(s->op,s->fd,buf,len);
+  if (s->n <= len) return (int)oneread(s->op,s->fd,buf,len);
   r = buffer_feed(s); if (r <= 0) return r;
   return getthis(s,buf,len);
 }
--- a/buffer_put.c
+++ b/buffer_put.c
@@ -3,9 +3,9 @@
 #include "byte.h"
 #include "error.h"
 
-static int allwrite(int (*op)(),int fd,char *buf,unsigned int len)
+static ssize_t allwrite(ssize_t (*op)(),int fd,char *buf,unsigned int len)
 {
-  int w;
+  ssize_t w;
 
   while (len) {
     w = op(fd,buf,len);
@@ -27,7 +27,7 @@
   p = s->p;
   if (!p) return 0;
   s->p = 0;
-  return allwrite(s->op,s->fd,s->x,p);
+  return (int)allwrite(s->op,s->fd,s->x,p);
 }
 
 int buffer_putalign(buffer *s,char *buf,unsigned int len)
@@ -55,7 +55,7 @@
     if (n < BUFFER_OUTSIZE) n = BUFFER_OUTSIZE;
     while (len > s->n) {
       if (n > len) n = len;
-      if (allwrite(s->op,s->fd,buf,n) == -1) return -1;
+      if ((int)allwrite(s->op,s->fd,buf,n) == -1) return -1;
       buf += n;
       len -= n;
     }
@@ -69,7 +69,7 @@
 int buffer_putflush(buffer *s,char *buf,unsigned int len)
 {
   if (buffer_flush(s) == -1) return -1;
-  return allwrite(s->op,s->fd,buf,len);
+  return (int)allwrite(s->op,s->fd,buf,len);
 }
 
 int buffer_putsalign(buffer *s,char *buf)
--- a/mconnect-io.c
+++ b/mconnect-io.c
@@ -13,7 +13,7 @@
 char inbuf[512];
 buffer bin;
 
-int myread(int fd,char *buf,int len)
+ssize_t myread(int fd,char *buf,int len)
 {
   buffer_flush(&bout);
   return read(fd,buf,len);
--- a/remoteinfo.c
+++ b/remoteinfo.c
@@ -10,7 +10,7 @@
 static struct taia now;
 static struct taia deadline;
 
-static int mywrite(int fd,char *buf,int len)
+static ssize_t mywrite(int fd,char *buf,int len)
 {
   iopause_fd x;
 
@@ -28,7 +28,7 @@
   return write(fd,buf,len);
 }
 
-static int myread(int fd,char *buf,int len)
+static ssize_t myread(int fd,char *buf,int len)
 {
   iopause_fd x;
 
--- a/buffer_0.c
+++ b/buffer_0.c
@@ -1,7 +1,7 @@
 #include "readwrite.h"
 #include "buffer.h"
 
-int buffer_0_read(fd,buf,len) int fd; char *buf; int len;
+ssize_t buffer_0_read(fd,buf,len) int fd; char *buf; int len;
 {
   if (buffer_flush(buffer_1) == -1) return -1;
   return read(fd,buf,len);
