1 /*
2  * Copyright (C) 1998,1999 Uwe Ohse
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  *
18  * As a special exception this source may be used as part of the
19  * SRS project by CORE/Computer Service Langenbach
20  * regardless of the copyright they choose.
21  *
22  * Contact: uwe@ohse.de
23  */
24 #ifndef UOIO_H
25 #define UOIO_H
26 
27 /* AUTOCONF: AC_CHECK_TYPE(ssize_t,int) */
28 #include "config.h"
29 #include "uostr.h"
30 #include <sys/uio.h>
31 
32 typedef struct
33 {
34 	int fd;
35 	union {
36 		/* this is a union to get rid of warnings ... */
37 		ssize_t (*r) P__((int fd,void *buf,size_t size));
38 		ssize_t (*w) P__((int fd,const void *buf,size_t size));
39 	} op;
40 	ssize_t (*opv) P__((int fd, const struct iovec * vector, int count));
41 	char *buf;
42 	size_t buflen;
43 	size_t bufsize;
44 	char *rstart;
45 	int eof;
46 	int oerr;
47 	unsigned int timeout; /* in seconds, user-settable */
48 } uoio_t;
49 
50 void uoio_assign_r P__((uoio_t *,int fd,
51 	ssize_t (*op)(int,void *,size_t),
52 	ssize_t (*opv)(int fd, const struct iovec * vector, int count)));
53 void uoio_assign_w P__((uoio_t *,int fd,
54 	ssize_t (*op)(int,const void *,size_t),
55 	ssize_t (*opv)(int fd, const struct iovec * vector, int count)));
56 void uoio_destroy P__((uoio_t *)); /* will not flush output */
57 ssize_t uoio_getdelim_zc  P__((uoio_t * u, char **s, int delim));
58 ssize_t uoio_getdelim_uostr  P__((uoio_t * u, uostr_t *s, int delim));
59 ssize_t uoio_getchar P__((uoio_t * u, char *s));
60 ssize_t uoio_getmem P__((uoio_t * u, void *vs, size_t len));
61 
62 
63 /* how many bytes are still in the buffer? */
64 #define UOIO_PENDING(u) ((u)->buflen-((u)->rstart-(u)->buf))
65 
66 	/* flush output */
67 ssize_t uoio_flush P__((uoio_t *u));
68 /* return -1 on error or len */
69 ssize_t uoio_write_mem P__((uoio_t *u, const void *buf,size_t len));
70 ssize_t uoio_write_cstr P__((uoio_t *u,const char *s));
71 ssize_t uoio_write_cstrmulti P__((uoio_t *u,...));
72 ssize_t uoio_write_char P__((uoio_t *u,char c)); /* of no real use ... */
73 ssize_t uoio_write_uostr P__((uoio_t *u,uostr_t *s));
74 ssize_t uoio_write_v P__((uoio_t *u,struct iovec *iov, int count));
75 
76 #endif
77