This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate mainline
[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;
20 IV (*Pushed) (PerlIO *f, const char *mode, SV *arg);
21 IV (*Popped) (PerlIO *f);
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);
14a5cf38 28 IV (*Fileno) (PerlIO *f);
ecdeb87c 29 PerlIO *(*Dup) (pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
14a5cf38
JH
30 /* Unix-like functions - cf sfio line disciplines */
31 SSize_t(*Read) (PerlIO *f, void *vbuf, Size_t count);
32 SSize_t(*Unread) (PerlIO *f, const void *vbuf, Size_t count);
33 SSize_t(*Write) (PerlIO *f, const void *vbuf, Size_t count);
34 IV (*Seek) (PerlIO *f, Off_t offset, int whence);
35 Off_t(*Tell) (PerlIO *f);
36 IV (*Close) (PerlIO *f);
37 /* Stdio-like buffered IO functions */
38 IV (*Flush) (PerlIO *f);
39 IV (*Fill) (PerlIO *f);
40 IV (*Eof) (PerlIO *f);
41 IV (*Error) (PerlIO *f);
42 void (*Clearerr) (PerlIO *f);
43 void (*Setlinebuf) (PerlIO *f);
44 /* Perl's snooping functions */
45 STDCHAR *(*Get_base) (PerlIO *f);
46 Size_t(*Get_bufsiz) (PerlIO *f);
47 STDCHAR *(*Get_ptr) (PerlIO *f);
48 SSize_t(*Get_cnt) (PerlIO *f);
49 void (*Set_ptrcnt) (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))
93
94/*--------------------------------------------------------------------------------------*/
26fb694e
NIS
95/* Data exports - EXT rather than extern is needed for Cygwin */
96EXT PerlIO_funcs PerlIO_unix;
97EXT PerlIO_funcs PerlIO_perlio;
98EXT PerlIO_funcs PerlIO_stdio;
99EXT PerlIO_funcs PerlIO_crlf;
100EXT PerlIO_funcs PerlIO_utf8;
101EXT PerlIO_funcs PerlIO_byte;
102EXT PerlIO_funcs PerlIO_raw;
7ea3cd40 103EXT PerlIO_funcs PerlIO_pending;
76ced9ad 104#ifdef HAS_MMAP
26fb694e 105EXT PerlIO_funcs PerlIO_mmap;
76ced9ad 106#endif
0c4128ad
NIS
107#ifdef WIN32
108EXT PerlIO_funcs PerlIO_win32;
109#endif
5f1a76d0 110extern PerlIO *PerlIO_allocate(pTHX);
14a5cf38 111extern SV *PerlIO_arg_fetch(PerlIO_list_t *av, IV n);
fcf2db38 112#define PerlIOArg PerlIO_arg_fetch(layers,n)
76ced9ad 113
35990314 114#ifdef PERLIO_USING_CRLF
f5b9d040
NIS
115#define PERLIO_STDTEXT "t"
116#else
117#define PERLIO_STDTEXT ""
118#endif
119
76ced9ad
NIS
120/*--------------------------------------------------------------------------------------*/
121/* Generic, or stub layer functions */
122
14a5cf38 123extern IV PerlIOBase_fileno(PerlIO *f);
ecdeb87c 124extern PerlIO *PerlIOBase_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
14a5cf38
JH
125extern IV PerlIOBase_pushed(PerlIO *f, const char *mode, SV *arg);
126extern IV PerlIOBase_popped(PerlIO *f);
127extern SSize_t PerlIOBase_read(PerlIO *f, void *vbuf, Size_t count);
128extern SSize_t PerlIOBase_unread(PerlIO *f, const void *vbuf,
129 Size_t count);
130extern IV PerlIOBase_eof(PerlIO *f);
131extern IV PerlIOBase_error(PerlIO *f);
132extern void PerlIOBase_clearerr(PerlIO *f);
133extern IV PerlIOBase_close(PerlIO *f);
134extern void PerlIOBase_setlinebuf(PerlIO *f);
135extern void PerlIOBase_flush_linebuf(void);
136
137extern IV PerlIOBase_noop_ok(PerlIO *f);
138extern IV PerlIOBase_noop_fail(PerlIO *f);
76ced9ad
NIS
139
140/*--------------------------------------------------------------------------------------*/
141/* perlio buffer layer
142 As this is reasonably generic its struct and "methods" are declared here
143 so they can be used to "inherit" from it.
144*/
145
14a5cf38
JH
146typedef struct {
147 struct _PerlIO base; /* Base "class" info */
148 STDCHAR *buf; /* Start of buffer */
149 STDCHAR *end; /* End of valid part of buffer */
150 STDCHAR *ptr; /* Current position in buffer */
151 Off_t posn; /* Offset of buf into the file */
152 Size_t bufsiz; /* Real size of buffer */
153 IV oneword; /* Emergency buffer */
76ced9ad
NIS
154} PerlIOBuf;
155
8cf8f3d1 156extern SV *PerlIO_sv_dup(pTHX_ SV *arg, CLONE_PARAMS *param);
14a5cf38
JH
157extern PerlIO *PerlIOBuf_open(pTHX_ PerlIO_funcs *self,
158 PerlIO_list_t *layers, IV n,
159 const char *mode, int fd, int imode,
160 int perm, PerlIO *old, int narg, SV **args);
161extern IV PerlIOBuf_pushed(PerlIO *f, const char *mode, SV *arg);
ecdeb87c 162extern PerlIO *PerlIOBuf_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
14a5cf38
JH
163extern SSize_t PerlIOBuf_read(PerlIO *f, void *vbuf, Size_t count);
164extern SSize_t PerlIOBuf_unread(PerlIO *f, const void *vbuf, Size_t count);
165extern SSize_t PerlIOBuf_write(PerlIO *f, const void *vbuf, Size_t count);
166extern IV PerlIOBuf_seek(PerlIO *f, Off_t offset, int whence);
167extern Off_t PerlIOBuf_tell(PerlIO *f);
168extern IV PerlIOBuf_close(PerlIO *f);
169extern IV PerlIOBuf_flush(PerlIO *f);
170extern IV PerlIOBuf_fill(PerlIO *f);
171extern STDCHAR *PerlIOBuf_get_base(PerlIO *f);
172extern Size_t PerlIOBuf_bufsiz(PerlIO *f);
173extern STDCHAR *PerlIOBuf_get_ptr(PerlIO *f);
174extern SSize_t PerlIOBuf_get_cnt(PerlIO *f);
175extern void PerlIOBuf_set_ptrcnt(PerlIO *f, STDCHAR * ptr, SSize_t cnt);
176
177extern int PerlIOUnix_oflags(const char *mode);
0c4128ad 178
76ced9ad
NIS
179/*--------------------------------------------------------------------------------------*/
180
14a5cf38 181#endif /* _PERLIOL_H */