X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Fmtio.c;h=70a0949684d4169c8aa6fec6cb51944939ba49c5;hb=3305e2b999bdc31f99ff159219fc6811b1c15585;hp=3b728d0d8c62b1647d62fbfe332b5a2a482902ef;hpb=0b7964e936e61c43e9f9db51a8f9cbb6f9869b63;p=ashd.git
diff --git a/lib/mtio.c b/lib/mtio.c
index 3b728d0..70a0949 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
@@ -107,6 +107,7 @@ static int mtclose(void *cookie)
return(0);
}
+#if defined(HAVE_GLIBC_STDIO)
static cookie_io_functions_t iofuns = {
.read = mtread,
.write = mtwrite,
@@ -129,3 +130,43 @@ FILE *mtstdopen(int fd, int issock, int timeout, char *mode)
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
return(ret);
}
+#elif defined(HAVE_BSD_STDIO)
+static int bsd2mtread(void *cookie, char *buf, int len)
+{
+ return(mtread(cookie, buf, len));
+}
+
+static int bsd2mtwrite(void *cookie, const char *buf, int len)
+{
+ return(mtwrite(cookie, buf, len));
+}
+
+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 = funopen(d, r?bsd2mtread:NULL, w?bsd2mtwrite:NULL, NULL, mtclose);
+ if(!ret)
+ free(d);
+ else
+ fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
+ return(ret);
+}
+#else
+#error "No stdio implementation for this system"
+#endif