16 struct _PerlIO_funcs {
21 IV (*Pushed) (pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
22 IV (*Popped) (pTHX_ PerlIO *f);
23 PerlIO *(*Open) (pTHX_ PerlIO_funcs *tab,
24 PerlIO_list_t *layers, IV n,
26 int fd, int imode, int perm,
27 PerlIO *old, int narg, SV **args);
28 IV (*Binmode)(pTHX_ PerlIO *f);
29 SV *(*Getarg) (pTHX_ PerlIO *f, CLONE_PARAMS *param, int flags);
30 IV (*Fileno) (pTHX_ PerlIO *f);
31 PerlIO *(*Dup) (pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
32 /* Unix-like functions - cf sfio line disciplines */
33 SSize_t(*Read) (pTHX_ PerlIO *f, void *vbuf, Size_t count);
34 SSize_t(*Unread) (pTHX_ PerlIO *f, const void *vbuf, Size_t count);
35 SSize_t(*Write) (pTHX_ PerlIO *f, const void *vbuf, Size_t count);
36 IV (*Seek) (pTHX_ PerlIO *f, Off_t offset, int whence);
37 Off_t(*Tell) (pTHX_ PerlIO *f);
38 IV (*Close) (pTHX_ PerlIO *f);
39 /* Stdio-like buffered IO functions */
40 IV (*Flush) (pTHX_ PerlIO *f);
41 IV (*Fill) (pTHX_ PerlIO *f);
42 IV (*Eof) (pTHX_ PerlIO *f);
43 IV (*Error) (pTHX_ PerlIO *f);
44 void (*Clearerr) (pTHX_ PerlIO *f);
45 void (*Setlinebuf) (pTHX_ PerlIO *f);
46 /* Perl's snooping functions */
47 STDCHAR *(*Get_base) (pTHX_ PerlIO *f);
48 Size_t(*Get_bufsiz) (pTHX_ PerlIO *f);
49 STDCHAR *(*Get_ptr) (pTHX_ PerlIO *f);
50 SSize_t(*Get_cnt) (pTHX_ PerlIO *f);
51 void (*Set_ptrcnt) (pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
54 /*--------------------------------------------------------------------------------------*/
56 #define PERLIO_K_RAW 0x00000001
57 #define PERLIO_K_BUFFERED 0x00000002
58 #define PERLIO_K_CANCRLF 0x00000004
59 #define PERLIO_K_FASTGETS 0x00000008
60 #define PERLIO_K_DUMMY 0x00000010
61 #define PERLIO_K_UTF8 0x00008000
62 #define PERLIO_K_DESTRUCT 0x00010000
63 #define PERLIO_K_MULTIARG 0x00020000
65 /*--------------------------------------------------------------------------------------*/
67 PerlIOl *next; /* Lower layer */
68 PerlIO_funcs *tab; /* Functions for this layer */
69 U32 flags; /* Various flags for state */
72 /*--------------------------------------------------------------------------------------*/
75 #define PERLIO_F_EOF 0x00000100
76 #define PERLIO_F_CANWRITE 0x00000200
77 #define PERLIO_F_CANREAD 0x00000400
78 #define PERLIO_F_ERROR 0x00000800
79 #define PERLIO_F_TRUNCATE 0x00001000
80 #define PERLIO_F_APPEND 0x00002000
81 #define PERLIO_F_CRLF 0x00004000
82 #define PERLIO_F_UTF8 0x00008000
83 #define PERLIO_F_UNBUF 0x00010000
84 #define PERLIO_F_WRBUF 0x00020000
85 #define PERLIO_F_RDBUF 0x00040000
86 #define PERLIO_F_LINEBUF 0x00080000
87 #define PERLIO_F_TEMP 0x00100000
88 #define PERLIO_F_OPEN 0x00200000
89 #define PERLIO_F_FASTGETS 0x00400000
90 #define PERLIO_F_TTY 0x00800000
91 #define PERLIO_F_NOTREG 0x01000000
93 #define PerlIOBase(f) (*(f))
94 #define PerlIOSelf(f,type) ((type *)PerlIOBase(f))
95 #define PerlIONext(f) (&(PerlIOBase(f)->next))
96 #define PerlIOValid(f) ((f) && *(f))
98 /*--------------------------------------------------------------------------------------*/
99 /* Data exports - EXTCONST rather than extern is needed for Cygwin */
101 #ifdef PERLIO_FUNCS_CONST
102 #define EXTPERLIO EXTCONST
104 #define EXTPERLIO EXT
106 EXTPERLIO PerlIO_funcs PerlIO_unix;
107 EXTPERLIO PerlIO_funcs PerlIO_perlio;
108 EXTPERLIO PerlIO_funcs PerlIO_stdio;
109 EXTPERLIO PerlIO_funcs PerlIO_crlf;
110 EXTPERLIO PerlIO_funcs PerlIO_utf8;
111 EXTPERLIO PerlIO_funcs PerlIO_byte;
112 EXTPERLIO PerlIO_funcs PerlIO_raw;
113 EXTPERLIO PerlIO_funcs PerlIO_pending;
115 EXTPERLIO PerlIO_funcs PerlIO_mmap;
118 EXTPERLIO PerlIO_funcs PerlIO_win32;
120 PERL_EXPORT_C PerlIO *PerlIO_allocate(pTHX);
121 PERL_EXPORT_C SV *PerlIO_arg_fetch(PerlIO_list_t *av, IV n);
122 #define PerlIOArg PerlIO_arg_fetch(layers,n)
124 #ifdef PERLIO_USING_CRLF
125 #define PERLIO_STDTEXT "t"
127 #define PERLIO_STDTEXT ""
130 /*--------------------------------------------------------------------------------------*/
131 /* perlio buffer layer
132 As this is reasonably generic its struct and "methods" are declared here
133 so they can be used to "inherit" from it.
137 struct _PerlIO base; /* Base "class" info */
138 STDCHAR *buf; /* Start of buffer */
139 STDCHAR *end; /* End of valid part of buffer */
140 STDCHAR *ptr; /* Current position in buffer */
141 Off_t posn; /* Offset of buf into the file */
142 Size_t bufsiz; /* Real size of buffer */
143 IV oneword; /* Emergency buffer */
146 PERL_EXPORT_C int PerlIO_apply_layera(pTHX_ PerlIO *f, const char *mode,
147 PerlIO_list_t *layers, IV n, IV max);
148 PERL_EXPORT_C int PerlIO_parse_layers(pTHX_ PerlIO_list_t *av, const char *names);
149 PERL_EXPORT_C PerlIO_funcs *PerlIO_layer_fetch(pTHX_ PerlIO_list_t *av, IV n, PerlIO_funcs *def);
152 PERL_EXPORT_C SV *PerlIO_sv_dup(pTHX_ SV *arg, CLONE_PARAMS *param);
153 PERL_EXPORT_C void PerlIO_cleantable(pTHX_ PerlIO **tablep);
154 PERL_EXPORT_C SV * PerlIO_tab_sv(pTHX_ PerlIO_funcs *tab);
155 PERL_EXPORT_C void PerlIO_default_buffer(pTHX_ PerlIO_list_t *av);
156 PERL_EXPORT_C void PerlIO_stdstreams(pTHX);
157 PERL_EXPORT_C int PerlIO__close(pTHX_ PerlIO *f);
158 PERL_EXPORT_C PerlIO_list_t * PerlIO_resolve_layers(pTHX_ const char *layers, const char *mode, int narg, SV **args);
159 PERL_EXPORT_C PerlIO_funcs * PerlIO_default_layer(pTHX_ I32 n);
160 PERL_EXPORT_C PerlIO_list_t * PerlIO_default_layers(pTHX);
161 PERL_EXPORT_C PerlIO * PerlIO_reopen(const char *path, const char *mode, PerlIO *f);
162 PERL_EXPORT_C int PerlIO_vsprintf(char *s, int n, const char *fmt, va_list ap)
163 __attribute__format__(__printf__,3,0);
165 PERL_EXPORT_C PerlIO_list_t *PerlIO_list_alloc(pTHX);
166 PERL_EXPORT_C PerlIO_list_t *PerlIO_clone_list(pTHX_ PerlIO_list_t *proto, CLONE_PARAMS *param);
167 PERL_EXPORT_C void PerlIO_list_free(pTHX_ PerlIO_list_t *list);
168 PERL_EXPORT_C void PerlIO_list_push(pTHX_ PerlIO_list_t *list, PerlIO_funcs *funcs, SV *arg);
169 PERL_EXPORT_C void PerlIO_list_free(pTHX_ PerlIO_list_t *list);
171 /* PerlIO_teardown doesn't need exporting, but the EXTERN_C is needed
172 * for compiling as C++. Must also match with what perl.h says. */
173 EXTERN_C void PerlIO_teardown(void);
175 /*--------------------------------------------------------------------------------------*/
176 /* Generic, or stub layer functions */
178 PERL_EXPORT_C IV PerlIOBase_binmode(pTHX_ PerlIO *f);
179 PERL_EXPORT_C void PerlIOBase_clearerr(pTHX_ PerlIO *f);
180 PERL_EXPORT_C IV PerlIOBase_close(pTHX_ PerlIO *f);
181 PERL_EXPORT_C PerlIO * PerlIOBase_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
182 PERL_EXPORT_C IV PerlIOBase_eof(pTHX_ PerlIO *f);
183 PERL_EXPORT_C IV PerlIOBase_error(pTHX_ PerlIO *f);
184 PERL_EXPORT_C IV PerlIOBase_fileno(pTHX_ PerlIO *f);
185 PERL_EXPORT_C void PerlIOBase_flush_linebuf(pTHX);
186 PERL_EXPORT_C IV PerlIOBase_noop_fail(pTHX_ PerlIO *f);
187 PERL_EXPORT_C IV PerlIOBase_noop_ok(pTHX_ PerlIO *f);
188 PERL_EXPORT_C IV PerlIOBase_popped(pTHX_ PerlIO *f);
189 PERL_EXPORT_C IV PerlIOBase_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
190 PERL_EXPORT_C SSize_t PerlIOBase_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
191 PERL_EXPORT_C void PerlIOBase_setlinebuf(pTHX_ PerlIO *f);
192 PERL_EXPORT_C SSize_t PerlIOBase_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
195 PERL_EXPORT_C Size_t PerlIOBuf_bufsiz(pTHX_ PerlIO *f);
196 PERL_EXPORT_C IV PerlIOBuf_close(pTHX_ PerlIO *f);
197 PERL_EXPORT_C PerlIO * PerlIOBuf_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
198 PERL_EXPORT_C IV PerlIOBuf_fill(pTHX_ PerlIO *f);
199 PERL_EXPORT_C IV PerlIOBuf_flush(pTHX_ PerlIO *f);
200 PERL_EXPORT_C STDCHAR * PerlIOBuf_get_base(pTHX_ PerlIO *f);
201 PERL_EXPORT_C SSize_t PerlIOBuf_get_cnt(pTHX_ PerlIO *f);
202 PERL_EXPORT_C STDCHAR * PerlIOBuf_get_ptr(pTHX_ PerlIO *f);
203 PERL_EXPORT_C PerlIO * PerlIOBuf_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const char *mode, int fd, int imode, int perm, PerlIO *old, int narg, SV **args);
204 PERL_EXPORT_C IV PerlIOBuf_popped(pTHX_ PerlIO *f);
205 PERL_EXPORT_C IV PerlIOBuf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
206 PERL_EXPORT_C SSize_t PerlIOBuf_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
207 PERL_EXPORT_C IV PerlIOBuf_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
208 PERL_EXPORT_C void PerlIOBuf_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
209 PERL_EXPORT_C Off_t PerlIOBuf_tell(pTHX_ PerlIO *f);
210 PERL_EXPORT_C SSize_t PerlIOBuf_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
211 PERL_EXPORT_C SSize_t PerlIOBuf_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
214 PERL_EXPORT_C IV PerlIOCrlf_binmode(pTHX_ PerlIO *f);
215 PERL_EXPORT_C IV PerlIOCrlf_flush(pTHX_ PerlIO *f);
216 PERL_EXPORT_C SSize_t PerlIOCrlf_get_cnt(pTHX_ PerlIO *f);
217 PERL_EXPORT_C IV PerlIOCrlf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
218 PERL_EXPORT_C void PerlIOCrlf_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
219 PERL_EXPORT_C SSize_t PerlIOCrlf_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
220 PERL_EXPORT_C SSize_t PerlIOCrlf_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
221 PERL_EXPORT_C SSize_t PerlIOCrlf_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
224 PERL_EXPORT_C IV PerlIOMmap_close(pTHX_ PerlIO *f);
225 PERL_EXPORT_C PerlIO * PerlIOMmap_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
226 PERL_EXPORT_C IV PerlIOMmap_fill(pTHX_ PerlIO *f);
227 PERL_EXPORT_C IV PerlIOMmap_flush(pTHX_ PerlIO *f);
228 PERL_EXPORT_C STDCHAR * PerlIOMmap_get_base(pTHX_ PerlIO *f);
229 PERL_EXPORT_C IV PerlIOMmap_map(pTHX_ PerlIO *f);
230 PERL_EXPORT_C IV PerlIOMmap_unmap(pTHX_ PerlIO *f);
231 PERL_EXPORT_C SSize_t PerlIOMmap_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
232 PERL_EXPORT_C SSize_t PerlIOMmap_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
235 PERL_EXPORT_C IV PerlIOPending_close(pTHX_ PerlIO *f);
236 PERL_EXPORT_C IV PerlIOPending_fill(pTHX_ PerlIO *f);
237 PERL_EXPORT_C IV PerlIOPending_flush(pTHX_ PerlIO *f);
238 PERL_EXPORT_C IV PerlIOPending_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
239 PERL_EXPORT_C SSize_t PerlIOPending_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
240 PERL_EXPORT_C IV PerlIOPending_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
241 PERL_EXPORT_C void PerlIOPending_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
244 PERL_EXPORT_C IV PerlIOPop_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
247 PERL_EXPORT_C PerlIO * PerlIORaw_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const char *mode, int fd, int imode, int perm, PerlIO *old, int narg, SV **args);
248 PERL_EXPORT_C IV PerlIORaw_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
251 PERL_EXPORT_C void PerlIOStdio_clearerr(pTHX_ PerlIO *f);
252 PERL_EXPORT_C IV PerlIOStdio_close(pTHX_ PerlIO *f);
253 PERL_EXPORT_C PerlIO * PerlIOStdio_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
254 PERL_EXPORT_C IV PerlIOStdio_eof(pTHX_ PerlIO *f);
255 PERL_EXPORT_C IV PerlIOStdio_error(pTHX_ PerlIO *f);
256 PERL_EXPORT_C IV PerlIOStdio_fileno(pTHX_ PerlIO *f);
257 PERL_EXPORT_C IV PerlIOStdio_fill(pTHX_ PerlIO *f);
258 PERL_EXPORT_C IV PerlIOStdio_flush(pTHX_ PerlIO *f);
259 PERL_EXPORT_C STDCHAR * PerlIOStdio_get_base(pTHX_ PerlIO *f);
260 PERL_EXPORT_C char * PerlIOStdio_mode(const char *mode, char *tmode);
261 PERL_EXPORT_C PerlIO * PerlIOStdio_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const char *mode, int fd, int imode, int perm, PerlIO *f, int narg, SV **args);
262 PERL_EXPORT_C IV PerlIOStdio_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
263 PERL_EXPORT_C SSize_t PerlIOStdio_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
264 PERL_EXPORT_C IV PerlIOStdio_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
265 PERL_EXPORT_C void PerlIOStdio_setlinebuf(pTHX_ PerlIO *f);
266 PERL_EXPORT_C Off_t PerlIOStdio_tell(pTHX_ PerlIO *f);
267 PERL_EXPORT_C SSize_t PerlIOStdio_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
268 PERL_EXPORT_C SSize_t PerlIOStdio_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
271 PERL_EXPORT_C IV PerlIOUnix_close(pTHX_ PerlIO *f);
272 PERL_EXPORT_C PerlIO * PerlIOUnix_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
273 PERL_EXPORT_C IV PerlIOUnix_fileno(pTHX_ PerlIO *f);
274 PERL_EXPORT_C int PerlIOUnix_oflags(const char *mode);
275 PERL_EXPORT_C PerlIO * PerlIOUnix_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const char *mode, int fd, int imode, int perm, PerlIO *f, int narg, SV **args);
276 PERL_EXPORT_C IV PerlIOUnix_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
277 PERL_EXPORT_C SSize_t PerlIOUnix_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
278 PERL_EXPORT_C int PerlIOUnix_refcnt_dec(int fd);
279 PERL_EXPORT_C void PerlIOUnix_refcnt_inc(int fd);
280 PERL_EXPORT_C IV PerlIOUnix_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
281 PERL_EXPORT_C Off_t PerlIOUnix_tell(pTHX_ PerlIO *f);
282 PERL_EXPORT_C SSize_t PerlIOUnix_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
285 PERL_EXPORT_C IV PerlIOUtf8_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
287 #endif /* _PERLIOL_H */
291 * c-indentation-style: bsd
293 * indent-tabs-mode: t
296 * ex: set ts=8 sts=4 sw=4 noet: