3 * Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003,
4 * 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 - forces PerlIO_xxx() to be #define-d onto stdio functions.
17 This is used for x2p subdirectory and for conservative
18 builds - "just like perl5.00X used to be".
19 This dominates over the others.
21 USE_PERLIO - The primary Configure variable that enables PerlIO.
22 If USE_PERLIO is _NOT_ set
23 then USE_STDIO above will be set to be conservative.
25 then there are two modes determined by USE_SFIO:
27 USE_SFIO - If set causes PerlIO_xxx() to be #define-d onto sfio functions.
28 A backward compatability mode for some specialist applications.
30 If USE_SFIO is not set then PerlIO_xxx() are real functions
31 defined in perlio.c which implement extra functionality
32 required for utf8 support.
34 One further note - the table-of-functions scheme controlled
35 by PERL_IMPLICIT_SYS turns on USE_PERLIO so that iperlsys.h can
36 #define PerlIO_xxx() to go via the function table, without having
37 to #undef them from (say) stdio forms.
41 #if defined(PERL_IMPLICIT_SYS)
44 /* # define USE_PERLIO */
54 # ifndef PERLIO_IS_STDIO
55 # define PERLIO_IS_STDIO
59 /* -------------------- End of Configure controls ---------------------------- */
62 * Although we may not want stdio to be used including <stdio.h> here
63 * avoids issues where stdio.h has strange side effects
68 int fseeko(FILE *stream, off_t offset, int whence);
69 off_t ftello(FILE *stream);
72 #if defined(USE_64_BIT_STDIO) && defined(HAS_FTELLO) && !defined(USE_FTELL64)
76 #if defined(USE_64_BIT_STDIO) && defined(HAS_FSEEKO) && !defined(USE_FSEEK64)
80 /* BS2000 includes are sometimes a bit non standard :-( */
81 #if defined(POSIX_BC) && defined(O_BINARY) && !defined(O_TEXT)
85 #ifdef PERLIO_IS_STDIO
86 /* #define PerlIO_xxxx() as equivalent stdio function */
88 #else /* PERLIO_IS_STDIO */
90 /* #define PerlIO_xxxx() as equivalent sfio function */
93 #endif /* PERLIO_IS_STDIO */
96 /* ----------- PerlIO implementation ---------- */
97 /* PerlIO not #define-d to something else - define the implementation */
99 typedef struct _PerlIO PerlIOl;
100 typedef struct _PerlIO_funcs PerlIO_funcs;
101 typedef PerlIOl *PerlIO;
102 #define PerlIO PerlIO
103 #define PERLIO_LAYERS 1
105 /* Making the big PerlIO_funcs vtables const is good (enables placing
106 * them in the const section which is good for speed, security, and
107 * embeddability) but this cannot be done by default because of
108 * backward compatibility. */
109 #ifdef PERLIO_FUNCS_CONST
110 #define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs
111 #define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs)
113 #define PERLIO_FUNCS_DECL(funcs) PerlIO_funcs funcs
114 #define PERLIO_FUNCS_CAST(funcs) (funcs)
117 PERL_EXPORT_C void PerlIO_define_layer(pTHX_ PerlIO_funcs *tab);
118 PERL_EXPORT_C PerlIO_funcs *PerlIO_find_layer(pTHX_ const char *name,
121 PERL_EXPORT_C PerlIO *PerlIO_push(pTHX_ PerlIO *f, PERLIO_FUNCS_DECL(*tab),
122 const char *mode, SV *arg);
123 PERL_EXPORT_C void PerlIO_pop(pTHX_ PerlIO *f);
124 PERL_EXPORT_C AV* PerlIO_get_layers(pTHX_ PerlIO *f);
125 PERL_EXPORT_C void PerlIO_clone(pTHX_ PerlInterpreter *proto,
126 CLONE_PARAMS *param);
130 /* ----------- End of implementation choices ---------- */
132 #ifndef PERLIO_IS_STDIO
133 /* Not using stdio _directly_ as PerlIO */
135 /* We now need to determine what happens if source trys to use stdio.
136 * There are three cases based on PERLIO_NOT_STDIO which XS code
137 * can set how it wants.
141 /* Make a choice for perl core code
142 - currently this is set to try and catch lingering raw stdio calls.
143 This is a known issue with some non UNIX ports which still use
144 "native" stdio features.
146 #ifndef PERLIO_NOT_STDIO
147 #define PERLIO_NOT_STDIO 1
150 #ifndef PERLIO_NOT_STDIO
151 #define PERLIO_NOT_STDIO 0
155 #ifdef PERLIO_NOT_STDIO
158 * PERLIO_NOT_STDIO #define'd as 1
159 * Case 1: Strong denial of stdio - make all stdio calls (we can think of) errors
162 #else /* if PERLIO_NOT_STDIO */
164 * PERLIO_NOT_STDIO #define'd as 0
165 * Case 2: Declares that both PerlIO and stdio can be used
167 #endif /* if PERLIO_NOT_STDIO */
168 #else /* ifdef PERLIO_NOT_STDIO */
170 * PERLIO_NOT_STDIO not defined
171 * Case 3: Try and fake stdio calls as PerlIO calls
173 #include "fakesdio.h"
174 #endif /* ifndef PERLIO_NOT_STDIO */
175 #endif /* PERLIO_IS_STDIO */
177 #define specialCopIO(sv) ((sv) == Nullsv)
179 /* ----------- fill in things that have not got #define'd ---------- */
189 /* This is to catch case with no stdio */
206 #define PERLIO_DUP_CLONE 1
207 #define PERLIO_DUP_FD 2
209 /* --------------------- Now prototypes for functions --------------- */
212 #ifndef __attribute__format__
213 # ifdef HASATTRIBUTE_FORMAT
214 # define __attribute__format__(x,y,z) __attribute__((format(x,y,z)))
216 # define __attribute__format__(x,y,z)
220 PERL_EXPORT_C void PerlIO_init(pTHX);
222 #ifndef PerlIO_stdoutf
223 PERL_EXPORT_C int PerlIO_stdoutf(const char *, ...)
224 __attribute__format__(__printf__, 1, 2);
227 PERL_EXPORT_C int PerlIO_puts(PerlIO *, const char *);
230 PERL_EXPORT_C PerlIO *PerlIO_open(const char *, const char *);
233 PERL_EXPORT_C PerlIO *PerlIO_openn(pTHX_ const char *layers, const char *mode,
234 int fd, int imode, int perm, PerlIO *old,
238 PERL_EXPORT_C int PerlIO_eof(PerlIO *);
241 PERL_EXPORT_C int PerlIO_error(PerlIO *);
243 #ifndef PerlIO_clearerr
244 PERL_EXPORT_C void PerlIO_clearerr(PerlIO *);
247 PERL_EXPORT_C int PerlIO_getc(PerlIO *);
250 PERL_EXPORT_C int PerlIO_putc(PerlIO *, int);
252 #ifndef PerlIO_ungetc
253 PERL_EXPORT_C int PerlIO_ungetc(PerlIO *, int);
255 #ifndef PerlIO_fdopen
256 PERL_EXPORT_C PerlIO *PerlIO_fdopen(int, const char *);
258 #ifndef PerlIO_importFILE
259 PERL_EXPORT_C PerlIO *PerlIO_importFILE(FILE *, const char *);
261 #ifndef PerlIO_exportFILE
262 PERL_EXPORT_C FILE *PerlIO_exportFILE(PerlIO *, const char *);
264 #ifndef PerlIO_findFILE
265 PERL_EXPORT_C FILE *PerlIO_findFILE(PerlIO *);
267 #ifndef PerlIO_releaseFILE
268 PERL_EXPORT_C void PerlIO_releaseFILE(PerlIO *, FILE *);
271 PERL_EXPORT_C SSize_t PerlIO_read(PerlIO *, void *, Size_t);
273 #ifndef PerlIO_unread
274 PERL_EXPORT_C SSize_t PerlIO_unread(PerlIO *, const void *, Size_t);
277 PERL_EXPORT_C SSize_t PerlIO_write(PerlIO *, const void *, Size_t);
279 #ifndef PerlIO_setlinebuf
280 PERL_EXPORT_C void PerlIO_setlinebuf(PerlIO *);
282 #ifndef PerlIO_printf
283 PERL_EXPORT_C int PerlIO_printf(PerlIO *, const char *, ...)
284 __attribute__format__(__printf__, 2, 3);
286 #ifndef PerlIO_sprintf
287 PERL_EXPORT_C int PerlIO_sprintf(char *, int, const char *, ...)
288 __attribute__format__(__printf__, 3, 4);
290 #ifndef PerlIO_vprintf
291 PERL_EXPORT_C int PerlIO_vprintf(PerlIO *, const char *, va_list);
294 PERL_EXPORT_C Off_t PerlIO_tell(PerlIO *);
297 PERL_EXPORT_C int PerlIO_seek(PerlIO *, Off_t, int);
299 #ifndef PerlIO_rewind
300 PERL_EXPORT_C void PerlIO_rewind(PerlIO *);
302 #ifndef PerlIO_has_base
303 PERL_EXPORT_C int PerlIO_has_base(PerlIO *);
305 #ifndef PerlIO_has_cntptr
306 PERL_EXPORT_C int PerlIO_has_cntptr(PerlIO *);
308 #ifndef PerlIO_fast_gets
309 PERL_EXPORT_C int PerlIO_fast_gets(PerlIO *);
311 #ifndef PerlIO_canset_cnt
312 PERL_EXPORT_C int PerlIO_canset_cnt(PerlIO *);
314 #ifndef PerlIO_get_ptr
315 PERL_EXPORT_C STDCHAR *PerlIO_get_ptr(PerlIO *);
317 #ifndef PerlIO_get_cnt
318 PERL_EXPORT_C int PerlIO_get_cnt(PerlIO *);
320 #ifndef PerlIO_set_cnt
321 PERL_EXPORT_C void PerlIO_set_cnt(PerlIO *, int);
323 #ifndef PerlIO_set_ptrcnt
324 PERL_EXPORT_C void PerlIO_set_ptrcnt(PerlIO *, STDCHAR *, int);
326 #ifndef PerlIO_get_base
327 PERL_EXPORT_C STDCHAR *PerlIO_get_base(PerlIO *);
329 #ifndef PerlIO_get_bufsiz
330 PERL_EXPORT_C int PerlIO_get_bufsiz(PerlIO *);
332 #ifndef PerlIO_tmpfile
333 PERL_EXPORT_C PerlIO *PerlIO_tmpfile(void);
336 PERL_EXPORT_C PerlIO *PerlIO_stdin(void);
338 #ifndef PerlIO_stdout
339 PERL_EXPORT_C PerlIO *PerlIO_stdout(void);
341 #ifndef PerlIO_stderr
342 PERL_EXPORT_C PerlIO *PerlIO_stderr(void);
344 #ifndef PerlIO_getpos
345 PERL_EXPORT_C int PerlIO_getpos(PerlIO *, SV *);
347 #ifndef PerlIO_setpos
348 PERL_EXPORT_C int PerlIO_setpos(PerlIO *, SV *);
350 #ifndef PerlIO_fdupopen
351 PERL_EXPORT_C PerlIO *PerlIO_fdupopen(pTHX_ PerlIO *, CLONE_PARAMS *, int);
353 #if !defined(PerlIO_modestr) && !defined(PERLIO_IS_STDIO)
354 PERL_EXPORT_C char *PerlIO_modestr(PerlIO *, char *buf);
356 #ifndef PerlIO_isutf8
357 PERL_EXPORT_C int PerlIO_isutf8(PerlIO *);
359 #ifndef PerlIO_apply_layers
360 PERL_EXPORT_C int PerlIO_apply_layers(pTHX_ PerlIO *f, const char *mode,
363 #ifndef PerlIO_binmode
364 PERL_EXPORT_C int PerlIO_binmode(pTHX_ PerlIO *f, int iotype, int omode,
367 #ifndef PerlIO_getname
368 PERL_EXPORT_C char *PerlIO_getname(PerlIO *, char *);
371 PERL_EXPORT_C void PerlIO_destruct(pTHX);
373 PERL_EXPORT_C int PerlIO_intmode2str(int rawmode, char *mode, int *writing);
376 PERL_EXPORT_C void PerlIO_cleanup(pTHX);
378 PERL_EXPORT_C void PerlIO_debug(const char *fmt, ...)
379 __attribute__format__(__printf__, 1, 2);
380 typedef struct PerlIO_list_s PerlIO_list_t;
386 #endif /* _PERLIO_H */