16 struct _PerlIO_funcs {
20 IV (*Pushed) (pTHX_ PerlIO *f, const char *mode, SV *arg);
21 IV (*Popped) (pTHX_ PerlIO *f);
22 PerlIO *(*Open) (pTHX_ PerlIO_funcs *tab,
23 PerlIO_list_t *layers, IV n,
25 int fd, int imode, int perm,
26 PerlIO *old, int narg, SV **args);
27 SV *(*Getarg) (pTHX_ PerlIO *f, CLONE_PARAMS *param, int flags);
28 IV (*Fileno) (pTHX_ PerlIO *f);
29 PerlIO *(*Dup) (pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
30 /* Unix-like functions - cf sfio line disciplines */
31 SSize_t(*Read) (pTHX_ PerlIO *f, void *vbuf, Size_t count);
32 SSize_t(*Unread) (pTHX_ PerlIO *f, const void *vbuf, Size_t count);
33 SSize_t(*Write) (pTHX_ PerlIO *f, const void *vbuf, Size_t count);
34 IV (*Seek) (pTHX_ PerlIO *f, Off_t offset, int whence);
35 Off_t(*Tell) (pTHX_ PerlIO *f);
36 IV (*Close) (pTHX_ PerlIO *f);
37 /* Stdio-like buffered IO functions */
38 IV (*Flush) (pTHX_ PerlIO *f);
39 IV (*Fill) (pTHX_ PerlIO *f);
40 IV (*Eof) (pTHX_ PerlIO *f);
41 IV (*Error) (pTHX_ PerlIO *f);
42 void (*Clearerr) (pTHX_ PerlIO *f);
43 void (*Setlinebuf) (pTHX_ PerlIO *f);
44 /* Perl's snooping functions */
45 STDCHAR *(*Get_base) (pTHX_ PerlIO *f);
46 Size_t(*Get_bufsiz) (pTHX_ PerlIO *f);
47 STDCHAR *(*Get_ptr) (pTHX_ PerlIO *f);
48 SSize_t(*Get_cnt) (pTHX_ PerlIO *f);
49 void (*Set_ptrcnt) (pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
52 /*--------------------------------------------------------------------------------------*/
54 #define PERLIO_K_RAW 0x00000001
55 #define PERLIO_K_BUFFERED 0x00000002
56 #define PERLIO_K_CANCRLF 0x00000004
57 #define PERLIO_K_FASTGETS 0x00000008
58 #define PERLIO_K_DUMMY 0x00000010
59 #define PERLIO_K_UTF8 0x00008000
60 #define PERLIO_K_DESTRUCT 0x00010000
61 #define PERLIO_K_MULTIARG 0x00020000
63 /*--------------------------------------------------------------------------------------*/
65 PerlIOl *next; /* Lower layer */
66 PerlIO_funcs *tab; /* Functions for this layer */
67 IV flags; /* Various flags for state */
70 /*--------------------------------------------------------------------------------------*/
73 #define PERLIO_F_EOF 0x00000100
74 #define PERLIO_F_CANWRITE 0x00000200
75 #define PERLIO_F_CANREAD 0x00000400
76 #define PERLIO_F_ERROR 0x00000800
77 #define PERLIO_F_TRUNCATE 0x00001000
78 #define PERLIO_F_APPEND 0x00002000
79 #define PERLIO_F_CRLF 0x00004000
80 #define PERLIO_F_UTF8 0x00008000
81 #define PERLIO_F_UNBUF 0x00010000
82 #define PERLIO_F_WRBUF 0x00020000
83 #define PERLIO_F_RDBUF 0x00040000
84 #define PERLIO_F_LINEBUF 0x00080000
85 #define PERLIO_F_TEMP 0x00100000
86 #define PERLIO_F_OPEN 0x00200000
87 #define PERLIO_F_FASTGETS 0x00400000
88 #define PERLIO_F_TTY 0x00800000
90 #define PerlIOBase(f) (*(f))
91 #define PerlIOSelf(f,type) ((type *)PerlIOBase(f))
92 #define PerlIONext(f) (&(PerlIOBase(f)->next))
93 #define PerlIOValid(f) ((f) && *(f))
95 /*--------------------------------------------------------------------------------------*/
96 /* Data exports - EXT rather than extern is needed for Cygwin */
97 EXT PerlIO_funcs PerlIO_unix;
98 EXT PerlIO_funcs PerlIO_perlio;
99 EXT PerlIO_funcs PerlIO_stdio;
100 EXT PerlIO_funcs PerlIO_crlf;
101 EXT PerlIO_funcs PerlIO_utf8;
102 EXT PerlIO_funcs PerlIO_byte;
103 EXT PerlIO_funcs PerlIO_raw;
104 EXT PerlIO_funcs PerlIO_pending;
106 EXT PerlIO_funcs PerlIO_mmap;
109 EXT PerlIO_funcs PerlIO_win32;
111 extern PerlIO *PerlIO_allocate(pTHX);
112 extern SV *PerlIO_arg_fetch(PerlIO_list_t *av, IV n);
113 #define PerlIOArg PerlIO_arg_fetch(layers,n)
115 #ifdef PERLIO_USING_CRLF
116 #define PERLIO_STDTEXT "t"
118 #define PERLIO_STDTEXT ""
121 /*--------------------------------------------------------------------------------------*/
122 /* Generic, or stub layer functions */
124 extern IV PerlIOBase_fileno(pTHX_ PerlIO *f);
125 extern PerlIO *PerlIOBase_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
126 extern IV PerlIOBase_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg);
127 extern IV PerlIOBase_popped(pTHX_ PerlIO *f);
128 extern SSize_t PerlIOBase_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
129 extern SSize_t PerlIOBase_unread(pTHX_ PerlIO *f, const void *vbuf,
131 extern IV PerlIOBase_eof(pTHX_ PerlIO *f);
132 extern IV PerlIOBase_error(pTHX_ PerlIO *f);
133 extern void PerlIOBase_clearerr(pTHX_ PerlIO *f);
134 extern IV PerlIOBase_close(pTHX_ PerlIO *f);
135 extern void PerlIOBase_setlinebuf(pTHX_ PerlIO *f);
136 extern void PerlIOBase_flush_linebuf(pTHX);
138 extern IV PerlIOBase_noop_ok(pTHX_ PerlIO *f);
139 extern IV PerlIOBase_noop_fail(pTHX_ PerlIO *f);
141 /*--------------------------------------------------------------------------------------*/
142 /* perlio buffer layer
143 As this is reasonably generic its struct and "methods" are declared here
144 so they can be used to "inherit" from it.
148 struct _PerlIO base; /* Base "class" info */
149 STDCHAR *buf; /* Start of buffer */
150 STDCHAR *end; /* End of valid part of buffer */
151 STDCHAR *ptr; /* Current position in buffer */
152 Off_t posn; /* Offset of buf into the file */
153 Size_t bufsiz; /* Real size of buffer */
154 IV oneword; /* Emergency buffer */
157 extern SV *PerlIO_sv_dup(pTHX_ SV *arg, CLONE_PARAMS *param);
158 extern PerlIO *PerlIOBuf_open(pTHX_ PerlIO_funcs *self,
159 PerlIO_list_t *layers, IV n,
160 const char *mode, int fd, int imode,
161 int perm, PerlIO *old, int narg, SV **args);
162 extern IV PerlIOBuf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg);
163 extern PerlIO *PerlIOBuf_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
164 extern SSize_t PerlIOBuf_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
165 extern SSize_t PerlIOBuf_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
166 extern SSize_t PerlIOBuf_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
167 extern IV PerlIOBuf_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
168 extern Off_t PerlIOBuf_tell(pTHX_ PerlIO *f);
169 extern IV PerlIOBuf_close(pTHX_ PerlIO *f);
170 extern IV PerlIOBuf_flush(pTHX_ PerlIO *f);
171 extern IV PerlIOBuf_fill(pTHX_ PerlIO *f);
172 extern STDCHAR *PerlIOBuf_get_base(pTHX_ PerlIO *f);
173 extern Size_t PerlIOBuf_bufsiz(pTHX_ PerlIO *f);
174 extern STDCHAR *PerlIOBuf_get_ptr(pTHX_ PerlIO *f);
175 extern SSize_t PerlIOBuf_get_cnt(pTHX_ PerlIO *f);
176 extern void PerlIOBuf_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
178 extern int PerlIOUnix_oflags(const char *mode);
180 /*--------------------------------------------------------------------------------------*/
182 #endif /* _PERLIOL_H */