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