Commit 90780cf7 90780cf7ea9ff44bb03eaced4a5d6e2f50ff6f6a by Alain Magloire

io.c io.h io0.h

istream_t and ostream_t implementation.
1 parent fe1332fb
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library 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 #include <io0.h>
19
20 #include <errno.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23
24 int
25 istream_init (istream_t *pis)
26 {
27 istream_t is;
28 if (pis == NULL)
29 return EINVAL;
30 is = calloc (1, sizeof (*is));
31 if (is == NULL)
32 return ENOMEM;
33 *pis = is;
34 return 0;
35 }
36
37 int
38 ostream_init (ostream_t *pos)
39 {
40 ostream_t os;
41 if (pos == NULL)
42 return EINVAL;
43 os = calloc (1, sizeof (*os));
44 if (os == NULL)
45 return ENOMEM;
46 *pos = os;
47 return 0;
48 }
49
50 void
51 istream_destroy (istream_t *pis)
52 {
53 free (pis);
54 }
55
56 void
57 ostream_destroy (ostream_t *pos)
58 {
59 free (pos);
60 }
61
62 int
63 istream_set_read (istream_t is, ssize_t (*read)
64 __P ((istream_t, char *, size_t, off_t)))
65 {
66 if (is == NULL)
67 return EINVAL;
68 is->_read = read;
69 return 0;
70 }
71
72 int
73 ostream_set_write (ostream_t os, ssize_t (*write)
74 __P ((ostream_t, const char *, size_t, off_t)))
75 {
76 if (os == NULL)
77 return EINVAL;
78 os->_write = write;
79 return 0;
80 }
81
82 ssize_t
83 istream_read (istream_t is, char *buf, size_t count, off_t offset)
84 {
85 if (is == NULL || is->_read == NULL)
86 {
87 errno = EINVAL;
88 return -1;
89 }
90 return is->_read (is, buf, count, offset);
91 }
92
93 ssize_t
94 ostream_write (ostream_t os, const char *buf, size_t count, off_t offset)
95 {
96 if (os == NULL || os->_write == NULL)
97 {
98 errno = EINVAL;
99 return -1;
100 }
101 return os->_write (os, buf, count, offset);
102 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library 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 #ifndef _IO_H
19 # define _IO_H
20
21 #include <sys/types.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #ifndef __P
28 # ifdef __STDC__
29 # define __P(args) args
30 # else
31 # define __P(args) ()
32 # endif
33 #endif /*__P */
34
35 struct _istream;
36 typedef struct _istream * istream_t;
37 struct _ostream;
38 typedef struct _ostream * ostream_t;
39
40 extern ssize_t istream_read __P ((istream_t, char *, size_t, off_t));
41
42 extern ssize_t ostream_write __P ((ostream_t, const char *, size_t, off_t));
43
44 #ifdef __cplusplus
45 }
46 #endif
47
48 #endif /* _IO_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library 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 #ifndef _IO0_H
19 # define _IO0_H
20
21 #include <io.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #ifndef __P
28 # ifdef __STDC__
29 # define __P(args) args
30 # else
31 # define __P(args) ()
32 # endif
33 #endif /*__P */
34
35 struct _istream
36 {
37 /* owner of the stream can not be a specific type */
38 void *owner;
39 ssize_t (*_read) __P ((istream_t, char *, size_t, off_t));
40 };
41
42 struct _ostream
43 {
44 /* owner of the stream can not be a specific type */
45 void *owner;
46 ssize_t (*_write) __P ((ostream_t, const char *, size_t, off_t));
47 };
48
49 extern int istream_init __P ((istream_t *));
50 extern void istream_destroy __P ((istream_t *));
51 extern int ostream_init __P ((ostream_t *));
52 extern void ostream_destroy __P ((ostream_t *));
53
54 #ifdef __cplusplus
55 }
56 #endif
57
58 #endif /* _IO0_H */