This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Win32 MM test fix
[perl5.git] / perliol.h
CommitLineData
76ced9ad
NIS
1#ifndef _PERLIOL_H
2#define _PERLIOL_H
3
14a5cf38
JH
4typedef struct {
5 PerlIO_funcs *funcs;
6 SV *arg;
fcf2db38
NIS
7} PerlIO_pair_t;
8
3a1ee7e8 9struct PerlIO_list_s {
14a5cf38
JH
10 IV refcnt;
11 IV cur;
12 IV len;
13 PerlIO_pair_t *array;
3a1ee7e8 14};
fcf2db38 15
14a5cf38 16struct _PerlIO_funcs {
2dc2558e 17 Size_t fsize;
e1ec3a88 18 const char *name;
14a5cf38 19 Size_t size;
c9e984e3 20 U32 kind;
2dc2558e 21 IV (*Pushed) (pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
f62ce20a 22 IV (*Popped) (pTHX_ PerlIO *f);
14a5cf38
JH
23 PerlIO *(*Open) (pTHX_ PerlIO_funcs *tab,
24 PerlIO_list_t *layers, IV n,
25 const char *mode,
26 int fd, int imode, int perm,
27 PerlIO *old, int narg, SV **args);
86e05cf2 28 IV (*Binmode)(pTHX_ PerlIO *f);
ecdeb87c 29 SV *(*Getarg) (pTHX_ PerlIO *f, CLONE_PARAMS *param, int flags);
f62ce20a 30 IV (*Fileno) (pTHX_ PerlIO *f);
ecdeb87c 31 PerlIO *(*Dup) (pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
14a5cf38 32 /* Unix-like functions - cf sfio line disciplines */
f62ce20a
NIS
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);
94a175e1 36 IV (*Seek) (pTHX_ PerlIO *f, Off_t offset, int whence);
f62ce20a
NIS
37 Off_t(*Tell) (pTHX_ PerlIO *f);
38 IV (*Close) (pTHX_ PerlIO *f);
14a5cf38 39 /* Stdio-like buffered IO functions */
f62ce20a
NIS
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);
14a5cf38 46 /* Perl's snooping functions */
f62ce20a
NIS
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);
76ced9ad
NIS
52};
53
f5b9d040
NIS
54/*--------------------------------------------------------------------------------------*/
55/* Kind values */
5e2ab84b
NIS
56#define PERLIO_K_RAW 0x00000001
57#define PERLIO_K_BUFFERED 0x00000002
f5b9d040 58#define PERLIO_K_CANCRLF 0x00000004
5e2ab84b 59#define PERLIO_K_FASTGETS 0x00000008
dfebf958 60#define PERLIO_K_DUMMY 0x00000010
26fb694e 61#define PERLIO_K_UTF8 0x00008000
13621cfb 62#define PERLIO_K_DESTRUCT 0x00010000
7cf31beb 63#define PERLIO_K_MULTIARG 0x00020000
f5b9d040
NIS
64
65/*--------------------------------------------------------------------------------------*/
14a5cf38
JH
66struct _PerlIO {
67 PerlIOl *next; /* Lower layer */
68 PerlIO_funcs *tab; /* Functions for this layer */
4b069b44 69 U32 flags; /* Various flags for state */
76ced9ad
NIS
70};
71
72/*--------------------------------------------------------------------------------------*/
73
74/* Flag values */
5e2ab84b
NIS
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
a9c883f6 90#define PERLIO_F_TTY 0x00800000
6caa5a9c 91#define PERLIO_F_NOTREG 0x01000000
76ced9ad
NIS
92
93#define PerlIOBase(f) (*(f))
94#define PerlIOSelf(f,type) ((type *)PerlIOBase(f))
95#define PerlIONext(f) (&(PerlIOBase(f)->next))
04892f78 96#define PerlIOValid(f) ((f) && *(f))
76ced9ad
NIS
97
98/*--------------------------------------------------------------------------------------*/
27da23d5
JH
99/* Data exports - EXTCONST rather than extern is needed for Cygwin */
100#undef EXTPERLIO
101#ifdef PERLIO_FUNCS_CONST
102#define EXTPERLIO EXTCONST
103#else
104#define EXTPERLIO EXT
105#endif
106EXTPERLIO PerlIO_funcs PerlIO_unix;
107EXTPERLIO PerlIO_funcs PerlIO_perlio;
108EXTPERLIO PerlIO_funcs PerlIO_stdio;
109EXTPERLIO PerlIO_funcs PerlIO_crlf;
110EXTPERLIO PerlIO_funcs PerlIO_utf8;
111EXTPERLIO PerlIO_funcs PerlIO_byte;
112EXTPERLIO PerlIO_funcs PerlIO_raw;
113EXTPERLIO PerlIO_funcs PerlIO_pending;
76ced9ad 114#ifdef HAS_MMAP
27da23d5 115EXTPERLIO PerlIO_funcs PerlIO_mmap;
76ced9ad 116#endif
0c4128ad 117#ifdef WIN32
27da23d5 118EXTPERLIO PerlIO_funcs PerlIO_win32;
0c4128ad 119#endif
27da23d5
JH
120PERL_EXPORT_C PerlIO *PerlIO_allocate(pTHX);
121PERL_EXPORT_C SV *PerlIO_arg_fetch(PerlIO_list_t *av, IV n);
fcf2db38 122#define PerlIOArg PerlIO_arg_fetch(layers,n)
76ced9ad 123
35990314 124#ifdef PERLIO_USING_CRLF
f5b9d040
NIS
125#define PERLIO_STDTEXT "t"
126#else
127#define PERLIO_STDTEXT ""
128#endif
129
76ced9ad
NIS
130/*--------------------------------------------------------------------------------------*/
131/* Generic, or stub layer functions */
132
27da23d5
JH
133PERL_EXPORT_C IV PerlIOBase_fileno(pTHX_ PerlIO *f);
134PERL_EXPORT_C PerlIO *PerlIOBase_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
135PERL_EXPORT_C IV PerlIOBase_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
136PERL_EXPORT_C IV PerlIOBase_popped(pTHX_ PerlIO *f);
137PERL_EXPORT_C IV PerlIOBase_binmode(pTHX_ PerlIO *f);
138PERL_EXPORT_C SSize_t PerlIOBase_read(pTHX_ PerlIO *f,
139 void *vbuf, Size_t count);
140PERL_EXPORT_C SSize_t PerlIOBase_unread(pTHX_ PerlIO *f,
141 const void *vbuf, Size_t count);
142PERL_EXPORT_C IV PerlIOBase_eof(pTHX_ PerlIO *f);
143PERL_EXPORT_C IV PerlIOBase_error(pTHX_ PerlIO *f);
144PERL_EXPORT_C void PerlIOBase_clearerr(pTHX_ PerlIO *f);
145PERL_EXPORT_C IV PerlIOBase_close(pTHX_ PerlIO *f);
146PERL_EXPORT_C void PerlIOBase_setlinebuf(pTHX_ PerlIO *f);
147PERL_EXPORT_C void PerlIOBase_flush_linebuf(pTHX);
148
149PERL_EXPORT_C IV PerlIOBase_noop_ok(pTHX_ PerlIO *f);
150PERL_EXPORT_C IV PerlIOBase_noop_fail(pTHX_ PerlIO *f);
76ced9ad
NIS
151
152/*--------------------------------------------------------------------------------------*/
153/* perlio buffer layer
154 As this is reasonably generic its struct and "methods" are declared here
155 so they can be used to "inherit" from it.
156*/
157
14a5cf38
JH
158typedef struct {
159 struct _PerlIO base; /* Base "class" info */
160 STDCHAR *buf; /* Start of buffer */
161 STDCHAR *end; /* End of valid part of buffer */
162 STDCHAR *ptr; /* Current position in buffer */
163 Off_t posn; /* Offset of buf into the file */
164 Size_t bufsiz; /* Real size of buffer */
165 IV oneword; /* Emergency buffer */
76ced9ad
NIS
166} PerlIOBuf;
167
27da23d5 168PERL_EXPORT_C int PerlIO_apply_layera(pTHX_ PerlIO *f, const char *mode,
d9dac8cd 169 PerlIO_list_t *layers, IV n, IV max);
27da23d5
JH
170PERL_EXPORT_C int PerlIO_parse_layers(pTHX_ PerlIO_list_t *av, const char *names);
171PERL_EXPORT_C void PerlIO_list_free(pTHX_ PerlIO_list_t *list);
172PERL_EXPORT_C PerlIO_funcs *PerlIO_layer_fetch(pTHX_ PerlIO_list_t *av, IV n, PerlIO_funcs *def);
d9dac8cd
NIS
173
174
27da23d5
JH
175PERL_EXPORT_C SV *PerlIO_sv_dup(pTHX_ SV *arg, CLONE_PARAMS *param);
176PERL_EXPORT_C PerlIO *PerlIOBuf_open(pTHX_ PerlIO_funcs *self,
14a5cf38
JH
177 PerlIO_list_t *layers, IV n,
178 const char *mode, int fd, int imode,
179 int perm, PerlIO *old, int narg, SV **args);
27da23d5
JH
180PERL_EXPORT_C IV PerlIOBuf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
181PERL_EXPORT_C IV PerlIOBuf_popped(pTHX_ PerlIO *f);
182PERL_EXPORT_C PerlIO *PerlIOBuf_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
183PERL_EXPORT_C SSize_t PerlIOBuf_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
184PERL_EXPORT_C SSize_t PerlIOBuf_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
185PERL_EXPORT_C SSize_t PerlIOBuf_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
186PERL_EXPORT_C IV PerlIOBuf_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
187PERL_EXPORT_C Off_t PerlIOBuf_tell(pTHX_ PerlIO *f);
188PERL_EXPORT_C IV PerlIOBuf_close(pTHX_ PerlIO *f);
189PERL_EXPORT_C IV PerlIOBuf_flush(pTHX_ PerlIO *f);
190PERL_EXPORT_C IV PerlIOBuf_fill(pTHX_ PerlIO *f);
191PERL_EXPORT_C STDCHAR *PerlIOBuf_get_base(pTHX_ PerlIO *f);
192PERL_EXPORT_C Size_t PerlIOBuf_bufsiz(pTHX_ PerlIO *f);
193PERL_EXPORT_C STDCHAR *PerlIOBuf_get_ptr(pTHX_ PerlIO *f);
194PERL_EXPORT_C SSize_t PerlIOBuf_get_cnt(pTHX_ PerlIO *f);
195PERL_EXPORT_C void PerlIOBuf_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
196
197PERL_EXPORT_C int PerlIOUnix_oflags(const char *mode);
0c4128ad 198
76ced9ad
NIS
199/*--------------------------------------------------------------------------------------*/
200
14a5cf38 201#endif /* _PERLIOL_H */