2 Copyright (C) 1993, 1995 Free Software Foundation
4 This file is part of the GNU IO Library. This library is free
5 software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option)
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this library; see the file COPYING. If not, write to the Free
17 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 As a special exception, if you link this library with files
20 compiled with a GNU compiler to produce an executable, this does not cause
21 the resulting executable to be covered by the GNU General Public License.
22 This exception does not however invalidate any other reasons why
23 the executable file might be covered by the GNU General Public License. */
28 struct _IO_cookie_file
{
32 _IO_cookie_io_functions_t io_functions
;
37 _IO_cookie_read (fp
, buf
, size
)
38 register _IO_FILE
* fp
;
42 struct _IO_cookie_file
*cfile
= (struct _IO_cookie_file
*) fp
;
44 if (cfile
->io_functions
.read
== NULL
)
47 return cfile
->io_functions
.read (cfile
->cookie
, buf
, size
);
51 _IO_cookie_write (fp
, buf
, size
)
52 register _IO_FILE
* fp
;
56 struct _IO_cookie_file
*cfile
= (struct _IO_cookie_file
*) fp
;
58 if (cfile
->io_functions
.write
== NULL
)
61 return cfile
->io_functions
.write (cfile
->cookie
, buf
, size
);
65 _IO_cookie_seek (fp
, offset
, dir
)
70 struct _IO_cookie_file
*cfile
= (struct _IO_cookie_file
*) fp
;
73 if (cfile
->io_functions
.seek
== NULL
)
77 _IO_pos_adjust (pos
, offset
);
79 if (cfile
->io_functions
.seek (cfile
->cookie
, pos
, dir
))
89 struct _IO_cookie_file
*cfile
= (struct _IO_cookie_file
*) fp
;
91 if (cfile
->io_functions
.close
== NULL
)
94 return cfile
->io_functions
.close (cfile
->cookie
);
98 static struct _IO_jump_t _IO_cookie_jumps
= {
100 JUMP_INIT(finish
, _IO_file_finish
),
101 JUMP_INIT(overflow
, _IO_file_overflow
),
102 JUMP_INIT(underflow
, _IO_file_underflow
),
103 JUMP_INIT(uflow
, _IO_default_uflow
),
104 JUMP_INIT(pbackfail
, _IO_default_pbackfail
),
105 JUMP_INIT(xsputn
, _IO_file_xsputn
),
106 JUMP_INIT(xsgetn
, _IO_default_xsgetn
),
107 JUMP_INIT(seekoff
, _IO_file_seekoff
),
108 JUMP_INIT(seekpos
, _IO_default_seekpos
),
109 JUMP_INIT(setbuf
, _IO_file_setbuf
),
110 JUMP_INIT(sync
, _IO_file_sync
),
111 JUMP_INIT(doallocate
, _IO_file_doallocate
),
112 JUMP_INIT(read
, _IO_cookie_read
),
113 JUMP_INIT(write
, _IO_cookie_write
),
114 JUMP_INIT(seek
, _IO_cookie_seek
),
115 JUMP_INIT(close
, _IO_cookie_close
),
116 JUMP_INIT(stat
, _IO_default_stat
)
121 fopencookie (cookie
, mode
, io_functions
)
124 _IO_cookie_io_functions_t io_functions
;
127 struct _IO_cookie_file
*cfile
;
132 read_write
= _IO_NO_WRITES
;
135 read_write
= _IO_NO_READS
;
138 read_write
= _IO_NO_READS
|_IO_IS_APPENDING
;
143 if (mode
[0] == '+' || (mode
[0] == 'b' && mode
[1] == '+'))
144 read_write
&= _IO_IS_APPENDING
;
146 cfile
= (struct _IO_cookie_file
*) malloc (sizeof (struct _IO_cookie_file
));
150 _IO_init (&cfile
->file
, 0);
151 _IO_JUMPS (&cfile
->file
) = &_IO_cookie_jumps
;
152 cfile
->cookie
= cookie
;
153 cfile
->io_functions
= io_functions
;
155 _IO_file_init(&cfile
->file
);
157 cfile
->file
._IO_file_flags
=
158 _IO_mask_flags (&cfile
->file
, read_write
,
159 _IO_NO_READS
+_IO_NO_WRITES
+_IO_IS_APPENDING
);