Test case for #10433/#10424.
[p5sagit/p5-mst-13.2.git] / perliol.h
CommitLineData
76ced9ad 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 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 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 41/*--------------------------------------------------------------------------------------*/
42/* Kind values */
5e2ab84b 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
13621cfb 49#define PERLIO_K_DESTRUCT 0x00010000
f5b9d040 50
51/*--------------------------------------------------------------------------------------*/
76ced9ad 52struct _PerlIO
53{
54 PerlIOl * next; /* Lower layer */
55 PerlIO_funcs * tab; /* Functions for this layer */
56 IV flags; /* Various flags for state */
57};
58
59/*--------------------------------------------------------------------------------------*/
60
61/* Flag values */
5e2ab84b 62#define PERLIO_F_EOF 0x00000100
63#define PERLIO_F_CANWRITE 0x00000200
64#define PERLIO_F_CANREAD 0x00000400
65#define PERLIO_F_ERROR 0x00000800
66#define PERLIO_F_TRUNCATE 0x00001000
67#define PERLIO_F_APPEND 0x00002000
68#define PERLIO_F_CRLF 0x00004000
69#define PERLIO_F_UTF8 0x00008000
70#define PERLIO_F_UNBUF 0x00010000
71#define PERLIO_F_WRBUF 0x00020000
72#define PERLIO_F_RDBUF 0x00040000
73#define PERLIO_F_LINEBUF 0x00080000
74#define PERLIO_F_TEMP 0x00100000
75#define PERLIO_F_OPEN 0x00200000
76#define PERLIO_F_FASTGETS 0x00400000
a9c883f6 77#define PERLIO_F_TTY 0x00800000
76ced9ad 78
79#define PerlIOBase(f) (*(f))
80#define PerlIOSelf(f,type) ((type *)PerlIOBase(f))
81#define PerlIONext(f) (&(PerlIOBase(f)->next))
82
83/*--------------------------------------------------------------------------------------*/
26fb694e 84/* Data exports - EXT rather than extern is needed for Cygwin */
85EXT PerlIO_funcs PerlIO_unix;
86EXT PerlIO_funcs PerlIO_perlio;
87EXT PerlIO_funcs PerlIO_stdio;
88EXT PerlIO_funcs PerlIO_crlf;
89EXT PerlIO_funcs PerlIO_utf8;
90EXT PerlIO_funcs PerlIO_byte;
91EXT PerlIO_funcs PerlIO_raw;
7ea3cd40 92EXT PerlIO_funcs PerlIO_pending;
76ced9ad 93#ifdef HAS_MMAP
26fb694e 94EXT PerlIO_funcs PerlIO_mmap;
76ced9ad 95#endif
96
5f1a76d0 97extern PerlIO *PerlIO_allocate(pTHX);
f6c77cf1 98extern SV *PerlIO_arg_fetch(pTHX_ AV *av,IV n);
99#define PerlIOArg PerlIO_arg_fetch(aTHX_ layers,n+1)
76ced9ad 100
f5b9d040 101#if O_BINARY != O_TEXT
102#define PERLIO_STDTEXT "t"
103#else
104#define PERLIO_STDTEXT ""
105#endif
106
76ced9ad 107/*--------------------------------------------------------------------------------------*/
108/* Generic, or stub layer functions */
109
110extern IV PerlIOBase_fileno (PerlIO *f);
e3f3bf95 111extern IV PerlIOBase_pushed (PerlIO *f, const char *mode,SV *arg);
76ced9ad 112extern IV PerlIOBase_popped (PerlIO *f);
f6c77cf1 113extern SSize_t PerlIOBase_read (PerlIO *f, void *vbuf, Size_t count);
76ced9ad 114extern SSize_t PerlIOBase_unread (PerlIO *f, const void *vbuf, Size_t count);
115extern IV PerlIOBase_eof (PerlIO *f);
116extern IV PerlIOBase_error (PerlIO *f);
117extern void PerlIOBase_clearerr (PerlIO *f);
76ced9ad 118extern IV PerlIOBase_close (PerlIO *f);
119extern void PerlIOBase_setlinebuf(PerlIO *f);
a9c883f6 120extern void PerlIOBase_flush_linebuf(void);
76ced9ad 121
122extern IV PerlIOBase_noop_ok (PerlIO *f);
123extern IV PerlIOBase_noop_fail (PerlIO *f);
124
125/*--------------------------------------------------------------------------------------*/
126/* perlio buffer layer
127 As this is reasonably generic its struct and "methods" are declared here
128 so they can be used to "inherit" from it.
129*/
130
131typedef struct
132{
133 struct _PerlIO base; /* Base "class" info */
134 STDCHAR * buf; /* Start of buffer */
135 STDCHAR * end; /* End of valid part of buffer */
136 STDCHAR * ptr; /* Current position in buffer */
137 Off_t posn; /* Offset of buf into the file */
138 Size_t bufsiz; /* Real size of buffer */
139 IV oneword; /* Emergency buffer */
140} PerlIOBuf;
141
e3f3bf95 142extern 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);
143extern IV PerlIOBuf_pushed (PerlIO *f, const char *mode,SV *arg);
76ced9ad 144extern SSize_t PerlIOBuf_read (PerlIO *f, void *vbuf, Size_t count);
145extern SSize_t PerlIOBuf_unread (PerlIO *f, const void *vbuf, Size_t count);
146extern SSize_t PerlIOBuf_write (PerlIO *f, const void *vbuf, Size_t count);
147extern IV PerlIOBuf_seek (PerlIO *f, Off_t offset, int whence);
148extern Off_t PerlIOBuf_tell (PerlIO *f);
149extern IV PerlIOBuf_close (PerlIO *f);
150extern IV PerlIOBuf_flush (PerlIO *f);
151extern IV PerlIOBuf_fill (PerlIO *f);
76ced9ad 152extern STDCHAR *PerlIOBuf_get_base (PerlIO *f);
153extern Size_t PerlIOBuf_bufsiz (PerlIO *f);
154extern STDCHAR *PerlIOBuf_get_ptr (PerlIO *f);
155extern SSize_t PerlIOBuf_get_cnt (PerlIO *f);
156extern void PerlIOBuf_set_ptrcnt (PerlIO *f, STDCHAR *ptr, SSize_t cnt);
157
158/*--------------------------------------------------------------------------------------*/
159
160#endif /* _PERLIOL_H */