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