This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix quote() function to escape backslashes but not minus signs
[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 */
0ea86a10
FC
70 int err; /* Saved errno value */
71#ifdef VMS
72 unsigned os_err; /* Saved vaxc$errno value */
73#elif defined (OS2)
74 unsigned long os_err;
75#elif defined (WIN32)
76 DWORD os_err; /* Saved GetLastError() value */
77#endif
16865ff7 78 PerlIOl *head; /* our ultimate parent pointer */
76ced9ad
NIS
79};
80
81/*--------------------------------------------------------------------------------------*/
82
83/* Flag values */
5e2ab84b
NIS
84#define PERLIO_F_EOF 0x00000100
85#define PERLIO_F_CANWRITE 0x00000200
86#define PERLIO_F_CANREAD 0x00000400
87#define PERLIO_F_ERROR 0x00000800
88#define PERLIO_F_TRUNCATE 0x00001000
89#define PERLIO_F_APPEND 0x00002000
90#define PERLIO_F_CRLF 0x00004000
91#define PERLIO_F_UTF8 0x00008000
92#define PERLIO_F_UNBUF 0x00010000
93#define PERLIO_F_WRBUF 0x00020000
94#define PERLIO_F_RDBUF 0x00040000
95#define PERLIO_F_LINEBUF 0x00080000
96#define PERLIO_F_TEMP 0x00100000
97#define PERLIO_F_OPEN 0x00200000
98#define PERLIO_F_FASTGETS 0x00400000
a9c883f6 99#define PERLIO_F_TTY 0x00800000
6caa5a9c 100#define PERLIO_F_NOTREG 0x01000000
abf9167d 101#define PERLIO_F_CLEARED 0x02000000 /* layer cleared but not freed */
76ced9ad
NIS
102
103#define PerlIOBase(f) (*(f))
104#define PerlIOSelf(f,type) ((type *)PerlIOBase(f))
105#define PerlIONext(f) (&(PerlIOBase(f)->next))
04892f78 106#define PerlIOValid(f) ((f) && *(f))
76ced9ad
NIS
107
108/*--------------------------------------------------------------------------------------*/
27da23d5
JH
109/* Data exports - EXTCONST rather than extern is needed for Cygwin */
110#undef EXTPERLIO
111#ifdef PERLIO_FUNCS_CONST
b5ce02ff 112#define EXTPERLIO EXTCONST
27da23d5
JH
113#else
114#define EXTPERLIO EXT
115#endif
116EXTPERLIO PerlIO_funcs PerlIO_unix;
117EXTPERLIO PerlIO_funcs PerlIO_perlio;
118EXTPERLIO PerlIO_funcs PerlIO_stdio;
119EXTPERLIO PerlIO_funcs PerlIO_crlf;
120EXTPERLIO PerlIO_funcs PerlIO_utf8;
121EXTPERLIO PerlIO_funcs PerlIO_byte;
122EXTPERLIO PerlIO_funcs PerlIO_raw;
123EXTPERLIO PerlIO_funcs PerlIO_pending;
0c4128ad 124#ifdef WIN32
27da23d5 125EXTPERLIO PerlIO_funcs PerlIO_win32;
0c4128ad 126#endif
27da23d5
JH
127PERL_EXPORT_C PerlIO *PerlIO_allocate(pTHX);
128PERL_EXPORT_C SV *PerlIO_arg_fetch(PerlIO_list_t *av, IV n);
fcf2db38 129#define PerlIOArg PerlIO_arg_fetch(layers,n)
76ced9ad 130
35990314 131#ifdef PERLIO_USING_CRLF
f5b9d040
NIS
132#define PERLIO_STDTEXT "t"
133#else
134#define PERLIO_STDTEXT ""
135#endif
136
76ced9ad 137/*--------------------------------------------------------------------------------------*/
76ced9ad
NIS
138/* perlio buffer layer
139 As this is reasonably generic its struct and "methods" are declared here
140 so they can be used to "inherit" from it.
141*/
142
14a5cf38
JH
143typedef struct {
144 struct _PerlIO base; /* Base "class" info */
145 STDCHAR *buf; /* Start of buffer */
146 STDCHAR *end; /* End of valid part of buffer */
147 STDCHAR *ptr; /* Current position in buffer */
148 Off_t posn; /* Offset of buf into the file */
149 Size_t bufsiz; /* Real size of buffer */
150 IV oneword; /* Emergency buffer */
76ced9ad
NIS
151} PerlIOBuf;
152
27da23d5 153PERL_EXPORT_C int PerlIO_apply_layera(pTHX_ PerlIO *f, const char *mode,
d9dac8cd 154 PerlIO_list_t *layers, IV n, IV max);
27da23d5 155PERL_EXPORT_C int PerlIO_parse_layers(pTHX_ PerlIO_list_t *av, const char *names);
27da23d5 156PERL_EXPORT_C PerlIO_funcs *PerlIO_layer_fetch(pTHX_ PerlIO_list_t *av, IV n, PerlIO_funcs *def);
d9dac8cd
NIS
157
158
27da23d5 159PERL_EXPORT_C SV *PerlIO_sv_dup(pTHX_ SV *arg, CLONE_PARAMS *param);
303f2dc3 160PERL_EXPORT_C void PerlIO_cleantable(pTHX_ PerlIOl **tablep);
de009b76
AL
161PERL_EXPORT_C SV * PerlIO_tab_sv(pTHX_ PerlIO_funcs *tab);
162PERL_EXPORT_C void PerlIO_default_buffer(pTHX_ PerlIO_list_t *av);
163PERL_EXPORT_C void PerlIO_stdstreams(pTHX);
164PERL_EXPORT_C int PerlIO__close(pTHX_ PerlIO *f);
165PERL_EXPORT_C PerlIO_list_t * PerlIO_resolve_layers(pTHX_ const char *layers, const char *mode, int narg, SV **args);
166PERL_EXPORT_C PerlIO_funcs * PerlIO_default_layer(pTHX_ I32 n);
167PERL_EXPORT_C PerlIO_list_t * PerlIO_default_layers(pTHX);
168PERL_EXPORT_C PerlIO * PerlIO_reopen(const char *path, const char *mode, PerlIO *f);
de009b76
AL
169
170PERL_EXPORT_C PerlIO_list_t *PerlIO_list_alloc(pTHX);
171PERL_EXPORT_C PerlIO_list_t *PerlIO_clone_list(pTHX_ PerlIO_list_t *proto, CLONE_PARAMS *param);
172PERL_EXPORT_C void PerlIO_list_free(pTHX_ PerlIO_list_t *list);
173PERL_EXPORT_C void PerlIO_list_push(pTHX_ PerlIO_list_t *list, PerlIO_funcs *funcs, SV *arg);
174PERL_EXPORT_C void PerlIO_list_free(pTHX_ PerlIO_list_t *list);
e670910b
JH
175
176/* PerlIO_teardown doesn't need exporting, but the EXTERN_C is needed
177 * for compiling as C++. Must also match with what perl.h says. */
0934c9d9 178EXTERN_C void PerlIO_teardown(void);
0c4128ad 179
76ced9ad 180/*--------------------------------------------------------------------------------------*/
de009b76
AL
181/* Generic, or stub layer functions */
182
183PERL_EXPORT_C IV PerlIOBase_binmode(pTHX_ PerlIO *f);
184PERL_EXPORT_C void PerlIOBase_clearerr(pTHX_ PerlIO *f);
185PERL_EXPORT_C IV PerlIOBase_close(pTHX_ PerlIO *f);
186PERL_EXPORT_C PerlIO * PerlIOBase_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
187PERL_EXPORT_C IV PerlIOBase_eof(pTHX_ PerlIO *f);
188PERL_EXPORT_C IV PerlIOBase_error(pTHX_ PerlIO *f);
189PERL_EXPORT_C IV PerlIOBase_fileno(pTHX_ PerlIO *f);
190PERL_EXPORT_C void PerlIOBase_flush_linebuf(pTHX);
191PERL_EXPORT_C IV PerlIOBase_noop_fail(pTHX_ PerlIO *f);
192PERL_EXPORT_C IV PerlIOBase_noop_ok(pTHX_ PerlIO *f);
193PERL_EXPORT_C IV PerlIOBase_popped(pTHX_ PerlIO *f);
194PERL_EXPORT_C IV PerlIOBase_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
81fe74fb 195PERL_EXPORT_C PerlIO * PerlIOBase_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);
de009b76
AL
196PERL_EXPORT_C SSize_t PerlIOBase_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
197PERL_EXPORT_C void PerlIOBase_setlinebuf(pTHX_ PerlIO *f);
198PERL_EXPORT_C SSize_t PerlIOBase_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
199
200/* Buf */
201PERL_EXPORT_C Size_t PerlIOBuf_bufsiz(pTHX_ PerlIO *f);
202PERL_EXPORT_C IV PerlIOBuf_close(pTHX_ PerlIO *f);
203PERL_EXPORT_C PerlIO * PerlIOBuf_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
204PERL_EXPORT_C IV PerlIOBuf_fill(pTHX_ PerlIO *f);
205PERL_EXPORT_C IV PerlIOBuf_flush(pTHX_ PerlIO *f);
206PERL_EXPORT_C STDCHAR * PerlIOBuf_get_base(pTHX_ PerlIO *f);
207PERL_EXPORT_C SSize_t PerlIOBuf_get_cnt(pTHX_ PerlIO *f);
208PERL_EXPORT_C STDCHAR * PerlIOBuf_get_ptr(pTHX_ PerlIO *f);
209PERL_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);
210PERL_EXPORT_C IV PerlIOBuf_popped(pTHX_ PerlIO *f);
211PERL_EXPORT_C IV PerlIOBuf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
212PERL_EXPORT_C SSize_t PerlIOBuf_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
213PERL_EXPORT_C IV PerlIOBuf_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
214PERL_EXPORT_C void PerlIOBuf_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
215PERL_EXPORT_C Off_t PerlIOBuf_tell(pTHX_ PerlIO *f);
216PERL_EXPORT_C SSize_t PerlIOBuf_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
217PERL_EXPORT_C SSize_t PerlIOBuf_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
218
219/* Crlf */
220PERL_EXPORT_C IV PerlIOCrlf_binmode(pTHX_ PerlIO *f);
221PERL_EXPORT_C IV PerlIOCrlf_flush(pTHX_ PerlIO *f);
222PERL_EXPORT_C SSize_t PerlIOCrlf_get_cnt(pTHX_ PerlIO *f);
223PERL_EXPORT_C IV PerlIOCrlf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
224PERL_EXPORT_C void PerlIOCrlf_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
225PERL_EXPORT_C SSize_t PerlIOCrlf_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
de009b76
AL
226PERL_EXPORT_C SSize_t PerlIOCrlf_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
227
de009b76
AL
228/* Pending */
229PERL_EXPORT_C IV PerlIOPending_close(pTHX_ PerlIO *f);
230PERL_EXPORT_C IV PerlIOPending_fill(pTHX_ PerlIO *f);
231PERL_EXPORT_C IV PerlIOPending_flush(pTHX_ PerlIO *f);
232PERL_EXPORT_C IV PerlIOPending_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
233PERL_EXPORT_C SSize_t PerlIOPending_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
234PERL_EXPORT_C IV PerlIOPending_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
235PERL_EXPORT_C void PerlIOPending_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
236
237/* Pop */
238PERL_EXPORT_C IV PerlIOPop_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
239
240/* Raw */
de009b76
AL
241PERL_EXPORT_C IV PerlIORaw_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
242
243/* Stdio */
244PERL_EXPORT_C void PerlIOStdio_clearerr(pTHX_ PerlIO *f);
245PERL_EXPORT_C IV PerlIOStdio_close(pTHX_ PerlIO *f);
246PERL_EXPORT_C PerlIO * PerlIOStdio_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
247PERL_EXPORT_C IV PerlIOStdio_eof(pTHX_ PerlIO *f);
248PERL_EXPORT_C IV PerlIOStdio_error(pTHX_ PerlIO *f);
249PERL_EXPORT_C IV PerlIOStdio_fileno(pTHX_ PerlIO *f);
15eb3045
BF
250#ifdef USE_STDIO_PTR
251PERL_EXPORT_C STDCHAR * PerlIOStdio_get_ptr(pTHX_ PerlIO *f);
252PERL_EXPORT_C SSize_t PerlIOStdio_get_cnt(pTHX_ PerlIO *f);
253PERL_EXPORT_C void PerlIOStdio_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
254#endif
de009b76
AL
255PERL_EXPORT_C IV PerlIOStdio_fill(pTHX_ PerlIO *f);
256PERL_EXPORT_C IV PerlIOStdio_flush(pTHX_ PerlIO *f);
15eb3045 257#ifdef FILE_base
de009b76 258PERL_EXPORT_C STDCHAR * PerlIOStdio_get_base(pTHX_ PerlIO *f);
15eb3045
BF
259PERL_EXPORT_C Size_t PerlIOStdio_get_bufsiz(pTHX_ PerlIO *f);
260#endif
de009b76
AL
261PERL_EXPORT_C char * PerlIOStdio_mode(const char *mode, char *tmode);
262PERL_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);
263PERL_EXPORT_C IV PerlIOStdio_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
264PERL_EXPORT_C SSize_t PerlIOStdio_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
265PERL_EXPORT_C IV PerlIOStdio_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
266PERL_EXPORT_C void PerlIOStdio_setlinebuf(pTHX_ PerlIO *f);
267PERL_EXPORT_C Off_t PerlIOStdio_tell(pTHX_ PerlIO *f);
268PERL_EXPORT_C SSize_t PerlIOStdio_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
269PERL_EXPORT_C SSize_t PerlIOStdio_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
270
271/* Unix */
272PERL_EXPORT_C IV PerlIOUnix_close(pTHX_ PerlIO *f);
273PERL_EXPORT_C PerlIO * PerlIOUnix_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
274PERL_EXPORT_C IV PerlIOUnix_fileno(pTHX_ PerlIO *f);
275PERL_EXPORT_C int PerlIOUnix_oflags(const char *mode);
276PERL_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);
277PERL_EXPORT_C IV PerlIOUnix_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
278PERL_EXPORT_C SSize_t PerlIOUnix_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
279PERL_EXPORT_C int PerlIOUnix_refcnt_dec(int fd);
280PERL_EXPORT_C void PerlIOUnix_refcnt_inc(int fd);
2e0cfa16 281PERL_EXPORT_C int PerlIOUnix_refcnt(int fd);
de009b76
AL
282PERL_EXPORT_C IV PerlIOUnix_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
283PERL_EXPORT_C Off_t PerlIOUnix_tell(pTHX_ PerlIO *f);
284PERL_EXPORT_C SSize_t PerlIOUnix_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
285
286/* Utf8 */
287PERL_EXPORT_C IV PerlIOUtf8_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
76ced9ad 288
14a5cf38 289#endif /* _PERLIOL_H */
e9a8c099
MHM
290
291/*
14d04a33 292 * ex: set ts=8 sts=4 sw=4 et:
e9a8c099 293 */