+ return(off);
+}
+
+static int mtclose(void *cookie)
+{
+ struct stdiofd *d = cookie;
+
+ close(d->fd);
+ free(d);
+ 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;
+
+ omalloc(d);
+ d->fd = fd;
+ d->sock = issock;
+ d->timeout = timeout;
+ ret = fopencookie(d, mode, iofuns);
+ if(!ret)
+ free(d);
+ else
+ fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
+ return(ret);