This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Revert "Introduce a "declaration after statement" into inline.h"
[perl5.git] / perlio.h
1 /*    perlio.h
2  *
3  *    Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003,
4  *    2004, 2005, 2006, 2007, by Larry Wall and others
5  *
6  *    You may distribute under the terms of either the GNU General Public
7  *    License or the Artistic License, as specified in the README file.
8  *
9  */
10
11 #ifndef PERLIO_H_
12 #define PERLIO_H_
13 /*
14   Interface for perl to IO functions.
15   There is a hierarchy of Configure determined #define controls:
16    USE_STDIO   - No longer available via Configure.  Formerly forced
17                  PerlIO_xxx() to be #define-d onto stdio functions.
18                  Now generates compile-time error.
19
20    USE_PERLIO  - The primary Configure variable that enables PerlIO.
21                  PerlIO_xxx() are real functions
22                  defined in perlio.c which implement extra functionality
23                  required for utf8 support.
24
25 */
26
27 #ifndef USE_PERLIO
28 # define USE_STDIO
29 #endif
30
31 #ifdef USE_STDIO
32 #  error "stdio is no longer supported as the default base layer -- use perlio."
33 #endif
34
35 /* --------------------  End of Configure controls ---------------------------- */
36
37 /*
38  * Although we may not want stdio to be used including <stdio.h> here
39  * avoids issues where stdio.h has strange side effects
40  */
41 #include <stdio.h>
42
43 #if defined(USE_64_BIT_STDIO) && defined(HAS_FTELLO) && !defined(USE_FTELL64)
44 #define ftell ftello
45 #endif
46
47 #if defined(USE_64_BIT_STDIO) && defined(HAS_FSEEKO) && !defined(USE_FSEEK64)
48 #define fseek fseeko
49 #endif
50
51 /* BS2000 includes are sometimes a bit non standard :-( */
52 #if defined(POSIX_BC) && defined(O_BINARY) && !defined(O_TEXT)
53 #undef O_BINARY
54 #endif
55
56 #ifndef PerlIO
57 /* ----------- PerlIO implementation ---------- */
58 /* PerlIO not #define-d to something else - define the implementation */
59
60 typedef struct _PerlIO PerlIOl;
61 typedef struct _PerlIO_funcs PerlIO_funcs;
62 typedef PerlIOl *PerlIO;
63 #define PerlIO PerlIO
64 #define PERLIO_LAYERS 1
65
66 #define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs
67 #define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs)
68
69 PERL_CALLCONV void PerlIO_define_layer(pTHX_ PerlIO_funcs *tab);
70 PERL_CALLCONV PerlIO_funcs *PerlIO_find_layer(pTHX_ const char *name,
71                                               STRLEN len,
72                                               int load);
73 PERL_CALLCONV PerlIO *PerlIO_push(pTHX_ PerlIO *f, PERLIO_FUNCS_DECL(*tab),
74                                   const char *mode, SV *arg);
75 PERL_CALLCONV void PerlIO_pop(pTHX_ PerlIO *f);
76 PERL_CALLCONV AV* PerlIO_get_layers(pTHX_ PerlIO *f);
77 PERL_CALLCONV void PerlIO_clone(pTHX_ PerlInterpreter *proto,
78                                 CLONE_PARAMS *param);
79
80 #endif                          /* PerlIO */
81
82 /* ----------- End of implementation choices  ---------- */
83
84 /* We now need to determine  what happens if source trys to use stdio.
85  * There are three cases based on PERLIO_NOT_STDIO which XS code
86  * can set how it wants.
87  */
88
89 #ifdef PERL_CORE
90 /* Make a choice for perl core code
91    - currently this is set to try and catch lingering raw stdio calls.
92      This is a known issue with some non UNIX ports which still use
93      "native" stdio features.
94 */
95 #  ifndef PERLIO_NOT_STDIO
96 #    define PERLIO_NOT_STDIO 1
97 #  endif
98 #else
99 #  ifndef PERLIO_NOT_STDIO
100 #    define PERLIO_NOT_STDIO 0
101 #  endif
102 #endif
103
104 #ifdef PERLIO_NOT_STDIO
105 #if PERLIO_NOT_STDIO
106 /*
107  * PERLIO_NOT_STDIO #define'd as 1
108  * Case 1: Strong denial of stdio - make all stdio calls (we can think of) errors
109  */
110 #include "nostdio.h"
111 #else                           /* if PERLIO_NOT_STDIO */
112 /*
113  * PERLIO_NOT_STDIO #define'd as 0
114  * Case 2: Declares that both PerlIO and stdio can be used
115  */
116 #endif                          /* if PERLIO_NOT_STDIO */
117 #else                           /* ifdef PERLIO_NOT_STDIO */
118 /*
119  * PERLIO_NOT_STDIO not defined
120  * Case 3: Try and fake stdio calls as PerlIO calls
121  */
122 #include "fakesdio.h"
123 #endif                          /* ifndef PERLIO_NOT_STDIO */
124
125 /* ----------- fill in things that have not got #define'd  ---------- */
126
127 #ifndef Fpos_t
128 #define Fpos_t Off_t
129 #endif
130
131 #ifndef EOF
132 #define EOF (-1)
133 #endif
134
135 /* This is to catch case with no stdio */
136 #ifndef BUFSIZ
137 #define BUFSIZ 1024
138 #endif
139
140 /* The default buffer size for the perlio buffering layer */
141 #ifndef PERLIOBUF_DEFAULT_BUFSIZ
142 #define PERLIOBUF_DEFAULT_BUFSIZ (BUFSIZ > 8192 ? BUFSIZ : 8192)
143 #endif
144
145 #ifndef SEEK_SET
146 #define SEEK_SET 0
147 #endif
148
149 #ifndef SEEK_CUR
150 #define SEEK_CUR 1
151 #endif
152
153 #ifndef SEEK_END
154 #define SEEK_END 2
155 #endif
156
157 #define PERLIO_DUP_CLONE        1
158 #define PERLIO_DUP_FD           2
159
160 /* --------------------- Now prototypes for functions --------------- */
161
162 START_EXTERN_C
163 #ifndef __attribute__format__
164 #  ifdef HASATTRIBUTE_FORMAT
165 #    define __attribute__format__(x,y,z) __attribute__((format(x,y,z)))
166 #  else
167 #    define __attribute__format__(x,y,z)
168 #  endif
169 #endif
170 #ifndef PerlIO_init
171 PERL_CALLCONV void PerlIO_init(pTHX);
172 #endif
173 #ifndef PerlIO_stdoutf
174 PERL_CALLCONV int PerlIO_stdoutf(const char *, ...)
175     __attribute__format__(__printf__, 1, 2);
176 #endif
177 #ifndef PerlIO_puts
178 PERL_CALLCONV int PerlIO_puts(PerlIO *, const char *);
179 #endif
180 #ifndef PerlIO_open
181 PERL_CALLCONV PerlIO *PerlIO_open(const char *, const char *);
182 #endif
183 #ifndef PerlIO_openn
184 PERL_CALLCONV PerlIO *PerlIO_openn(pTHX_ const char *layers, const char *mode,
185                                    int fd, int imode, int perm, PerlIO *old,
186                                    int narg, SV **arg);
187 #endif
188 #ifndef PerlIO_eof
189 PERL_CALLCONV int PerlIO_eof(PerlIO *);
190 #endif
191 #ifndef PerlIO_error
192 PERL_CALLCONV int PerlIO_error(PerlIO *);
193 #endif
194 #ifndef PerlIO_clearerr
195 PERL_CALLCONV void PerlIO_clearerr(PerlIO *);
196 #endif
197 #ifndef PerlIO_getc
198 PERL_CALLCONV int PerlIO_getc(PerlIO *);
199 #endif
200 #ifndef PerlIO_putc
201 PERL_CALLCONV int PerlIO_putc(PerlIO *, int);
202 #endif
203 #ifndef PerlIO_ungetc
204 PERL_CALLCONV int PerlIO_ungetc(PerlIO *, int);
205 #endif
206 #ifndef PerlIO_fdopen
207 PERL_CALLCONV PerlIO *PerlIO_fdopen(int, const char *);
208 #endif
209 #ifndef PerlIO_importFILE
210 PERL_CALLCONV PerlIO *PerlIO_importFILE(FILE *, const char *);
211 #endif
212 #ifndef PerlIO_exportFILE
213 PERL_CALLCONV FILE *PerlIO_exportFILE(PerlIO *, const char *);
214 #endif
215 #ifndef PerlIO_findFILE
216 PERL_CALLCONV FILE *PerlIO_findFILE(PerlIO *);
217 #endif
218 #ifndef PerlIO_releaseFILE
219 PERL_CALLCONV void PerlIO_releaseFILE(PerlIO *, FILE *);
220 #endif
221 #ifndef PerlIO_read
222 PERL_CALLCONV SSize_t PerlIO_read(PerlIO *, void *, Size_t);
223 #endif
224 #ifndef PerlIO_unread
225 PERL_CALLCONV SSize_t PerlIO_unread(PerlIO *, const void *, Size_t);
226 #endif
227 #ifndef PerlIO_write
228 PERL_CALLCONV SSize_t PerlIO_write(PerlIO *, const void *, Size_t);
229 #endif
230 #ifndef PerlIO_setlinebuf
231 PERL_CALLCONV void PerlIO_setlinebuf(PerlIO *);
232 #endif
233 #ifndef PerlIO_printf
234 PERL_CALLCONV int PerlIO_printf(PerlIO *, const char *, ...)
235     __attribute__format__(__printf__, 2, 3);
236 #endif
237 #ifndef PerlIO_vprintf
238 PERL_CALLCONV int PerlIO_vprintf(PerlIO *, const char *, va_list);
239 #endif
240 #ifndef PerlIO_tell
241 PERL_CALLCONV Off_t PerlIO_tell(PerlIO *);
242 #endif
243 #ifndef PerlIO_seek
244 PERL_CALLCONV int PerlIO_seek(PerlIO *, Off_t, int);
245 #endif
246 #ifndef PerlIO_rewind
247 PERL_CALLCONV void PerlIO_rewind(PerlIO *);
248 #endif
249 #ifndef PerlIO_has_base
250 PERL_CALLCONV int PerlIO_has_base(PerlIO *);
251 #endif
252 #ifndef PerlIO_has_cntptr
253 PERL_CALLCONV int PerlIO_has_cntptr(PerlIO *);
254 #endif
255 #ifndef PerlIO_fast_gets
256 PERL_CALLCONV int PerlIO_fast_gets(PerlIO *);
257 #endif
258 #ifndef PerlIO_canset_cnt
259 PERL_CALLCONV int PerlIO_canset_cnt(PerlIO *);
260 #endif
261 #ifndef PerlIO_get_ptr
262 PERL_CALLCONV STDCHAR *PerlIO_get_ptr(PerlIO *);
263 #endif
264 #ifndef PerlIO_get_cnt
265 PERL_CALLCONV SSize_t PerlIO_get_cnt(PerlIO *);
266 #endif
267 #ifndef PerlIO_set_cnt
268 PERL_CALLCONV void PerlIO_set_cnt(PerlIO *, SSize_t);
269 #endif
270 #ifndef PerlIO_set_ptrcnt
271 PERL_CALLCONV void PerlIO_set_ptrcnt(PerlIO *, STDCHAR *, SSize_t);
272 #endif
273 #ifndef PerlIO_get_base
274 PERL_CALLCONV STDCHAR *PerlIO_get_base(PerlIO *);
275 #endif
276 #ifndef PerlIO_get_bufsiz
277 PERL_CALLCONV SSize_t PerlIO_get_bufsiz(PerlIO *);
278 #endif
279 #ifndef PerlIO_tmpfile
280 PERL_CALLCONV PerlIO *PerlIO_tmpfile(void);
281 #endif
282 #ifndef PerlIO_tmpfile_flags
283 PERL_CALLCONV PerlIO *PerlIO_tmpfile_flags(int flags);
284 #endif
285 #ifndef PerlIO_stdin
286 PERL_CALLCONV PerlIO *PerlIO_stdin(void);
287 #endif
288 #ifndef PerlIO_stdout
289 PERL_CALLCONV PerlIO *PerlIO_stdout(void);
290 #endif
291 #ifndef PerlIO_stderr
292 PERL_CALLCONV PerlIO *PerlIO_stderr(void);
293 #endif
294 #ifndef PerlIO_getpos
295 PERL_CALLCONV int PerlIO_getpos(PerlIO *, SV *);
296 #endif
297 #ifndef PerlIO_setpos
298 PERL_CALLCONV int PerlIO_setpos(PerlIO *, SV *);
299 #endif
300 #ifndef PerlIO_fdupopen
301 PERL_CALLCONV PerlIO *PerlIO_fdupopen(pTHX_ PerlIO *, CLONE_PARAMS *, int);
302 #endif
303 #if !defined(PerlIO_modestr)
304 PERL_CALLCONV char *PerlIO_modestr(PerlIO *, char *buf);
305 #endif
306 #ifndef PerlIO_isutf8
307 PERL_CALLCONV int PerlIO_isutf8(PerlIO *);
308 #endif
309 #ifndef PerlIO_apply_layers
310 PERL_CALLCONV int PerlIO_apply_layers(pTHX_ PerlIO *f, const char *mode,
311                                       const char *names);
312 #endif
313 #ifndef PerlIO_binmode
314 PERL_CALLCONV int PerlIO_binmode(pTHX_ PerlIO *f, int iotype, int omode,
315                                  const char *names);
316 #endif
317 #ifndef PerlIO_getname
318 PERL_CALLCONV char *PerlIO_getname(PerlIO *, char *);
319 #endif
320
321 PERL_CALLCONV void PerlIO_destruct(pTHX);
322
323 PERL_CALLCONV int PerlIO_intmode2str(int rawmode, char *mode, int *writing);
324
325 #ifdef PERLIO_LAYERS
326 PERL_CALLCONV void PerlIO_cleanup(pTHX);
327
328 PERL_CALLCONV void PerlIO_debug(const char *fmt, ...)
329     __attribute__format__(__printf__, 1, 2);
330 typedef struct PerlIO_list_s PerlIO_list_t;
331
332 #endif
333
334 END_EXTERN_C
335 #endif                          /* PERLIO_H_ */
336
337 /*
338  * ex: set ts=8 sts=4 sw=4 et:
339  */