X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=blobdiff_plain;f=lib%2Fmtio.c;h=d7f36ac82d31be22e5d5c9111476d16ee2a15e99;hp=b2f55f8ef6e2c9ded84dbee955617f450f0adb06;hb=b71ad67f41a9e99bd243d57b5038de28f1696f27;hpb=ff28e3a531571868159d2a48039bec6bc83f2f0f diff --git a/lib/mtio.c b/lib/mtio.c index b2f55f8..d7f36ac 100644 --- a/lib/mtio.c +++ b/lib/mtio.c @@ -32,12 +32,6 @@ #include #include -struct stdiofd { - int fd; - int sock; - int timeout; -}; - static ssize_t mtread(void *cookie, void *buf, size_t len) { struct stdiofd *d = cookie; @@ -98,7 +92,7 @@ static int mtclose(void *cookie) return(0); } -FILE *mtstdopen(int fd, int issock, int timeout, char *mode) +FILE *mtstdopen(int fd, int issock, int timeout, char *mode, struct stdiofd **infop) { struct stdiofd *d; FILE *ret; @@ -117,11 +111,13 @@ FILE *mtstdopen(int fd, int issock, int timeout, char *mode) d->fd = fd; d->sock = issock; d->timeout = timeout; - ret = funstdio(d, r?mtread:NULL, w?mtwrite:NULL, NULL, mtclose); - if(!ret) + if(!(ret = funstdio(d, r?mtread:NULL, w?mtwrite:NULL, NULL, mtclose))) { free(d); - else - fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); + return(NULL); + } + fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); + if(infop) + *infop = d; return(ret); }