This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perlretut: Cleanup, nits
[perl5.git] / perlio.h
CommitLineData
eb1102fc
NIS
1/* perlio.h
2 *
4bb101f2 3 * Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003,
663f364b 4 * 2004, 2005, 2006, 2007, by Larry Wall and others
eb1102fc
NIS
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
76ced9ad
NIS
11#ifndef _PERLIO_H
12#define _PERLIO_H
13/*
14 Interface for perl to IO functions.
3d036c2b 15 There is a hierarchy of Configure determined #define controls:
786296d4
CB
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.
76ced9ad
NIS
19
20 USE_PERLIO - The primary Configure variable that enables PerlIO.
97cb92d6 21 PerlIO_xxx() are real functions
76ced9ad
NIS
22 defined in perlio.c which implement extra functionality
23 required for utf8 support.
24
76ced9ad
NIS
25*/
26
76ced9ad
NIS
27#ifndef USE_PERLIO
28# define USE_STDIO
29#endif
30
31#ifdef USE_STDIO
786296d4 32# error "stdio is no longer supported as the default base layer -- use perlio."
76ced9ad
NIS
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
6f2bd249
JH
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
76ced9ad
NIS
56#ifndef PerlIO
57/* ----------- PerlIO implementation ---------- */
58/* PerlIO not #define-d to something else - define the implementation */
59
60typedef struct _PerlIO PerlIOl;
61typedef struct _PerlIO_funcs PerlIO_funcs;
62typedef PerlIOl *PerlIO;
63#define PerlIO PerlIO
a1d180c4 64#define PERLIO_LAYERS 1
76ced9ad 65
f0e5c859
DD
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 */
27da23d5
JH
68#ifdef PERLIO_FUNCS_CONST
69#define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs
70#define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs)
71#else
72#define PERLIO_FUNCS_DECL(funcs) PerlIO_funcs funcs
73#define PERLIO_FUNCS_CAST(funcs) (funcs)
74#endif
75
fc6bde6f
DD
76PERL_CALLCONV void PerlIO_define_layer(pTHX_ PerlIO_funcs *tab);
77PERL_CALLCONV PerlIO_funcs *PerlIO_find_layer(pTHX_ const char *name,
27da23d5
JH
78 STRLEN len,
79 int load);
fc6bde6f 80PERL_CALLCONV PerlIO *PerlIO_push(pTHX_ PerlIO *f, PERLIO_FUNCS_DECL(*tab),
27da23d5 81 const char *mode, SV *arg);
fc6bde6f
DD
82PERL_CALLCONV void PerlIO_pop(pTHX_ PerlIO *f);
83PERL_CALLCONV AV* PerlIO_get_layers(pTHX_ PerlIO *f);
84PERL_CALLCONV void PerlIO_clone(pTHX_ PerlInterpreter *proto,
27da23d5 85 CLONE_PARAMS *param);
76ced9ad 86
14a5cf38 87#endif /* PerlIO */
76ced9ad
NIS
88
89/* ----------- End of implementation choices ---------- */
90
76ced9ad
NIS
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.
94 */
95
786296d4 96#ifdef PERL_CORE
76ced9ad
NIS
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.
101*/
786296d4
CB
102# ifndef PERLIO_NOT_STDIO
103# define PERLIO_NOT_STDIO 1
104# endif
105#else
106# ifndef PERLIO_NOT_STDIO
107# define PERLIO_NOT_STDIO 0
108# endif
76ced9ad
NIS
109#endif
110
111#ifdef PERLIO_NOT_STDIO
112#if PERLIO_NOT_STDIO
113/*
114 * PERLIO_NOT_STDIO #define'd as 1
115 * Case 1: Strong denial of stdio - make all stdio calls (we can think of) errors
116 */
117#include "nostdio.h"
14a5cf38 118#else /* if PERLIO_NOT_STDIO */
76ced9ad
NIS
119/*
120 * PERLIO_NOT_STDIO #define'd as 0
121 * Case 2: Declares that both PerlIO and stdio can be used
122 */
14a5cf38
JH
123#endif /* if PERLIO_NOT_STDIO */
124#else /* ifdef PERLIO_NOT_STDIO */
76ced9ad
NIS
125/*
126 * PERLIO_NOT_STDIO not defined
127 * Case 3: Try and fake stdio calls as PerlIO calls
128 */
129#include "fakesdio.h"
14a5cf38 130#endif /* ifndef PERLIO_NOT_STDIO */
76ced9ad
NIS
131
132/* ----------- fill in things that have not got #define'd ---------- */
133
134#ifndef Fpos_t
135#define Fpos_t Off_t
136#endif
137
138#ifndef EOF
139#define EOF (-1)
140#endif
141
142/* This is to catch case with no stdio */
143#ifndef BUFSIZ
144#define BUFSIZ 1024
145#endif
146
1810cd7c
CB
147/* The default buffer size for the perlio buffering layer */
148#ifndef PERLIOBUF_DEFAULT_BUFSIZ
b83080de 149#define PERLIOBUF_DEFAULT_BUFSIZ (BUFSIZ > 8192 ? BUFSIZ : 8192)
a3cbd8d0
CB
150#endif
151
76ced9ad
NIS
152#ifndef SEEK_SET
153#define SEEK_SET 0
154#endif
155
156#ifndef SEEK_CUR
157#define SEEK_CUR 1
158#endif
159
160#ifndef SEEK_END
161#define SEEK_END 2
162#endif
163
ecdeb87c
NIS
164#define PERLIO_DUP_CLONE 1
165#define PERLIO_DUP_FD 2
166
76ced9ad
NIS
167/* --------------------- Now prototypes for functions --------------- */
168
adb71456 169START_EXTERN_C
2c2e4525 170#ifndef __attribute__format__
b79c357a
RGS
171# ifdef HASATTRIBUTE_FORMAT
172# define __attribute__format__(x,y,z) __attribute__((format(x,y,z)))
173# else
174# define __attribute__format__(x,y,z)
175# endif
76ced9ad 176#endif
76ced9ad 177#ifndef PerlIO_init
fc6bde6f 178PERL_CALLCONV void PerlIO_init(pTHX);
76ced9ad
NIS
179#endif
180#ifndef PerlIO_stdoutf
fc6bde6f 181PERL_CALLCONV int PerlIO_stdoutf(const char *, ...)
287c8091 182 __attribute__format__(__printf__, 1, 2);
76ced9ad
NIS
183#endif
184#ifndef PerlIO_puts
fc6bde6f 185PERL_CALLCONV int PerlIO_puts(PerlIO *, const char *);
76ced9ad
NIS
186#endif
187#ifndef PerlIO_open
fc6bde6f 188PERL_CALLCONV PerlIO *PerlIO_open(const char *, const char *);
76ced9ad 189#endif
6e60e805 190#ifndef PerlIO_openn
fc6bde6f 191PERL_CALLCONV PerlIO *PerlIO_openn(pTHX_ const char *layers, const char *mode,
27da23d5
JH
192 int fd, int imode, int perm, PerlIO *old,
193 int narg, SV **arg);
ee518936 194#endif
76ced9ad 195#ifndef PerlIO_eof
fc6bde6f 196PERL_CALLCONV int PerlIO_eof(PerlIO *);
76ced9ad
NIS
197#endif
198#ifndef PerlIO_error
fc6bde6f 199PERL_CALLCONV int PerlIO_error(PerlIO *);
76ced9ad
NIS
200#endif
201#ifndef PerlIO_clearerr
fc6bde6f 202PERL_CALLCONV void PerlIO_clearerr(PerlIO *);
76ced9ad
NIS
203#endif
204#ifndef PerlIO_getc
fc6bde6f 205PERL_CALLCONV int PerlIO_getc(PerlIO *);
76ced9ad
NIS
206#endif
207#ifndef PerlIO_putc
fc6bde6f 208PERL_CALLCONV int PerlIO_putc(PerlIO *, int);
76ced9ad 209#endif
76ced9ad 210#ifndef PerlIO_ungetc
fc6bde6f 211PERL_CALLCONV int PerlIO_ungetc(PerlIO *, int);
76ced9ad 212#endif
76ced9ad 213#ifndef PerlIO_fdopen
fc6bde6f 214PERL_CALLCONV PerlIO *PerlIO_fdopen(int, const char *);
76ced9ad
NIS
215#endif
216#ifndef PerlIO_importFILE
fc6bde6f 217PERL_CALLCONV PerlIO *PerlIO_importFILE(FILE *, const char *);
76ced9ad
NIS
218#endif
219#ifndef PerlIO_exportFILE
fc6bde6f 220PERL_CALLCONV FILE *PerlIO_exportFILE(PerlIO *, const char *);
76ced9ad
NIS
221#endif
222#ifndef PerlIO_findFILE
fc6bde6f 223PERL_CALLCONV FILE *PerlIO_findFILE(PerlIO *);
76ced9ad
NIS
224#endif
225#ifndef PerlIO_releaseFILE
fc6bde6f 226PERL_CALLCONV void PerlIO_releaseFILE(PerlIO *, FILE *);
76ced9ad
NIS
227#endif
228#ifndef PerlIO_read
fc6bde6f 229PERL_CALLCONV SSize_t PerlIO_read(PerlIO *, void *, Size_t);
76ced9ad 230#endif
a15cef0c 231#ifndef PerlIO_unread
fc6bde6f 232PERL_CALLCONV SSize_t PerlIO_unread(PerlIO *, const void *, Size_t);
a15cef0c 233#endif
76ced9ad 234#ifndef PerlIO_write
fc6bde6f 235PERL_CALLCONV SSize_t PerlIO_write(PerlIO *, const void *, Size_t);
76ced9ad
NIS
236#endif
237#ifndef PerlIO_setlinebuf
fc6bde6f 238PERL_CALLCONV void PerlIO_setlinebuf(PerlIO *);
76ced9ad
NIS
239#endif
240#ifndef PerlIO_printf
fc6bde6f 241PERL_CALLCONV int PerlIO_printf(PerlIO *, const char *, ...)
287c8091 242 __attribute__format__(__printf__, 2, 3);
76ced9ad 243#endif
76ced9ad 244#ifndef PerlIO_vprintf
fc6bde6f 245PERL_CALLCONV int PerlIO_vprintf(PerlIO *, const char *, va_list);
76ced9ad
NIS
246#endif
247#ifndef PerlIO_tell
fc6bde6f 248PERL_CALLCONV Off_t PerlIO_tell(PerlIO *);
76ced9ad
NIS
249#endif
250#ifndef PerlIO_seek
fc6bde6f 251PERL_CALLCONV int PerlIO_seek(PerlIO *, Off_t, int);
76ced9ad
NIS
252#endif
253#ifndef PerlIO_rewind
fc6bde6f 254PERL_CALLCONV void PerlIO_rewind(PerlIO *);
76ced9ad
NIS
255#endif
256#ifndef PerlIO_has_base
fc6bde6f 257PERL_CALLCONV int PerlIO_has_base(PerlIO *);
76ced9ad
NIS
258#endif
259#ifndef PerlIO_has_cntptr
fc6bde6f 260PERL_CALLCONV int PerlIO_has_cntptr(PerlIO *);
76ced9ad
NIS
261#endif
262#ifndef PerlIO_fast_gets
fc6bde6f 263PERL_CALLCONV int PerlIO_fast_gets(PerlIO *);
76ced9ad
NIS
264#endif
265#ifndef PerlIO_canset_cnt
fc6bde6f 266PERL_CALLCONV int PerlIO_canset_cnt(PerlIO *);
76ced9ad
NIS
267#endif
268#ifndef PerlIO_get_ptr
fc6bde6f 269PERL_CALLCONV STDCHAR *PerlIO_get_ptr(PerlIO *);
76ced9ad
NIS
270#endif
271#ifndef PerlIO_get_cnt
fc6bde6f 272PERL_CALLCONV SSize_t PerlIO_get_cnt(PerlIO *);
76ced9ad
NIS
273#endif
274#ifndef PerlIO_set_cnt
fc6bde6f 275PERL_CALLCONV void PerlIO_set_cnt(PerlIO *, SSize_t);
76ced9ad
NIS
276#endif
277#ifndef PerlIO_set_ptrcnt
fc6bde6f 278PERL_CALLCONV void PerlIO_set_ptrcnt(PerlIO *, STDCHAR *, SSize_t);
76ced9ad
NIS
279#endif
280#ifndef PerlIO_get_base
fc6bde6f 281PERL_CALLCONV STDCHAR *PerlIO_get_base(PerlIO *);
76ced9ad
NIS
282#endif
283#ifndef PerlIO_get_bufsiz
fc6bde6f 284PERL_CALLCONV SSize_t PerlIO_get_bufsiz(PerlIO *);
76ced9ad
NIS
285#endif
286#ifndef PerlIO_tmpfile
fc6bde6f 287PERL_CALLCONV PerlIO *PerlIO_tmpfile(void);
76ced9ad
NIS
288#endif
289#ifndef PerlIO_stdin
fc6bde6f 290PERL_CALLCONV PerlIO *PerlIO_stdin(void);
76ced9ad
NIS
291#endif
292#ifndef PerlIO_stdout
fc6bde6f 293PERL_CALLCONV PerlIO *PerlIO_stdout(void);
76ced9ad
NIS
294#endif
295#ifndef PerlIO_stderr
fc6bde6f 296PERL_CALLCONV PerlIO *PerlIO_stderr(void);
76ced9ad
NIS
297#endif
298#ifndef PerlIO_getpos
fc6bde6f 299PERL_CALLCONV int PerlIO_getpos(PerlIO *, SV *);
76ced9ad
NIS
300#endif
301#ifndef PerlIO_setpos
fc6bde6f 302PERL_CALLCONV int PerlIO_setpos(PerlIO *, SV *);
76ced9ad
NIS
303#endif
304#ifndef PerlIO_fdupopen
fc6bde6f 305PERL_CALLCONV PerlIO *PerlIO_fdupopen(pTHX_ PerlIO *, CLONE_PARAMS *, int);
5f1a76d0 306#endif
786296d4 307#if !defined(PerlIO_modestr)
fc6bde6f 308PERL_CALLCONV char *PerlIO_modestr(PerlIO *, char *buf);
76ced9ad
NIS
309#endif
310#ifndef PerlIO_isutf8
fc6bde6f 311PERL_CALLCONV int PerlIO_isutf8(PerlIO *);
76ced9ad 312#endif
156e9b51 313#ifndef PerlIO_apply_layers
fc6bde6f 314PERL_CALLCONV int PerlIO_apply_layers(pTHX_ PerlIO *f, const char *mode,
27da23d5 315 const char *names);
60382766
NIS
316#endif
317#ifndef PerlIO_binmode
fc6bde6f 318PERL_CALLCONV int PerlIO_binmode(pTHX_ PerlIO *f, int iotype, int omode,
27da23d5 319 const char *names);
ac27b0f5 320#endif
a15cef0c 321#ifndef PerlIO_getname
fc6bde6f 322PERL_CALLCONV char *PerlIO_getname(PerlIO *, char *);
a15cef0c 323#endif
76ced9ad 324
fc6bde6f 325PERL_CALLCONV void PerlIO_destruct(pTHX);
13621cfb 326
fc6bde6f 327PERL_CALLCONV int PerlIO_intmode2str(int rawmode, char *mode, int *writing);
06c7082d 328
3a1ee7e8 329#ifdef PERLIO_LAYERS
fc6bde6f 330PERL_CALLCONV void PerlIO_cleanup(pTHX);
adb71456 331
fc6bde6f 332PERL_CALLCONV void PerlIO_debug(const char *fmt, ...)
de009b76 333 __attribute__format__(__printf__, 1, 2);
3a1ee7e8
NIS
334typedef struct PerlIO_list_s PerlIO_list_t;
335
11ae941d
CB
336#endif
337
adb71456 338END_EXTERN_C
14a5cf38 339#endif /* _PERLIO_H */
e9a8c099
MHM
340
341/*
14d04a33 342 * ex: set ts=8 sts=4 sw=4 et:
e9a8c099 343 */