Dolda2000 GitWeb
/
ashd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
lib: Introduced a portable abstraction layer for custom stdio streams.
[ashd.git]
/
lib
/
mtio.c
diff --git
a/lib/mtio.c
b/lib/mtio.c
index
43cc1f7
..
1f4a579
100644
(file)
--- a/
lib/mtio.c
+++ b/
lib/mtio.c
@@
-16,16
+16,17
@@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
+#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
#include <log.h>
#include <utils.h>
#include <mt.h>
#include <log.h>
#include <utils.h>
#include <mt.h>
@@
-37,7
+38,7
@@
struct stdiofd {
int timeout;
};
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;
{
struct stdiofd *d = cookie;
int ev;
@@
-62,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;
{
struct stdiofd *d = cookie;
int ev;
@@
-106,22
+107,26
@@
static int mtclose(void *cookie)
return(0);
}
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;
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;
omalloc(d);
d->fd = fd;
d->sock = issock;
d->timeout = timeout;
- ret = f
opencookie(d, mode, iofuns
);
+ ret = f
unstdio(d, r?mtread:NULL, w?mtwrite:NULL, NULL, mtclose
);
if(!ret)
free(d);
else
if(!ret)
free(d);
else