This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perlio internals re-organized.
[perl5.git] / perliol.h
CommitLineData
76ced9ad
NIS
1#ifndef _PERLIOL_H
2#define _PERLIOL_H
3
4struct _PerlIO_funcs
5{
6 char * name;
7 Size_t size;
8 IV kind;
e3f3bf95 9 IV (*Pushed)(PerlIO *f,const char *mode,SV *arg);
76ced9ad 10 IV (*Popped)(PerlIO *f);
e3f3bf95
NIS
11 PerlIO * (*Open)(pTHX_ PerlIO_funcs *tab,
12 AV *layers, IV n,
13 const char *mode,
14 int fd, int imode, int perm,
15 PerlIO *old,
16 int narg, SV **args);
17 SV * (*Getarg)(PerlIO *f);
18 IV (*Fileno)(PerlIO *f);
76ced9ad
NIS
19 /* Unix-like functions - cf sfio line disciplines */
20 SSize_t (*Read)(PerlIO *f, void *vbuf, Size_t count);
21 SSize_t (*Unread)(PerlIO *f, const void *vbuf, Size_t count);
22 SSize_t (*Write)(PerlIO *f, const void *vbuf, Size_t count);
23 IV (*Seek)(PerlIO *f, Off_t offset, int whence);
24 Off_t (*Tell)(PerlIO *f);
25 IV (*Close)(PerlIO *f);
26 /* Stdio-like buffered IO functions */
27 IV (*Flush)(PerlIO *f);
28 IV (*Fill)(PerlIO *f);
29 IV (*Eof)(PerlIO *f);
30 IV (*Error)(PerlIO *f);
31 void (*Clearerr)(PerlIO *f);
32 void (*Setlinebuf)(PerlIO *f);
33 /* Perl's snooping functions */
34 STDCHAR * (*Get_base)(PerlIO *f);
35 Size_t (*Get_bufsiz)(PerlIO *f);
36 STDCHAR * (*Get_ptr)(PerlIO *f);
37 SSize_t (*Get_cnt)(PerlIO *f);
38 void (*Set_ptrcnt)(PerlIO *f,STDCHAR *ptr,SSize_t cnt);
39};
40
f5b9d040
NIS
41/*--------------------------------------------------------------------------------------*/
42/* Kind values */
5e2ab84b
NIS
43#define PERLIO_K_RAW 0x00000001
44#define PERLIO_K_BUFFERED 0x00000002
f5b9d040 45#define PERLIO_K_CANCRLF 0x00000004
5e2ab84b 46#define PERLIO_K_FASTGETS 0x00000008
dfebf958 47#define PERLIO_K_DUMMY 0x00000010
26fb694e 48#define PERLIO_K_UTF8 0x00008000
f5b9d040
NIS
49
50/*--------------------------------------------------------------------------------------*/
76ced9ad
NIS
51struct _PerlIO
52{
53 PerlIOl * next; /* Lower layer */
54 PerlIO_funcs * tab; /* Functions for this layer */
55 IV flags; /* Various flags for state */
56};
57
58/*--------------------------------------------------------------------------------------*/
59
60/* Flag values */
5e2ab84b
NIS
61#define PERLIO_F_EOF 0x00000100
62#define PERLIO_F_CANWRITE 0x00000200
63#define PERLIO_F_CANREAD 0x00000400
64#define PERLIO_F_ERROR 0x00000800
65#define PERLIO_F_TRUNCATE 0x00001000
66#define PERLIO_F_APPEND 0x00002000
67#define PERLIO_F_CRLF 0x00004000
68#define PERLIO_F_UTF8 0x00008000
69#define PERLIO_F_UNBUF 0x00010000
70#define PERLIO_F_WRBUF 0x00020000
71#define PERLIO_F_RDBUF 0x00040000
72#define PERLIO_F_LINEBUF 0x00080000
73#define PERLIO_F_TEMP 0x00100000
74#define PERLIO_F_OPEN 0x00200000
75#define PERLIO_F_FASTGETS 0x00400000
76ced9ad
NIS
76
77#define PerlIOBase(f) (*(f))
78#define PerlIOSelf(f,type) ((type *)PerlIOBase(f))
79#define PerlIONext(f) (&(PerlIOBase(f)->next))
80
81/*--------------------------------------------------------------------------------------*/
26fb694e
NIS
82/* Data exports - EXT rather than extern is needed for Cygwin */
83EXT PerlIO_funcs PerlIO_unix;
84EXT PerlIO_funcs PerlIO_perlio;
85EXT PerlIO_funcs PerlIO_stdio;
86EXT PerlIO_funcs PerlIO_crlf;
87EXT PerlIO_funcs PerlIO_utf8;
88EXT PerlIO_funcs PerlIO_byte;
89EXT PerlIO_funcs PerlIO_raw;
7ea3cd40 90EXT PerlIO_funcs PerlIO_pending;
76ced9ad 91#ifdef HAS_MMAP
26fb694e 92EXT PerlIO_funcs PerlIO_mmap;
76ced9ad
NIS
93#endif
94
5f1a76d0 95extern PerlIO *PerlIO_allocate(pTHX);
76ced9ad 96
f5b9d040
NIS
97#if O_BINARY != O_TEXT
98#define PERLIO_STDTEXT "t"
99#else
100#define PERLIO_STDTEXT ""
101#endif
102
76ced9ad
NIS
103/*--------------------------------------------------------------------------------------*/
104/* Generic, or stub layer functions */
105
106extern IV PerlIOBase_fileno (PerlIO *f);
e3f3bf95 107extern IV PerlIOBase_pushed (PerlIO *f, const char *mode,SV *arg);
76ced9ad
NIS
108extern IV PerlIOBase_popped (PerlIO *f);
109extern SSize_t PerlIOBase_unread (PerlIO *f, const void *vbuf, Size_t count);
110extern IV PerlIOBase_eof (PerlIO *f);
111extern IV PerlIOBase_error (PerlIO *f);
112extern void PerlIOBase_clearerr (PerlIO *f);
113extern IV PerlIOBase_flush (PerlIO *f);
114extern IV PerlIOBase_fill (PerlIO *f);
115extern IV PerlIOBase_close (PerlIO *f);
116extern void PerlIOBase_setlinebuf(PerlIO *f);
117
118extern IV PerlIOBase_noop_ok (PerlIO *f);
119extern IV PerlIOBase_noop_fail (PerlIO *f);
120
121/*--------------------------------------------------------------------------------------*/
122/* perlio buffer layer
123 As this is reasonably generic its struct and "methods" are declared here
124 so they can be used to "inherit" from it.
125*/
126
127typedef struct
128{
129 struct _PerlIO base; /* Base "class" info */
130 STDCHAR * buf; /* Start of buffer */
131 STDCHAR * end; /* End of valid part of buffer */
132 STDCHAR * ptr; /* Current position in buffer */
133 Off_t posn; /* Offset of buf into the file */
134 Size_t bufsiz; /* Real size of buffer */
135 IV oneword; /* Emergency buffer */
136} PerlIOBuf;
137
e3f3bf95
NIS
138extern PerlIO * PerlIOBuf_open (pTHX_ PerlIO_funcs *self, AV *layers, IV n, const char *mode, int fd, int imode, int perm, PerlIO *old, int narg, SV **args);
139extern IV PerlIOBuf_pushed (PerlIO *f, const char *mode,SV *arg);
76ced9ad
NIS
140extern SSize_t PerlIOBuf_read (PerlIO *f, void *vbuf, Size_t count);
141extern SSize_t PerlIOBuf_unread (PerlIO *f, const void *vbuf, Size_t count);
142extern SSize_t PerlIOBuf_write (PerlIO *f, const void *vbuf, Size_t count);
143extern IV PerlIOBuf_seek (PerlIO *f, Off_t offset, int whence);
144extern Off_t PerlIOBuf_tell (PerlIO *f);
145extern IV PerlIOBuf_close (PerlIO *f);
146extern IV PerlIOBuf_flush (PerlIO *f);
147extern IV PerlIOBuf_fill (PerlIO *f);
148extern void PerlIOBuf_setlinebuf (PerlIO *f);
149extern STDCHAR *PerlIOBuf_get_base (PerlIO *f);
150extern Size_t PerlIOBuf_bufsiz (PerlIO *f);
151extern STDCHAR *PerlIOBuf_get_ptr (PerlIO *f);
152extern SSize_t PerlIOBuf_get_cnt (PerlIO *f);
153extern void PerlIOBuf_set_ptrcnt (PerlIO *f, STDCHAR *ptr, SSize_t cnt);
154
155/*--------------------------------------------------------------------------------------*/
156
157#endif /* _PERLIOL_H */