xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/perliol.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate #ifndef _PERLIOL_H
2*0Sstevel@tonic-gate #define _PERLIOL_H
3*0Sstevel@tonic-gate 
4*0Sstevel@tonic-gate typedef struct {
5*0Sstevel@tonic-gate     PerlIO_funcs *funcs;
6*0Sstevel@tonic-gate     SV *arg;
7*0Sstevel@tonic-gate } PerlIO_pair_t;
8*0Sstevel@tonic-gate 
9*0Sstevel@tonic-gate struct PerlIO_list_s {
10*0Sstevel@tonic-gate     IV refcnt;
11*0Sstevel@tonic-gate     IV cur;
12*0Sstevel@tonic-gate     IV len;
13*0Sstevel@tonic-gate     PerlIO_pair_t *array;
14*0Sstevel@tonic-gate };
15*0Sstevel@tonic-gate 
16*0Sstevel@tonic-gate struct _PerlIO_funcs {
17*0Sstevel@tonic-gate     Size_t fsize;
18*0Sstevel@tonic-gate     char *name;
19*0Sstevel@tonic-gate     Size_t size;
20*0Sstevel@tonic-gate     U32 kind;
21*0Sstevel@tonic-gate     IV (*Pushed) (pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
22*0Sstevel@tonic-gate     IV (*Popped) (pTHX_ PerlIO *f);
23*0Sstevel@tonic-gate     PerlIO *(*Open) (pTHX_ PerlIO_funcs *tab,
24*0Sstevel@tonic-gate 		     PerlIO_list_t *layers, IV n,
25*0Sstevel@tonic-gate 		     const char *mode,
26*0Sstevel@tonic-gate 		     int fd, int imode, int perm,
27*0Sstevel@tonic-gate 		     PerlIO *old, int narg, SV **args);
28*0Sstevel@tonic-gate     IV (*Binmode)(pTHX_ PerlIO *f);
29*0Sstevel@tonic-gate     SV *(*Getarg) (pTHX_ PerlIO *f, CLONE_PARAMS *param, int flags);
30*0Sstevel@tonic-gate     IV (*Fileno) (pTHX_ PerlIO *f);
31*0Sstevel@tonic-gate     PerlIO *(*Dup) (pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
32*0Sstevel@tonic-gate     /* Unix-like functions - cf sfio line disciplines */
33*0Sstevel@tonic-gate      SSize_t(*Read) (pTHX_ PerlIO *f, void *vbuf, Size_t count);
34*0Sstevel@tonic-gate      SSize_t(*Unread) (pTHX_ PerlIO *f, const void *vbuf, Size_t count);
35*0Sstevel@tonic-gate      SSize_t(*Write) (pTHX_ PerlIO *f, const void *vbuf, Size_t count);
36*0Sstevel@tonic-gate     IV (*Seek) (pTHX_ PerlIO *f, Off_t offset, int whence);
37*0Sstevel@tonic-gate      Off_t(*Tell) (pTHX_ PerlIO *f);
38*0Sstevel@tonic-gate     IV (*Close) (pTHX_ PerlIO *f);
39*0Sstevel@tonic-gate     /* Stdio-like buffered IO functions */
40*0Sstevel@tonic-gate     IV (*Flush) (pTHX_ PerlIO *f);
41*0Sstevel@tonic-gate     IV (*Fill) (pTHX_ PerlIO *f);
42*0Sstevel@tonic-gate     IV (*Eof) (pTHX_ PerlIO *f);
43*0Sstevel@tonic-gate     IV (*Error) (pTHX_ PerlIO *f);
44*0Sstevel@tonic-gate     void (*Clearerr) (pTHX_ PerlIO *f);
45*0Sstevel@tonic-gate     void (*Setlinebuf) (pTHX_ PerlIO *f);
46*0Sstevel@tonic-gate     /* Perl's snooping functions */
47*0Sstevel@tonic-gate     STDCHAR *(*Get_base) (pTHX_ PerlIO *f);
48*0Sstevel@tonic-gate      Size_t(*Get_bufsiz) (pTHX_ PerlIO *f);
49*0Sstevel@tonic-gate     STDCHAR *(*Get_ptr) (pTHX_ PerlIO *f);
50*0Sstevel@tonic-gate      SSize_t(*Get_cnt) (pTHX_ PerlIO *f);
51*0Sstevel@tonic-gate     void (*Set_ptrcnt) (pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
52*0Sstevel@tonic-gate };
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate /*--------------------------------------------------------------------------------------*/
55*0Sstevel@tonic-gate /* Kind values */
56*0Sstevel@tonic-gate #define PERLIO_K_RAW		0x00000001
57*0Sstevel@tonic-gate #define PERLIO_K_BUFFERED	0x00000002
58*0Sstevel@tonic-gate #define PERLIO_K_CANCRLF	0x00000004
59*0Sstevel@tonic-gate #define PERLIO_K_FASTGETS	0x00000008
60*0Sstevel@tonic-gate #define PERLIO_K_DUMMY		0x00000010
61*0Sstevel@tonic-gate #define PERLIO_K_UTF8		0x00008000
62*0Sstevel@tonic-gate #define PERLIO_K_DESTRUCT	0x00010000
63*0Sstevel@tonic-gate #define PERLIO_K_MULTIARG	0x00020000
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate /*--------------------------------------------------------------------------------------*/
66*0Sstevel@tonic-gate struct _PerlIO {
67*0Sstevel@tonic-gate     PerlIOl *next;		/* Lower layer */
68*0Sstevel@tonic-gate     PerlIO_funcs *tab;		/* Functions for this layer */
69*0Sstevel@tonic-gate     U32 flags;			/* Various flags for state */
70*0Sstevel@tonic-gate };
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate /*--------------------------------------------------------------------------------------*/
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate /* Flag values */
75*0Sstevel@tonic-gate #define PERLIO_F_EOF		0x00000100
76*0Sstevel@tonic-gate #define PERLIO_F_CANWRITE	0x00000200
77*0Sstevel@tonic-gate #define PERLIO_F_CANREAD	0x00000400
78*0Sstevel@tonic-gate #define PERLIO_F_ERROR		0x00000800
79*0Sstevel@tonic-gate #define PERLIO_F_TRUNCATE	0x00001000
80*0Sstevel@tonic-gate #define PERLIO_F_APPEND		0x00002000
81*0Sstevel@tonic-gate #define PERLIO_F_CRLF		0x00004000
82*0Sstevel@tonic-gate #define PERLIO_F_UTF8		0x00008000
83*0Sstevel@tonic-gate #define PERLIO_F_UNBUF		0x00010000
84*0Sstevel@tonic-gate #define PERLIO_F_WRBUF		0x00020000
85*0Sstevel@tonic-gate #define PERLIO_F_RDBUF		0x00040000
86*0Sstevel@tonic-gate #define PERLIO_F_LINEBUF	0x00080000
87*0Sstevel@tonic-gate #define PERLIO_F_TEMP		0x00100000
88*0Sstevel@tonic-gate #define PERLIO_F_OPEN		0x00200000
89*0Sstevel@tonic-gate #define PERLIO_F_FASTGETS	0x00400000
90*0Sstevel@tonic-gate #define PERLIO_F_TTY		0x00800000
91*0Sstevel@tonic-gate #define PERLIO_F_NOTREG         0x01000000
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate #define PerlIOBase(f)      (*(f))
94*0Sstevel@tonic-gate #define PerlIOSelf(f,type) ((type *)PerlIOBase(f))
95*0Sstevel@tonic-gate #define PerlIONext(f)      (&(PerlIOBase(f)->next))
96*0Sstevel@tonic-gate #define PerlIOValid(f)     ((f) && *(f))
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate /*--------------------------------------------------------------------------------------*/
99*0Sstevel@tonic-gate /* Data exports - EXT rather than extern is needed for Cygwin */
100*0Sstevel@tonic-gate EXT PerlIO_funcs PerlIO_unix;
101*0Sstevel@tonic-gate EXT PerlIO_funcs PerlIO_perlio;
102*0Sstevel@tonic-gate EXT PerlIO_funcs PerlIO_stdio;
103*0Sstevel@tonic-gate EXT PerlIO_funcs PerlIO_crlf;
104*0Sstevel@tonic-gate EXT PerlIO_funcs PerlIO_utf8;
105*0Sstevel@tonic-gate EXT PerlIO_funcs PerlIO_byte;
106*0Sstevel@tonic-gate EXT PerlIO_funcs PerlIO_raw;
107*0Sstevel@tonic-gate EXT PerlIO_funcs PerlIO_pending;
108*0Sstevel@tonic-gate #ifdef HAS_MMAP
109*0Sstevel@tonic-gate EXT PerlIO_funcs PerlIO_mmap;
110*0Sstevel@tonic-gate #endif
111*0Sstevel@tonic-gate #ifdef WIN32
112*0Sstevel@tonic-gate EXT PerlIO_funcs PerlIO_win32;
113*0Sstevel@tonic-gate #endif
114*0Sstevel@tonic-gate extern PerlIO *PerlIO_allocate(pTHX);
115*0Sstevel@tonic-gate extern SV *PerlIO_arg_fetch(PerlIO_list_t *av, IV n);
116*0Sstevel@tonic-gate #define PerlIOArg PerlIO_arg_fetch(layers,n)
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate #ifdef PERLIO_USING_CRLF
119*0Sstevel@tonic-gate #define PERLIO_STDTEXT "t"
120*0Sstevel@tonic-gate #else
121*0Sstevel@tonic-gate #define PERLIO_STDTEXT ""
122*0Sstevel@tonic-gate #endif
123*0Sstevel@tonic-gate 
124*0Sstevel@tonic-gate /*--------------------------------------------------------------------------------------*/
125*0Sstevel@tonic-gate /* Generic, or stub layer functions */
126*0Sstevel@tonic-gate 
127*0Sstevel@tonic-gate extern IV PerlIOBase_fileno(pTHX_ PerlIO *f);
128*0Sstevel@tonic-gate extern PerlIO *PerlIOBase_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
129*0Sstevel@tonic-gate extern IV PerlIOBase_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
130*0Sstevel@tonic-gate extern IV PerlIOBase_popped(pTHX_ PerlIO *f);
131*0Sstevel@tonic-gate extern IV PerlIOBase_binmode(pTHX_ PerlIO *f);
132*0Sstevel@tonic-gate extern SSize_t PerlIOBase_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
133*0Sstevel@tonic-gate extern SSize_t PerlIOBase_unread(pTHX_ PerlIO *f, const void *vbuf,
134*0Sstevel@tonic-gate 				 Size_t count);
135*0Sstevel@tonic-gate extern IV PerlIOBase_eof(pTHX_ PerlIO *f);
136*0Sstevel@tonic-gate extern IV PerlIOBase_error(pTHX_ PerlIO *f);
137*0Sstevel@tonic-gate extern void PerlIOBase_clearerr(pTHX_ PerlIO *f);
138*0Sstevel@tonic-gate extern IV PerlIOBase_close(pTHX_ PerlIO *f);
139*0Sstevel@tonic-gate extern void PerlIOBase_setlinebuf(pTHX_ PerlIO *f);
140*0Sstevel@tonic-gate extern void PerlIOBase_flush_linebuf(pTHX);
141*0Sstevel@tonic-gate 
142*0Sstevel@tonic-gate extern IV PerlIOBase_noop_ok(pTHX_ PerlIO *f);
143*0Sstevel@tonic-gate extern IV PerlIOBase_noop_fail(pTHX_ PerlIO *f);
144*0Sstevel@tonic-gate 
145*0Sstevel@tonic-gate /*--------------------------------------------------------------------------------------*/
146*0Sstevel@tonic-gate /* perlio buffer layer
147*0Sstevel@tonic-gate    As this is reasonably generic its struct and "methods" are declared here
148*0Sstevel@tonic-gate    so they can be used to "inherit" from it.
149*0Sstevel@tonic-gate */
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate typedef struct {
152*0Sstevel@tonic-gate     struct _PerlIO base;	/* Base "class" info */
153*0Sstevel@tonic-gate     STDCHAR *buf;		/* Start of buffer */
154*0Sstevel@tonic-gate     STDCHAR *end;		/* End of valid part of buffer */
155*0Sstevel@tonic-gate     STDCHAR *ptr;		/* Current position in buffer */
156*0Sstevel@tonic-gate     Off_t posn;			/* Offset of buf into the file */
157*0Sstevel@tonic-gate     Size_t bufsiz;		/* Real size of buffer */
158*0Sstevel@tonic-gate     IV oneword;			/* Emergency buffer */
159*0Sstevel@tonic-gate } PerlIOBuf;
160*0Sstevel@tonic-gate 
161*0Sstevel@tonic-gate extern int PerlIO_apply_layera(pTHX_ PerlIO *f, const char *mode,
162*0Sstevel@tonic-gate 		    PerlIO_list_t *layers, IV n, IV max);
163*0Sstevel@tonic-gate extern int PerlIO_parse_layers(pTHX_ PerlIO_list_t *av, const char *names);
164*0Sstevel@tonic-gate extern void PerlIO_list_free(pTHX_ PerlIO_list_t *list);
165*0Sstevel@tonic-gate extern PerlIO_funcs *PerlIO_layer_fetch(pTHX_ PerlIO_list_t *av, IV n, PerlIO_funcs *def);
166*0Sstevel@tonic-gate 
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate extern SV *PerlIO_sv_dup(pTHX_ SV *arg, CLONE_PARAMS *param);
169*0Sstevel@tonic-gate extern PerlIO *PerlIOBuf_open(pTHX_ PerlIO_funcs *self,
170*0Sstevel@tonic-gate 			      PerlIO_list_t *layers, IV n,
171*0Sstevel@tonic-gate 			      const char *mode, int fd, int imode,
172*0Sstevel@tonic-gate 			      int perm, PerlIO *old, int narg, SV **args);
173*0Sstevel@tonic-gate extern IV PerlIOBuf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab);
174*0Sstevel@tonic-gate extern IV PerlIOBuf_popped(pTHX_ PerlIO *f);
175*0Sstevel@tonic-gate extern PerlIO *PerlIOBuf_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags);
176*0Sstevel@tonic-gate extern SSize_t PerlIOBuf_read(pTHX_ PerlIO *f, void *vbuf, Size_t count);
177*0Sstevel@tonic-gate extern SSize_t PerlIOBuf_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
178*0Sstevel@tonic-gate extern SSize_t PerlIOBuf_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
179*0Sstevel@tonic-gate extern IV PerlIOBuf_seek(pTHX_ PerlIO *f, Off_t offset, int whence);
180*0Sstevel@tonic-gate extern Off_t PerlIOBuf_tell(pTHX_ PerlIO *f);
181*0Sstevel@tonic-gate extern IV PerlIOBuf_close(pTHX_ PerlIO *f);
182*0Sstevel@tonic-gate extern IV PerlIOBuf_flush(pTHX_ PerlIO *f);
183*0Sstevel@tonic-gate extern IV PerlIOBuf_fill(pTHX_ PerlIO *f);
184*0Sstevel@tonic-gate extern STDCHAR *PerlIOBuf_get_base(pTHX_ PerlIO *f);
185*0Sstevel@tonic-gate extern Size_t PerlIOBuf_bufsiz(pTHX_ PerlIO *f);
186*0Sstevel@tonic-gate extern STDCHAR *PerlIOBuf_get_ptr(pTHX_ PerlIO *f);
187*0Sstevel@tonic-gate extern SSize_t PerlIOBuf_get_cnt(pTHX_ PerlIO *f);
188*0Sstevel@tonic-gate extern void PerlIOBuf_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt);
189*0Sstevel@tonic-gate 
190*0Sstevel@tonic-gate extern int PerlIOUnix_oflags(const char *mode);
191*0Sstevel@tonic-gate 
192*0Sstevel@tonic-gate /*--------------------------------------------------------------------------------------*/
193*0Sstevel@tonic-gate 
194*0Sstevel@tonic-gate #endif				/* _PERLIOL_H */
195