This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Document the tied/magical/shared array/hash non-autovivifying bug.
[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
JH
16struct _PerlIO_funcs {
17 char *name;
18 Size_t size;
19 IV kind;
f62ce20a
NIS
20 IV (*Pushed) (pTHX_ PerlIO *f, const char *mode, SV *arg);
21 IV (*Popped) (pTHX_ PerlIO *f);
14a5cf38
JH
22 PerlIO *(*Open) (pTHX_ PerlIO_funcs *tab,
23 PerlIO_list_t *layers, IV n,
24 const char *mode,
25 int fd, int imode, int perm,
26 PerlIO *old, int narg, SV **args);
ecdeb87c 27 SV *(*Getarg) (pTHX_ PerlIO *f, CLONE_PARAMS *param, int flags);
f62ce20a 28 IV (*Fileno) (pTHX_ PerlIO *f);
ecdeb87c 29 PerlIO *(*Dup) (pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
14a5cf38 30 /* Unix-like functions - cf sfio line disciplines */
f62ce20a
NIS
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);
14a5cf38 37 /* Stdio-like buffered IO functions */
f62ce20a
NIS
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);
14a5cf38 44 /* Perl's snooping functions */
f62ce20a
NIS
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);
76ced9ad
NIS
50};
51
f5b9d040
NIS
52/*--------------------------------------------------------------------------------------*/
53/* Kind values */
5e2ab84b
NIS
54#define PERLIO_K_RAW 0x00000001
55#define PERLIO_K_BUFFERED 0x00000002
f5b9d040 56#define PERLIO_K_CANCRLF 0x00000004
5e2ab84b 57#define PERLIO_K_FASTGETS 0x00000008
dfebf958 58#define PERLIO_K_DUMMY 0x00000010
26fb694e 59#define PERLIO_K_UTF8 0x00008000
13621cfb 60#define PERLIO_K_DESTRUCT 0x00010000
7cf31beb 61#define PERLIO_K_MULTIARG 0x00020000
f5b9d040
NIS
62
63/*--------------------------------------------------------------------------------------*/
14a5cf38
JH
64struct _PerlIO {
65 PerlIOl *next; /* Lower layer */
66 PerlIO_funcs *tab; /* Functions for this layer */
67 IV flags; /* Various flags for state */
76ced9ad
NIS
68};
69
70/*--------------------------------------------------------------------------------------*/
71
72/* Flag values */
5e2ab84b
NIS
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
a9c883f6 88#define PERLIO_F_TTY 0x00800000
76ced9ad
NIS
89
90#define PerlIOBase(f) (*(f))
91#define PerlIOSelf(f,type) ((type *)PerlIOBase(f))
92#define PerlIONext(f) (&(PerlIOBase(f)->next))
04892f78 93#define PerlIOValid(f) ((f) && *(f))
76ced9ad
NIS
94
95/*--------------------------------------------------------------------------------------*/
26fb694e
NIS
96/* Data exports - EXT rather than extern is needed for Cygwin */
97EXT PerlIO_funcs PerlIO_unix;
98EXT PerlIO_funcs PerlIO_perlio;
99EXT PerlIO_funcs PerlIO_stdio;
100EXT PerlIO_funcs PerlIO_crlf;
101EXT PerlIO_funcs PerlIO_utf8;
102EXT PerlIO_funcs PerlIO_byte;
103EXT PerlIO_funcs PerlIO_raw;
7ea3cd40 104EXT PerlIO_funcs PerlIO_pending;
76ced9ad 105#ifdef HAS_MMAP
26fb694e 106EXT PerlIO_funcs PerlIO_mmap;
76ced9ad 107#endif
0c4128ad
NIS
108#ifdef WIN32
109EXT PerlIO_funcs PerlIO_win32;
110#endif
5f1a76d0 111extern PerlIO *PerlIO_allocate(pTHX);
14a5cf38 112extern SV *PerlIO_arg_fetch(PerlIO_list_t *av, IV n);
fcf2db38 113#define PerlIOArg PerlIO_arg_fetch(layers,n)
76ced9ad 114
35990314 115#ifdef PERLIO_USING_CRLF
f5b9d040
NIS
116#define PERLIO_STDTEXT "t"
117#else
118#define PERLIO_STDTEXT ""
119#endif
120
76ced9ad
NIS
121/*--------------------------------------------------------------------------------------*/
122/* Generic, or stub layer functions */
123
f62ce20a 124extern IV PerlIOBase_fileno(pTHX_ PerlIO *f);
ecdeb87c 125extern PerlIO *PerlIOBase_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
f62ce20a
NIS
126extern IV PerlIOBase_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg);
127extern IV PerlIOBase_popped(pTHX_ PerlIO *f);
128extern SSize_t PerlIOBase_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
129extern SSize_t PerlIOBase_unread(pTHX_ PerlIO *f, const void *vbuf,
14a5cf38 130 Size_t count);
f62ce20a
NIS
131extern IV PerlIOBase_eof(pTHX_ PerlIO *f);
132extern IV PerlIOBase_error(pTHX_ PerlIO *f);
133extern void PerlIOBase_clearerr(pTHX_ PerlIO *f);
134extern IV PerlIOBase_close(pTHX_ PerlIO *f);
135extern void PerlIOBase_setlinebuf(pTHX_ PerlIO *f);
136extern void PerlIOBase_flush_linebuf(pTHX);
14a5cf38 137
f62ce20a
NIS
138extern IV PerlIOBase_noop_ok(pTHX_ PerlIO *f);
139extern IV PerlIOBase_noop_fail(pTHX_ PerlIO *f);
76ced9ad
NIS
140
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.
145*/
146
14a5cf38
JH
147typedef struct {
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 */
76ced9ad
NIS
155} PerlIOBuf;
156
d9dac8cd
NIS
157extern int PerlIO_apply_layera(pTHX_ PerlIO *f, const char *mode,
158 PerlIO_list_t *layers, IV n, IV max);
159extern int PerlIO_parse_layers(pTHX_ PerlIO_list_t *av, const char *names);
160extern void PerlIO_list_free(pTHX_ PerlIO_list_t *list);
161extern PerlIO_funcs *PerlIO_layer_fetch(pTHX_ PerlIO_list_t *av, IV n, PerlIO_funcs *def);
162
163
8cf8f3d1 164extern SV *PerlIO_sv_dup(pTHX_ SV *arg, CLONE_PARAMS *param);
14a5cf38
JH
165extern PerlIO *PerlIOBuf_open(pTHX_ PerlIO_funcs *self,
166 PerlIO_list_t *layers, IV n,
167 const char *mode, int fd, int imode,
168 int perm, PerlIO *old, int narg, SV **args);
f62ce20a 169extern IV PerlIOBuf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg);
44798d05 170extern IV PerlIOBuf_popped(pTHX_ PerlIO *f);
ecdeb87c 171extern PerlIO *PerlIOBuf_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
f62ce20a
NIS
172extern SSize_t PerlIOBuf_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
173extern SSize_t PerlIOBuf_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
174extern SSize_t PerlIOBuf_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
175extern IV PerlIOBuf_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
176extern Off_t PerlIOBuf_tell(pTHX_ PerlIO *f);
177extern IV PerlIOBuf_close(pTHX_ PerlIO *f);
178extern IV PerlIOBuf_flush(pTHX_ PerlIO *f);
179extern IV PerlIOBuf_fill(pTHX_ PerlIO *f);
180extern STDCHAR *PerlIOBuf_get_base(pTHX_ PerlIO *f);
181extern Size_t PerlIOBuf_bufsiz(pTHX_ PerlIO *f);
182extern STDCHAR *PerlIOBuf_get_ptr(pTHX_ PerlIO *f);
183extern SSize_t PerlIOBuf_get_cnt(pTHX_ PerlIO *f);
184extern void PerlIOBuf_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
14a5cf38
JH
185
186extern int PerlIOUnix_oflags(const char *mode);
0c4128ad 187
76ced9ad
NIS
188/*--------------------------------------------------------------------------------------*/
189
14a5cf38 190#endif /* _PERLIOL_H */