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
66 /* PERLIO_FUNCS_CONST is now on by default for efficiency, PERLIO_FUNCS_CONST
67 can be removed 1 day once stable & then PerlIO vtables are permanently RO */
68 #ifdef PERLIO_FUNCS_CONST
69 #define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs
70 #define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs)
72 #define PERLIO_FUNCS_DECL(funcs) PerlIO_funcs funcs
73 #define PERLIO_FUNCS_CAST(funcs) (funcs)
76 PERL_CALLCONV void PerlIO_define_layer(pTHX_ PerlIO_funcs *tab);
77 PERL_CALLCONV PerlIO_funcs *PerlIO_find_layer(pTHX_ const char *name,
80 PERL_CALLCONV PerlIO *PerlIO_push(pTHX_ PerlIO *f, PERLIO_FUNCS_DECL(*tab),
81 const char *mode, SV *arg);
82 PERL_CALLCONV void PerlIO_pop(pTHX_ PerlIO *f);
83 PERL_CALLCONV AV* PerlIO_get_layers(pTHX_ PerlIO *f);
84 PERL_CALLCONV void PerlIO_clone(pTHX_ PerlInterpreter *proto,
89 /* ----------- End of implementation choices ---------- */
91 /* We now need to determine what happens if source trys to use stdio.
92 * There are three cases based on PERLIO_NOT_STDIO which XS code
93 * can set how it wants.
97 /* Make a choice for perl core code
98 - currently this is set to try and catch lingering raw stdio calls.
99 This is a known issue with some non UNIX ports which still use
100 "native" stdio features.
102 # ifndef PERLIO_NOT_STDIO
103 # define PERLIO_NOT_STDIO 1
106 # ifndef PERLIO_NOT_STDIO
107 # define PERLIO_NOT_STDIO 0
111 #ifdef PERLIO_NOT_STDIO
114 * PERLIO_NOT_STDIO #define'd as 1
115 * Case 1: Strong denial of stdio - make all stdio calls (we can think of) errors
118 #else /* if PERLIO_NOT_STDIO */
120 * PERLIO_NOT_STDIO #define'd as 0
121 * Case 2: Declares that both PerlIO and stdio can be used
123 #endif /* if PERLIO_NOT_STDIO */
124 #else /* ifdef PERLIO_NOT_STDIO */
126 * PERLIO_NOT_STDIO not defined
127 * Case 3: Try and fake stdio calls as PerlIO calls
129 #include "fakesdio.h"
130 #endif /* ifndef PERLIO_NOT_STDIO */
132 /* ----------- fill in things that have not got #define'd ---------- */
142 /* This is to catch case with no stdio */
147 /* The default buffer size for the perlio buffering layer */
148 #ifndef PERLIOBUF_DEFAULT_BUFSIZ
149 #define PERLIOBUF_DEFAULT_BUFSIZ (BUFSIZ > 8192 ? BUFSIZ : 8192)
164 #define PERLIO_DUP_CLONE 1
165 #define PERLIO_DUP_FD 2
167 /* --------------------- Now prototypes for functions --------------- */
170 #ifndef __attribute__format__
171 # ifdef HASATTRIBUTE_FORMAT
172 # define __attribute__format__(x,y,z) __attribute__((format(x,y,z)))
174 # define __attribute__format__(x,y,z)
178 PERL_CALLCONV void PerlIO_init(pTHX);
180 #ifndef PerlIO_stdoutf
181 PERL_CALLCONV int PerlIO_stdoutf(const char *, ...)
182 __attribute__format__(__printf__, 1, 2);
185 PERL_CALLCONV int PerlIO_puts(PerlIO *, const char *);
188 PERL_CALLCONV PerlIO *PerlIO_open(const char *, const char *);
191 PERL_CALLCONV PerlIO *PerlIO_openn(pTHX_ const char *layers, const char *mode,
192 int fd, int imode, int perm, PerlIO *old,
196 PERL_CALLCONV int PerlIO_eof(PerlIO *);
199 PERL_CALLCONV int PerlIO_error(PerlIO *);
201 #ifndef PerlIO_clearerr
202 PERL_CALLCONV void PerlIO_clearerr(PerlIO *);
205 PERL_CALLCONV int PerlIO_getc(PerlIO *);
208 PERL_CALLCONV int PerlIO_putc(PerlIO *, int);
210 #ifndef PerlIO_ungetc
211 PERL_CALLCONV int PerlIO_ungetc(PerlIO *, int);
213 #ifndef PerlIO_fdopen
214 PERL_CALLCONV PerlIO *PerlIO_fdopen(int, const char *);
216 #ifndef PerlIO_importFILE
217 PERL_CALLCONV PerlIO *PerlIO_importFILE(FILE *, const char *);
219 #ifndef PerlIO_exportFILE
220 PERL_CALLCONV FILE *PerlIO_exportFILE(PerlIO *, const char *);
222 #ifndef PerlIO_findFILE
223 PERL_CALLCONV FILE *PerlIO_findFILE(PerlIO *);
225 #ifndef PerlIO_releaseFILE
226 PERL_CALLCONV void PerlIO_releaseFILE(PerlIO *, FILE *);
229 PERL_CALLCONV SSize_t PerlIO_read(PerlIO *, void *, Size_t);
231 #ifndef PerlIO_unread
232 PERL_CALLCONV SSize_t PerlIO_unread(PerlIO *, const void *, Size_t);
235 PERL_CALLCONV SSize_t PerlIO_write(PerlIO *, const void *, Size_t);
237 #ifndef PerlIO_setlinebuf
238 PERL_CALLCONV void PerlIO_setlinebuf(PerlIO *);
240 #ifndef PerlIO_printf
241 PERL_CALLCONV int PerlIO_printf(PerlIO *, const char *, ...)
242 __attribute__format__(__printf__, 2, 3);
244 #ifndef PerlIO_vprintf
245 PERL_CALLCONV int PerlIO_vprintf(PerlIO *, const char *, va_list);
248 PERL_CALLCONV Off_t PerlIO_tell(PerlIO *);
251 PERL_CALLCONV int PerlIO_seek(PerlIO *, Off_t, int);
253 #ifndef PerlIO_rewind
254 PERL_CALLCONV void PerlIO_rewind(PerlIO *);
256 #ifndef PerlIO_has_base
257 PERL_CALLCONV int PerlIO_has_base(PerlIO *);
259 #ifndef PerlIO_has_cntptr
260 PERL_CALLCONV int PerlIO_has_cntptr(PerlIO *);
262 #ifndef PerlIO_fast_gets
263 PERL_CALLCONV int PerlIO_fast_gets(PerlIO *);
265 #ifndef PerlIO_canset_cnt
266 PERL_CALLCONV int PerlIO_canset_cnt(PerlIO *);
268 #ifndef PerlIO_get_ptr
269 PERL_CALLCONV STDCHAR *PerlIO_get_ptr(PerlIO *);
271 #ifndef PerlIO_get_cnt
272 PERL_CALLCONV SSize_t PerlIO_get_cnt(PerlIO *);
274 #ifndef PerlIO_set_cnt
275 PERL_CALLCONV void PerlIO_set_cnt(PerlIO *, SSize_t);
277 #ifndef PerlIO_set_ptrcnt
278 PERL_CALLCONV void PerlIO_set_ptrcnt(PerlIO *, STDCHAR *, SSize_t);
280 #ifndef PerlIO_get_base
281 PERL_CALLCONV STDCHAR *PerlIO_get_base(PerlIO *);
283 #ifndef PerlIO_get_bufsiz
284 PERL_CALLCONV SSize_t PerlIO_get_bufsiz(PerlIO *);
286 #ifndef PerlIO_tmpfile
287 PERL_CALLCONV PerlIO *PerlIO_tmpfile(void);
289 #ifndef PerlIO_tmpfile_flags
290 PERL_CALLCONV PerlIO *PerlIO_tmpfile_flags(int flags);
293 PERL_CALLCONV PerlIO *PerlIO_stdin(void);
295 #ifndef PerlIO_stdout
296 PERL_CALLCONV PerlIO *PerlIO_stdout(void);
298 #ifndef PerlIO_stderr
299 PERL_CALLCONV PerlIO *PerlIO_stderr(void);
301 #ifndef PerlIO_getpos
302 PERL_CALLCONV int PerlIO_getpos(PerlIO *, SV *);
304 #ifndef PerlIO_setpos
305 PERL_CALLCONV int PerlIO_setpos(PerlIO *, SV *);
307 #ifndef PerlIO_fdupopen
308 PERL_CALLCONV PerlIO *PerlIO_fdupopen(pTHX_ PerlIO *, CLONE_PARAMS *, int);
310 #if !defined(PerlIO_modestr)
311 PERL_CALLCONV char *PerlIO_modestr(PerlIO *, char *buf);
313 #ifndef PerlIO_isutf8
314 PERL_CALLCONV int PerlIO_isutf8(PerlIO *);
316 #ifndef PerlIO_apply_layers
317 PERL_CALLCONV int PerlIO_apply_layers(pTHX_ PerlIO *f, const char *mode,
320 #ifndef PerlIO_binmode
321 PERL_CALLCONV int PerlIO_binmode(pTHX_ PerlIO *f, int iotype, int omode,
324 #ifndef PerlIO_getname
325 PERL_CALLCONV char *PerlIO_getname(PerlIO *, char *);
328 PERL_CALLCONV void PerlIO_destruct(pTHX);
330 PERL_CALLCONV int PerlIO_intmode2str(int rawmode, char *mode, int *writing);
333 PERL_CALLCONV void PerlIO_cleanup(pTHX);
335 PERL_CALLCONV void PerlIO_debug(const char *fmt, ...)
336 __attribute__format__(__printf__, 1, 2);
337 typedef struct PerlIO_list_s PerlIO_list_t;
342 #endif /* PERLIO_H_ */
345 * ex: set ts=8 sts=4 sw=4 et: