This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Implement flush of linebuffered streams on read of a tty.
[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
13621cfb 49#define PERLIO_K_DESTRUCT 0x00010000
f5b9d040
NIS
50
51/*--------------------------------------------------------------------------------------*/
76ced9ad
NIS
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
NIS
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
NIS
78
79#define PerlIOBase(f) (*(f))
80#define PerlIOSelf(f,type) ((type *)PerlIOBase(f))
81#define PerlIONext(f) (&(PerlIOBase(f)->next))
82
83/*--------------------------------------------------------------------------------------*/
26fb694e
NIS
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
NIS
95#endif
96
5f1a76d0 97extern PerlIO *PerlIO_allocate(pTHX);
f6c77cf1
NIS
98extern SV *PerlIO_arg_fetch(pTHX_ AV *av,IV n);
99#define PerlIOArg PerlIO_arg_fetch(aTHX_ layers,n+1)
76ced9ad 100
f5b9d040
NIS
101#if O_BINARY != O_TEXT
102#define PERLIO_STDTEXT "t"
103#else
104#define PERLIO_STDTEXT ""
105#endif
106
76ced9ad
NIS
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
NIS
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);
118extern IV PerlIOBase_flush (PerlIO *f);
119extern IV PerlIOBase_fill (PerlIO *f);
120extern IV PerlIOBase_close (PerlIO *f);
121extern void PerlIOBase_setlinebuf(PerlIO *f);
a9c883f6 122extern void PerlIOBase_flush_linebuf(void);
76ced9ad
NIS
123
124extern IV PerlIOBase_noop_ok (PerlIO *f);
125extern IV PerlIOBase_noop_fail (PerlIO *f);
126
127/*--------------------------------------------------------------------------------------*/
128/* perlio buffer layer
129 As this is reasonably generic its struct and "methods" are declared here
130 so they can be used to "inherit" from it.
131*/
132
133typedef struct
134{
135 struct _PerlIO base; /* Base "class" info */
136 STDCHAR * buf; /* Start of buffer */
137 STDCHAR * end; /* End of valid part of buffer */
138 STDCHAR * ptr; /* Current position in buffer */
139 Off_t posn; /* Offset of buf into the file */
140 Size_t bufsiz; /* Real size of buffer */
141 IV oneword; /* Emergency buffer */
142} PerlIOBuf;
143
e3f3bf95
NIS
144extern 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);
145extern IV PerlIOBuf_pushed (PerlIO *f, const char *mode,SV *arg);
76ced9ad
NIS
146extern SSize_t PerlIOBuf_read (PerlIO *f, void *vbuf, Size_t count);
147extern SSize_t PerlIOBuf_unread (PerlIO *f, const void *vbuf, Size_t count);
148extern SSize_t PerlIOBuf_write (PerlIO *f, const void *vbuf, Size_t count);
149extern IV PerlIOBuf_seek (PerlIO *f, Off_t offset, int whence);
150extern Off_t PerlIOBuf_tell (PerlIO *f);
151extern IV PerlIOBuf_close (PerlIO *f);
152extern IV PerlIOBuf_flush (PerlIO *f);
153extern IV PerlIOBuf_fill (PerlIO *f);
76ced9ad
NIS
154extern STDCHAR *PerlIOBuf_get_base (PerlIO *f);
155extern Size_t PerlIOBuf_bufsiz (PerlIO *f);
156extern STDCHAR *PerlIOBuf_get_ptr (PerlIO *f);
157extern SSize_t PerlIOBuf_get_cnt (PerlIO *f);
158extern void PerlIOBuf_set_ptrcnt (PerlIO *f, STDCHAR *ptr, SSize_t cnt);
159
160/*--------------------------------------------------------------------------------------*/
161
162#endif /* _PERLIOL_H */