nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit b21142012117318e76d7efc4eadb061966e2b2aa
parent 5b825d28a528bd62f553098357bef83c84609d4d
Author: Rolf Eike Beer <eike@sf-mail.de>
Date:   Tue, 20 Aug 2019 20:53:26 +0200

use size_t and ssize_t in substdio

Adapt the prototypes of all op functions used in substdio to match the interface
of read() and write(). In summary this is:

- the return type is ssize_t
- the buffer is void* for read and const void* for write functions
- the length parameter is size_t

Diffstat:
Mcondredirect.c | 2+-
Mforward.c | 2+-
Mqmail-pop3d.c | 8++++----
Mqmail-popup.c | 8++++----
Mqmail-qmqpc.c | 8++++----
Mqmail-qmqpd.c | 8++++----
Mqmail-qmtpd.c | 8++++----
Mqmail-remote.c | 9+++++----
Mqmail-smtpd.c | 8++++----
Mqmail.c | 2+-
Mremoteinfo.c | 4++--
Mspawn.c | 2+-
Msubfd.h | 4++--
Msubfdin.c | 2+-
Msubfdins.c | 2+-
Msubstdi.c | 10++--------
Msubstdio.c | 7+------
Msubstdio.h | 14++++++++------
Msubstdo.c | 23+++++------------------
Mtimeoutread.c | 2+-
Mtimeoutread.h | 4+++-
Mtimeoutwrite.c | 2+-
Mtimeoutwrite.h | 4+++-
23 files changed, 63 insertions(+), 80 deletions(-)

diff --git a/condredirect.c b/condredirect.c @@ -15,7 +15,7 @@ struct qmail qqt; -int mywrite(fd,buf,len) int fd; char *buf; int len; +ssize_t mywrite(int fd, const void *buf, size_t len) { qmail_put(&qqt,buf,len); return len; diff --git a/forward.c b/forward.c @@ -12,7 +12,7 @@ void die_nomem() { strerr_die2x(111,FATAL,"out of memory"); } struct qmail qqt; -int mywrite(fd,buf,len) int fd; char *buf; int len; +ssize_t mywrite(int fd, const void *buf, size_t len) { qmail_put(&qqt,buf,len); return len; diff --git a/qmail-pop3d.c b/qmail-pop3d.c @@ -24,17 +24,17 @@ void die() { _exit(0); } extern int rename(const char *, const char *); -int saferead(fd,buf,len) int fd; char *buf; int len; +ssize_t saferead(int fd, void *buf, size_t len) { - int r; + ssize_t r; r = timeoutread(1200,fd,buf,len); if (r <= 0) die(); return r; } -int safewrite(fd,buf,len) int fd; char *buf; int len; +ssize_t safewrite(int fd, const void *buf, size_t len) { - int r; + ssize_t r; r = timeoutwrite(1200,fd,buf,len); if (r <= 0) die(); return r; diff --git a/qmail-popup.c b/qmail-popup.c @@ -16,17 +16,17 @@ void die() { _exit(1); } -int saferead(fd,buf,len) int fd; char *buf; int len; +ssize_t saferead(int fd, void *buf, size_t len) { - int r; + ssize_t r; r = timeoutread(1200,fd,buf,len); if (r <= 0) die(); return r; } -int safewrite(fd,buf,len) int fd; char *buf; int len; +ssize_t safewrite(int fd, const void *buf, size_t len) { - int r; + ssize_t r; r = timeoutwrite(1200,fd,buf,len); if (r <= 0) die(); return r; diff --git a/qmail-qmqpc.c b/qmail-qmqpc.c @@ -34,16 +34,16 @@ void die_format() { _exit(91); } int lasterror = 55; int qmqpfd; -int saferead(fd,buf,len) int fd; char *buf; int len; +ssize_t saferead(int fd, void *buf, size_t len) { - int r; + ssize_t r; r = timeoutread(60,qmqpfd,buf,len); if (r <= 0) die_conn(); return r; } -int safewrite(fd,buf,len) int fd; char *buf; int len; +ssize_t safewrite(int fd, const void *buf, size_t len) { - int r; + ssize_t r; r = timeoutwrite(60,qmqpfd,buf,len); if (r <= 0) die_conn(); return r; diff --git a/qmail-qmqpd.c b/qmail-qmqpd.c @@ -13,16 +13,16 @@ void resources() { _exit(111); } -int safewrite(fd,buf,len) int fd; char *buf; int len; +ssize_t safewrite(int fd, const void *buf, size_t len) { - int r; + ssize_t r; r = write(fd,buf,len); if (r <= 0) _exit(0); return r; } -int saferead(fd,buf,len) int fd; char *buf; int len; +ssize_t saferead(int fd, void *buf, size_t len) { - int r; + ssize_t r; r = read(fd,buf,len); if (r <= 0) _exit(0); return r; diff --git a/qmail-qmtpd.c b/qmail-qmtpd.c @@ -17,9 +17,9 @@ void badproto() { _exit(100); } void resources() { _exit(111); } -int safewrite(fd,buf,len) int fd; char *buf; int len; +ssize_t safewrite(int fd, const void *buf, size_t len) { - int r; + ssize_t r; r = write(fd,buf,len); if (r <= 0) _exit(0); return r; @@ -28,9 +28,9 @@ int safewrite(fd,buf,len) int fd; char *buf; int len; char ssoutbuf[256]; substdio ssout = SUBSTDIO_FDBUF(safewrite,1,ssoutbuf,sizeof ssoutbuf); -int saferead(fd,buf,len) int fd; char *buf; int len; +ssize_t saferead(int fd, void *buf, size_t len) { - int r; + ssize_t r; substdio_flush(&ssout); r = read(fd,buf,len); if (r <= 0) _exit(0); diff --git a/qmail-remote.c b/qmail-remote.c @@ -106,16 +106,17 @@ int timeoutconnect = 60; int smtpfd; int timeout = 1200; -int saferead(fd,buf,len) int fd; char *buf; int len; +ssize_t saferead(int fd, void *buf, size_t len) { - int r; + ssize_t r; r = timeoutread(timeout,smtpfd,buf,len); if (r <= 0) dropped(); return r; } -int safewrite(fd,buf,len) int fd; char *buf; int len; + +ssize_t safewrite(int fd, const void *buf, size_t len) { - int r; + ssize_t r; r = timeoutwrite(timeout,smtpfd,buf,len); if (r <= 0) dropped(); return r; diff --git a/qmail-smtpd.c b/qmail-smtpd.c @@ -29,9 +29,9 @@ unsigned int databytes = 0; int timeout = 1200; -int safewrite(fd,buf,len) int fd; char *buf; int len; +ssize_t safewrite(int fd, const void *buf, size_t len) { - int r; + ssize_t r; r = timeoutwrite(timeout,fd,buf,len); if (r <= 0) _exit(1); return r; @@ -266,9 +266,9 @@ void smtp_rcpt(arg) char *arg; { } -int saferead(fd,buf,len) int fd; char *buf; int len; +ssize_t saferead(int fd, void *buf, size_t len) { - int r; + ssize_t r; flush(); r = timeoutread(timeout,fd,buf,len); if (r == -1) if (errno == error_timeout) die_alarm(); diff --git a/qmail.c b/qmail.c @@ -61,7 +61,7 @@ void qmail_fail(qq) struct qmail *qq; qq->flagerr = 1; } -void qmail_put(qq,s,len) struct qmail *qq; char *s; unsigned int len; +void qmail_put(struct qmail *qq, char *s, size_t len) { if (!qq->flagerr) if (substdio_put(&qq->ss,s,len) == -1) qq->flagerr = 1; } diff --git a/remoteinfo.c b/remoteinfo.c @@ -15,11 +15,11 @@ static char line[999]; static int t; -static int mywrite(fd,buf,len) int fd; char *buf; int len; +static ssize_t mywrite(int fd, const void *buf, size_t len) { return timeoutwrite(t,fd,buf,len); } -static int myread(fd,buf,len) int fd; char *buf; int len; +static ssize_t myread(int fd, void *buf, size_t len) { return timeoutread(t,fd,buf,len); } diff --git a/spawn.c b/spawn.c @@ -48,7 +48,7 @@ void sigchld() int flagwriting = 1; -int okwrite(fd,buf,n) int fd; char *buf; int n; +ssize_t okwrite(int fd, const void *buf, size_t n) { int w; if (!flagwriting) return n; diff --git a/subfd.h b/subfd.h @@ -9,7 +9,7 @@ extern substdio *subfdout; extern substdio *subfdoutsmall; extern substdio *subfderr; -extern int subfd_read(); -extern int subfd_readsmall(); +extern ssize_t subfd_read(int fd, void *buf, size_t len); +extern ssize_t subfd_readsmall(int fd, void *buf, size_t len); #endif diff --git a/subfdin.c b/subfdin.c @@ -2,7 +2,7 @@ #include "substdio.h" #include "subfd.h" -int subfd_read(fd,buf,len) int fd; char *buf; int len; +ssize_t subfd_read(int fd, void *buf, size_t len) { if (substdio_flush(subfdout) == -1) return -1; return read(fd,buf,len); diff --git a/subfdins.c b/subfdins.c @@ -2,7 +2,7 @@ #include "substdio.h" #include "subfd.h" -int subfd_readsmall(fd,buf,len) int fd; char *buf; int len; +ssize_t subfd_readsmall(int fd, void *buf, size_t len) { if (substdio_flush(subfdoutsmall) == -1) return -1; return read(fd,buf,len); diff --git a/substdi.c b/substdi.c @@ -2,16 +2,10 @@ #include "byte.h" #include "error.h" -static int oneread(op,fd,buf,len) -register int (*op)(); -register int fd; -register char *buf; -register int len; +static int oneread(ssize_t (*op)(), int fd, char *buf, size_t len) { - register int r; - for (;;) { - r = op(fd,buf,len); + ssize_t r = op(fd,buf,len); if (r == -1) if (errno == error_intr) continue; return r; } diff --git a/substdio.c b/substdio.c @@ -1,11 +1,6 @@ #include "substdio.h" -void substdio_fdbuf(s,op,fd,buf,len) -register substdio *s; -register int (*op)(); -register int fd; -register char *buf; -register int len; +void substdio_fdbuf(substdio *s, ssize_t (*op)(), int fd, char *buf, int len) { s->x = buf; s->fd = fd; diff --git a/substdio.h b/substdio.h @@ -1,22 +1,24 @@ #ifndef SUBSTDIO_H #define SUBSTDIO_H +#include <sys/types.h> + typedef struct substdio { char *x; int p; int n; int fd; - int (*op)(); + ssize_t (*op)(); } substdio; -#define SUBSTDIO_FDBUF(op,fd,buf,len) { (buf), 0, (len), (fd), (op) } +#define SUBSTDIO_FDBUF(o,f,buf,len) { (buf), 0, (len), (f), (o) } -extern void substdio_fdbuf(); +extern void substdio_fdbuf(substdio *s, ssize_t (*op)(), int fd, char *buf, int len); extern int substdio_flush(); -extern int substdio_put(); -extern int substdio_bput(); -extern int substdio_putflush(); +extern int substdio_put(substdio *s, char *buf, size_t len); +extern int substdio_bput(substdio *s, char *buf, size_t len); +extern int substdio_putflush(substdio *s, char *buf, size_t len); extern int substdio_puts(); extern int substdio_bputs(); extern int substdio_putsflush(); diff --git a/substdo.c b/substdo.c @@ -3,13 +3,9 @@ #include "byte.h" #include "error.h" -static int allwrite(op,fd,buf,len) -register int (*op)(); -register int fd; -register char *buf; -register unsigned int len; +static int allwrite(ssize_t (*op)(), int fd, char *buf, size_t len) { - register int w; + ssize_t w; while (len) { w = op(fd,buf,len); @@ -35,10 +31,7 @@ register substdio *s; return allwrite(s->op,s->fd,s->x,p); } -int substdio_bput(s,buf,len) -register substdio *s; -register char *buf; -register unsigned int len; +int substdio_bput(substdio *s, char *buf, size_t len) { register unsigned int n; @@ -55,10 +48,7 @@ register unsigned int len; return 0; } -int substdio_put(s,buf,len) -register substdio *s; -register char *buf; -register unsigned int len; +int substdio_put(substdio *s, char *buf, size_t len) { register unsigned int n = s->n; /* how many bytes to write in next chunk */ @@ -82,10 +72,7 @@ register unsigned int len; return 0; } -int substdio_putflush(s,buf,len) -register substdio *s; -register char *buf; -register int len; +int substdio_putflush(substdio *s, char *buf, size_t len) { if (substdio_flush(s) == -1) return -1; return allwrite(s->op,s->fd,buf,len); diff --git a/timeoutread.c b/timeoutread.c @@ -3,7 +3,7 @@ #include "error.h" #include "readwrite.h" -int timeoutread(t,fd,buf,len) int t; int fd; char *buf; int len; +ssize_t timeoutread(int t, int fd, char *buf, size_t len) { fd_set rfds; struct timeval tv; diff --git a/timeoutread.h b/timeoutread.h @@ -1,6 +1,8 @@ #ifndef TIMEOUTREAD_H #define TIMEOUTREAD_H -extern int timeoutread(); +#include <sys/types.h> + +extern ssize_t timeoutread(int t, int fd, char *buf, size_t len); #endif diff --git a/timeoutwrite.c b/timeoutwrite.c @@ -3,7 +3,7 @@ #include "error.h" #include "readwrite.h" -int timeoutwrite(t,fd,buf,len) int t; int fd; char *buf; int len; +ssize_t timeoutwrite(int t, int fd, const void *buf, size_t len) { fd_set wfds; struct timeval tv; diff --git a/timeoutwrite.h b/timeoutwrite.h @@ -1,6 +1,8 @@ #ifndef TIMEOUTWRITE_H #define TIMEOUTWRITE_H -extern int timeoutwrite(); +#include <sys/types.h> + +extern ssize_t timeoutwrite(int t, int fd, const void *buf, size_t len); #endif