3 * Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003,
4 * 2004, 2005, 2006, 2007, by Larry Wall and others
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.
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.
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.
32 # error "stdio is no longer supported as the default base layer -- use perlio."
35 /* -------------------- End of Configure controls ---------------------------- */
38 * Although we may not want stdio to be used including <stdio.h> here
39 * avoids issues where stdio.h has strange side effects
43 #if defined(USE_64_BIT_STDIO) && defined(HAS_FTELLO) && !defined(USE_FTELL64)
47 #if defined(USE_64_BIT_STDIO) && defined(HAS_FSEEKO) && !defined(USE_FSEEK64)
51 /* BS2000 includes are sometimes a bit non standard :-( */
52 #if defined(POSIX_BC) && defined(O_BINARY) && !defined(O_TEXT)
57 /* ----------- PerlIO implementation ---------- */
58 /* PerlIO not #define-d to something else - define the implementation */
60 typedef struct _PerlIO PerlIOl;
61 typedef struct _PerlIO_funcs PerlIO_funcs;
62 typedef PerlIOl *PerlIO;
64 #define PERLIO_LAYERS 1
67 =for apidoc_section $io
68 =for apidoc Amu||PERLIO_FUNCS_DECL|PerlIO * ftab
69 Declare C<ftab> to be a PerlIO function table, that is, of type
72 =for apidoc Ay|PerlIO_funcs *|PERLIO_FUNCS_CAST|PerlIO * func
73 Cast the pointer C<func> to be of type S<C<PerlIO_funcs *>>.
77 #define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs
78 #define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs)
80 PERL_CALLCONV void PerlIO_define_layer(pTHX_ PerlIO_funcs *tab);
81 PERL_CALLCONV PerlIO_funcs *PerlIO_find_layer(pTHX_ const char *name,
84 PERL_CALLCONV PerlIO *PerlIO_push(pTHX_ PerlIO *f, PERLIO_FUNCS_DECL(*tab),
85 const char *mode, SV *arg);
86 PERL_CALLCONV void PerlIO_pop(pTHX_ PerlIO *f);
87 PERL_CALLCONV AV* PerlIO_get_layers(pTHX_ PerlIO *f);
88 PERL_CALLCONV void PerlIO_clone(pTHX_ PerlInterpreter *proto,
93 /* ----------- End of implementation choices ---------- */
95 /* We now need to determine what happens if source trys to use stdio.
96 * There are three cases based on PERLIO_NOT_STDIO which XS code
97 * can set how it wants.
101 /* Make a choice for perl core code
102 - currently this is set to try and catch lingering raw stdio calls.
103 This is a known issue with some non UNIX ports which still use
104 "native" stdio features.
106 # ifndef PERLIO_NOT_STDIO
107 # define PERLIO_NOT_STDIO 1
110 # ifndef PERLIO_NOT_STDIO
111 # define PERLIO_NOT_STDIO 0
115 #ifdef PERLIO_NOT_STDIO
118 * PERLIO_NOT_STDIO #define'd as 1
119 * Case 1: Strong denial of stdio - make all stdio calls (we can think of) errors
122 #else /* if PERLIO_NOT_STDIO */
124 * PERLIO_NOT_STDIO #define'd as 0
125 * Case 2: Declares that both PerlIO and stdio can be used
127 #endif /* if PERLIO_NOT_STDIO */
128 #else /* ifdef PERLIO_NOT_STDIO */
130 * PERLIO_NOT_STDIO not defined
131 * Case 3: Try and fake stdio calls as PerlIO calls
133 #include "fakesdio.h"
134 #endif /* ifndef PERLIO_NOT_STDIO */
136 /* ----------- fill in things that have not got #define'd ---------- */
146 /* This is to catch case with no stdio */
151 /* The default buffer size for the perlio buffering layer */
152 #ifndef PERLIOBUF_DEFAULT_BUFSIZ
153 #define PERLIOBUF_DEFAULT_BUFSIZ (BUFSIZ > 8192 ? BUFSIZ : 8192)
168 #define PERLIO_DUP_CLONE 1
169 #define PERLIO_DUP_FD 2
171 /* --------------------- Now prototypes for functions --------------- */
174 #ifndef __attribute__format__
175 # ifdef HASATTRIBUTE_FORMAT
176 # define __attribute__format__(x,y,z) __attribute__((format(x,y,z)))
178 # define __attribute__format__(x,y,z)
182 PERL_CALLCONV void PerlIO_init(pTHX);
184 #ifndef PerlIO_stdoutf
185 PERL_CALLCONV int PerlIO_stdoutf(const char *, ...)
186 __attribute__format__(__printf__, 1, 2);
189 PERL_CALLCONV int PerlIO_puts(PerlIO *, const char *);
192 PERL_CALLCONV PerlIO *PerlIO_open(const char *, const char *);
195 PERL_CALLCONV PerlIO *PerlIO_openn(pTHX_ const char *layers, const char *mode,
196 int fd, int imode, int perm, PerlIO *old,
200 PERL_CALLCONV int PerlIO_eof(PerlIO *);
203 PERL_CALLCONV int PerlIO_error(PerlIO *);
205 #ifndef PerlIO_clearerr
206 PERL_CALLCONV void PerlIO_clearerr(PerlIO *);
209 PERL_CALLCONV int PerlIO_getc(PerlIO *);
212 PERL_CALLCONV int PerlIO_putc(PerlIO *, int);
214 #ifndef PerlIO_ungetc
215 PERL_CALLCONV int PerlIO_ungetc(PerlIO *, int);
217 #ifndef PerlIO_fdopen
218 PERL_CALLCONV PerlIO *PerlIO_fdopen(int, const char *);
220 #ifndef PerlIO_importFILE
221 PERL_CALLCONV PerlIO *PerlIO_importFILE(FILE *, const char *);
223 #ifndef PerlIO_exportFILE
224 PERL_CALLCONV FILE *PerlIO_exportFILE(PerlIO *, const char *);
226 #ifndef PerlIO_findFILE
227 PERL_CALLCONV FILE *PerlIO_findFILE(PerlIO *);
229 #ifndef PerlIO_releaseFILE
230 PERL_CALLCONV void PerlIO_releaseFILE(PerlIO *, FILE *);
233 PERL_CALLCONV SSize_t PerlIO_read(PerlIO *, void *, Size_t);
235 #ifndef PerlIO_unread
236 PERL_CALLCONV SSize_t PerlIO_unread(PerlIO *, const void *, Size_t);
239 PERL_CALLCONV SSize_t PerlIO_write(PerlIO *, const void *, Size_t);
241 #ifndef PerlIO_setlinebuf
242 PERL_CALLCONV void PerlIO_setlinebuf(PerlIO *);
244 #ifndef PerlIO_printf
245 PERL_CALLCONV int PerlIO_printf(PerlIO *, const char *, ...)
246 __attribute__format__(__printf__, 2, 3);
248 #ifndef PerlIO_vprintf
249 PERL_CALLCONV int PerlIO_vprintf(PerlIO *, const char *, va_list);
252 PERL_CALLCONV Off_t PerlIO_tell(PerlIO *);
255 PERL_CALLCONV int PerlIO_seek(PerlIO *, Off_t, int);
257 #ifndef PerlIO_rewind
258 PERL_CALLCONV void PerlIO_rewind(PerlIO *);
260 #ifndef PerlIO_has_base
261 PERL_CALLCONV int PerlIO_has_base(PerlIO *);
263 #ifndef PerlIO_has_cntptr
264 PERL_CALLCONV int PerlIO_has_cntptr(PerlIO *);
266 #ifndef PerlIO_fast_gets
267 PERL_CALLCONV int PerlIO_fast_gets(PerlIO *);
269 #ifndef PerlIO_canset_cnt
270 PERL_CALLCONV int PerlIO_canset_cnt(PerlIO *);
272 #ifndef PerlIO_get_ptr
273 PERL_CALLCONV STDCHAR *PerlIO_get_ptr(PerlIO *);
275 #ifndef PerlIO_get_cnt
276 PERL_CALLCONV SSize_t PerlIO_get_cnt(PerlIO *);
278 #ifndef PerlIO_set_cnt
279 PERL_CALLCONV void PerlIO_set_cnt(PerlIO *, SSize_t);
281 #ifndef PerlIO_set_ptrcnt
282 PERL_CALLCONV void PerlIO_set_ptrcnt(PerlIO *, STDCHAR *, SSize_t);
284 #ifndef PerlIO_get_base
285 PERL_CALLCONV STDCHAR *PerlIO_get_base(PerlIO *);
287 #ifndef PerlIO_get_bufsiz
288 PERL_CALLCONV SSize_t PerlIO_get_bufsiz(PerlIO *);
290 #ifndef PerlIO_tmpfile
291 PERL_CALLCONV PerlIO *PerlIO_tmpfile(void);
293 #ifndef PerlIO_tmpfile_flags
294 PERL_CALLCONV PerlIO *PerlIO_tmpfile_flags(int flags);
297 PERL_CALLCONV PerlIO *PerlIO_stdin(void);
299 #ifndef PerlIO_stdout
300 PERL_CALLCONV PerlIO *PerlIO_stdout(void);
302 #ifndef PerlIO_stderr
303 PERL_CALLCONV PerlIO *PerlIO_stderr(void);
305 #ifndef PerlIO_getpos
306 PERL_CALLCONV int PerlIO_getpos(PerlIO *, SV *);
308 #ifndef PerlIO_setpos
309 PERL_CALLCONV int PerlIO_setpos(PerlIO *, SV *);
311 #ifndef PerlIO_fdupopen
312 PERL_CALLCONV PerlIO *PerlIO_fdupopen(pTHX_ PerlIO *, CLONE_PARAMS *, int);
314 #if !defined(PerlIO_modestr)
315 PERL_CALLCONV char *PerlIO_modestr(PerlIO *, char *buf);
317 #ifndef PerlIO_isutf8
318 PERL_CALLCONV int PerlIO_isutf8(PerlIO *);
320 #ifndef PerlIO_apply_layers
321 PERL_CALLCONV int PerlIO_apply_layers(pTHX_ PerlIO *f, const char *mode,
324 #ifndef PerlIO_binmode
325 PERL_CALLCONV int PerlIO_binmode(pTHX_ PerlIO *f, int iotype, int omode,
328 #ifndef PerlIO_getname
329 PERL_CALLCONV char *PerlIO_getname(PerlIO *, char *);
332 PERL_CALLCONV void PerlIO_destruct(pTHX);
334 PERL_CALLCONV int PerlIO_intmode2str(int rawmode, char *mode, int *writing);
337 PERL_CALLCONV void PerlIO_cleanup(pTHX);
339 PERL_CALLCONV void PerlIO_debug(const char *fmt, ...)
340 __attribute__format__(__printf__, 1, 2);
341 typedef struct PerlIO_list_s PerlIO_list_t;
346 #endif /* PERLIO_H_ */
349 * ex: set ts=8 sts=4 sw=4 et: