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
92 #define PerlIOBase(f) (*(f))
93 #define PerlIOSelf(f,type) ((type *)PerlIOBase(f))
94 #define PerlIONext(f) (&(PerlIOBase(f)->next))
95 #define PerlIOValid(f) ((f) && *(f))
97 /*--------------------------------------------------------------------------------------*/
98 /* Data exports - EXT rather than extern is needed for Cygwin */
99 EXT PerlIO_funcs PerlIO_unix;
100 EXT PerlIO_funcs PerlIO_perlio;
101 EXT PerlIO_funcs PerlIO_stdio;
102 EXT PerlIO_funcs PerlIO_crlf;
103 EXT PerlIO_funcs PerlIO_utf8;
104 EXT PerlIO_funcs PerlIO_byte;
105 EXT PerlIO_funcs PerlIO_raw;
106 EXT PerlIO_funcs PerlIO_pending;
108 EXT PerlIO_funcs PerlIO_mmap;
111 EXT PerlIO_funcs PerlIO_win32;
113 extern PerlIO *PerlIO_allocate(pTHX);
114 extern SV *PerlIO_arg_fetch(PerlIO_list_t *av, IV n);
115 #define PerlIOArg PerlIO_arg_fetch(layers,n)
117 #ifdef PERLIO_USING_CRLF
118 #define PERLIO_STDTEXT "t"
120 #define PERLIO_STDTEXT ""
123 /*--------------------------------------------------------------------------------------*/
124 /* Generic, or stub layer functions */
126 extern IV PerlIOBase_fileno(pTHX_ PerlIO *f);
127 extern PerlIO *PerlIOBase_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
128 extern IV PerlIOBase_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
129 extern IV PerlIOBase_popped(pTHX_ PerlIO *f);
130 extern IV PerlIOBase_binmode(pTHX_ PerlIO *f);
131 extern SSize_t PerlIOBase_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
132 extern SSize_t PerlIOBase_unread(pTHX_ PerlIO *f, const void *vbuf,
134 extern IV PerlIOBase_eof(pTHX_ PerlIO *f);
135 extern IV PerlIOBase_error(pTHX_ PerlIO *f);
136 extern void PerlIOBase_clearerr(pTHX_ PerlIO *f);
137 extern IV PerlIOBase_close(pTHX_ PerlIO *f);
138 extern void PerlIOBase_setlinebuf(pTHX_ PerlIO *f);
139 extern void PerlIOBase_flush_linebuf(pTHX);
141 extern IV PerlIOBase_noop_ok(pTHX_ PerlIO *f);
142 extern IV PerlIOBase_noop_fail(pTHX_ PerlIO *f);
144 /*--------------------------------------------------------------------------------------*/
145 /* perlio buffer layer
146 As this is reasonably generic its struct and "methods" are declared here
147 so they can be used to "inherit" from it.
151 struct _PerlIO base; /* Base "class" info */
152 STDCHAR *buf; /* Start of buffer */
153 STDCHAR *end; /* End of valid part of buffer */
154 STDCHAR *ptr; /* Current position in buffer */
155 Off_t posn; /* Offset of buf into the file */
156 Size_t bufsiz; /* Real size of buffer */
157 IV oneword; /* Emergency buffer */
160 extern int PerlIO_apply_layera(pTHX_ PerlIO *f, const char *mode,
161 PerlIO_list_t *layers, IV n, IV max);
162 extern int PerlIO_parse_layers(pTHX_ PerlIO_list_t *av, const char *names);
163 extern void PerlIO_list_free(pTHX_ PerlIO_list_t *list);
164 extern PerlIO_funcs *PerlIO_layer_fetch(pTHX_ PerlIO_list_t *av, IV n, PerlIO_funcs *def);
167 extern SV *PerlIO_sv_dup(pTHX_ SV *arg, CLONE_PARAMS *param);
168 extern PerlIO *PerlIOBuf_open(pTHX_ PerlIO_funcs *self,
169 PerlIO_list_t *layers, IV n,
170 const char *mode, int fd, int imode,
171 int perm, PerlIO *old, int narg, SV **args);
172 extern IV PerlIOBuf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
173 extern IV PerlIOBuf_popped(pTHX_ PerlIO *f);
174 extern PerlIO *PerlIOBuf_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
175 extern SSize_t PerlIOBuf_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
176 extern SSize_t PerlIOBuf_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
177 extern SSize_t PerlIOBuf_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
178 extern IV PerlIOBuf_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
179 extern Off_t PerlIOBuf_tell(pTHX_ PerlIO *f);
180 extern IV PerlIOBuf_close(pTHX_ PerlIO *f);
181 extern IV PerlIOBuf_flush(pTHX_ PerlIO *f);
182 extern IV PerlIOBuf_fill(pTHX_ PerlIO *f);
183 extern STDCHAR *PerlIOBuf_get_base(pTHX_ PerlIO *f);
184 extern Size_t PerlIOBuf_bufsiz(pTHX_ PerlIO *f);
185 extern STDCHAR *PerlIOBuf_get_ptr(pTHX_ PerlIO *f);
186 extern SSize_t PerlIOBuf_get_cnt(pTHX_ PerlIO *f);
187 extern void PerlIOBuf_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
189 extern int PerlIOUnix_oflags(const char *mode);
191 /*--------------------------------------------------------------------------------------*/
193 #endif /* _PERLIOL_H */