X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=lib%2Fmtio.c;h=1f4a579b9612eb18a643972deb0528173f0466fa;hb=2b8eb6dfb02dc93372c5e0a4efa6dff73a8ba004;hp=3b728d0d8c62b1647d62fbfe332b5a2a482902ef;hpb=4d2dc22a9a68395a5788ae66c84ae0ced2d0e733;p=ashd.git diff --git a/lib/mtio.c b/lib/mtio.c index 3b728d0..1f4a579 100644 --- a/lib/mtio.c +++ b/lib/mtio.c @@ -16,6 +16,9 @@ along with this program. If not, see . */ +#ifdef HAVE_CONFIG_H +#include +#endif #include #include #include @@ -24,9 +27,6 @@ #include #include -#ifdef HAVE_CONFIG_H -#include -#endif #include #include #include @@ -38,7 +38,7 @@ struct stdiofd { int timeout; }; -static ssize_t mtread(void *cookie, char *buf, size_t len) +static ssize_t mtread(void *cookie, void *buf, size_t len) { struct stdiofd *d = cookie; int ev; @@ -63,7 +63,7 @@ static ssize_t mtread(void *cookie, char *buf, size_t len) } } -static ssize_t mtwrite(void *cookie, const char *buf, size_t len) +static ssize_t mtwrite(void *cookie, const void *buf, size_t len) { struct stdiofd *d = cookie; int ev; @@ -107,22 +107,26 @@ static int mtclose(void *cookie) return(0); } -static cookie_io_functions_t iofuns = { - .read = mtread, - .write = mtwrite, - .close = mtclose, -}; - FILE *mtstdopen(int fd, int issock, int timeout, char *mode) { struct stdiofd *d; FILE *ret; + int r, w; + if(!strcmp(mode, "r")) { + r = 1; w = 0; + } else if(!strcmp(mode, "w")) { + r = 0; w = 1; + } else if(!strcmp(mode, "r+")) { + r = w = 1; + } else { + return(NULL); + } omalloc(d); d->fd = fd; d->sock = issock; d->timeout = timeout; - ret = fopencookie(d, mode, iofuns); + ret = funstdio(d, r?mtread:NULL, w?mtwrite:NULL, NULL, mtclose); if(!ret) free(d); else