This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
win32.c: Add mutexes around some calls
[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
6a5bc5ac
KW
11#ifndef PERLIO_H_
12#define PERLIO_H_
76ced9ad
NIS
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
dc911d66
KW
66/*
67=for apidoc_section $io
68=for apidoc Amu||PERLIO_FUNCS_DECL|PerlIO * ftab
69Declare C<ftab> to be a PerlIO function table, that is, of type
70C<PerlIO_funcs>.
71
72=for apidoc Ay|PerlIO_funcs *|PERLIO_FUNCS_CAST|PerlIO * func
73Cast the pointer C<func> to be of type S<C<PerlIO_funcs *>>.
74
75=cut
76*/
27da23d5
JH
77#define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs
78#define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs)
27da23d5 79
fc6bde6f
DD
80PERL_CALLCONV void PerlIO_define_layer(pTHX_ PerlIO_funcs *tab);
81PERL_CALLCONV PerlIO_funcs *PerlIO_find_layer(pTHX_ const char *name,
27da23d5 82 STRLEN len,
1604cfb0 83 int load);
fc6bde6f 84PERL_CALLCONV PerlIO *PerlIO_push(pTHX_ PerlIO *f, PERLIO_FUNCS_DECL(*tab),
1604cfb0 85 const char *mode, SV *arg);
fc6bde6f
DD
86PERL_CALLCONV void PerlIO_pop(pTHX_ PerlIO *f);
87PERL_CALLCONV AV* PerlIO_get_layers(pTHX_ PerlIO *f);
88PERL_CALLCONV void PerlIO_clone(pTHX_ PerlInterpreter *proto,
27da23d5 89 CLONE_PARAMS *param);
76ced9ad 90
14a5cf38 91#endif /* PerlIO */
76ced9ad
NIS
92
93/* ----------- End of implementation choices ---------- */
94
76ced9ad
NIS
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.
98 */
99
786296d4 100#ifdef PERL_CORE
76ced9ad
NIS
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.
105*/
786296d4
CB
106# ifndef PERLIO_NOT_STDIO
107# define PERLIO_NOT_STDIO 1
108# endif
109#else
110# ifndef PERLIO_NOT_STDIO
111# define PERLIO_NOT_STDIO 0
112# endif
76ced9ad
NIS
113#endif
114
115#ifdef PERLIO_NOT_STDIO
116#if PERLIO_NOT_STDIO
117/*
118 * PERLIO_NOT_STDIO #define'd as 1
119 * Case 1: Strong denial of stdio - make all stdio calls (we can think of) errors
120 */
121#include "nostdio.h"
14a5cf38 122#else /* if PERLIO_NOT_STDIO */
76ced9ad
NIS
123/*
124 * PERLIO_NOT_STDIO #define'd as 0
125 * Case 2: Declares that both PerlIO and stdio can be used
126 */
14a5cf38
JH
127#endif /* if PERLIO_NOT_STDIO */
128#else /* ifdef PERLIO_NOT_STDIO */
76ced9ad
NIS
129/*
130 * PERLIO_NOT_STDIO not defined
131 * Case 3: Try and fake stdio calls as PerlIO calls
132 */
133#include "fakesdio.h"
14a5cf38 134#endif /* ifndef PERLIO_NOT_STDIO */
76ced9ad
NIS
135
136/* ----------- fill in things that have not got #define'd ---------- */
137
138#ifndef Fpos_t
139#define Fpos_t Off_t
140#endif
141
142#ifndef EOF
143#define EOF (-1)
144#endif
145
146/* This is to catch case with no stdio */
147#ifndef BUFSIZ
148#define BUFSIZ 1024
149#endif
150
1810cd7c
CB
151/* The default buffer size for the perlio buffering layer */
152#ifndef PERLIOBUF_DEFAULT_BUFSIZ
b83080de 153#define PERLIOBUF_DEFAULT_BUFSIZ (BUFSIZ > 8192 ? BUFSIZ : 8192)
a3cbd8d0
CB
154#endif
155
76ced9ad
NIS
156#ifndef SEEK_SET
157#define SEEK_SET 0
158#endif
159
160#ifndef SEEK_CUR
161#define SEEK_CUR 1
162#endif
163
164#ifndef SEEK_END
165#define SEEK_END 2
166#endif
167
ecdeb87c
NIS
168#define PERLIO_DUP_CLONE 1
169#define PERLIO_DUP_FD 2
170
76ced9ad
NIS
171/* --------------------- Now prototypes for functions --------------- */
172
adb71456 173START_EXTERN_C
2c2e4525 174#ifndef __attribute__format__
b79c357a
RGS
175# ifdef HASATTRIBUTE_FORMAT
176# define __attribute__format__(x,y,z) __attribute__((format(x,y,z)))
177# else
178# define __attribute__format__(x,y,z)
179# endif
76ced9ad 180#endif
76ced9ad 181#ifndef PerlIO_init
fc6bde6f 182PERL_CALLCONV void PerlIO_init(pTHX);
76ced9ad
NIS
183#endif
184#ifndef PerlIO_stdoutf
fc6bde6f 185PERL_CALLCONV int PerlIO_stdoutf(const char *, ...)
287c8091 186 __attribute__format__(__printf__, 1, 2);
76ced9ad
NIS
187#endif
188#ifndef PerlIO_puts
fc6bde6f 189PERL_CALLCONV int PerlIO_puts(PerlIO *, const char *);
76ced9ad
NIS
190#endif
191#ifndef PerlIO_open
fc6bde6f 192PERL_CALLCONV PerlIO *PerlIO_open(const char *, const char *);
76ced9ad 193#endif
6e60e805 194#ifndef PerlIO_openn
fc6bde6f 195PERL_CALLCONV PerlIO *PerlIO_openn(pTHX_ const char *layers, const char *mode,
1604cfb0
MS
196 int fd, int imode, int perm, PerlIO *old,
197 int narg, SV **arg);
ee518936 198#endif
76ced9ad 199#ifndef PerlIO_eof
fc6bde6f 200PERL_CALLCONV int PerlIO_eof(PerlIO *);
76ced9ad
NIS
201#endif
202#ifndef PerlIO_error
fc6bde6f 203PERL_CALLCONV int PerlIO_error(PerlIO *);
76ced9ad
NIS
204#endif
205#ifndef PerlIO_clearerr
fc6bde6f 206PERL_CALLCONV void PerlIO_clearerr(PerlIO *);
76ced9ad
NIS
207#endif
208#ifndef PerlIO_getc
fc6bde6f 209PERL_CALLCONV int PerlIO_getc(PerlIO *);
76ced9ad
NIS
210#endif
211#ifndef PerlIO_putc
fc6bde6f 212PERL_CALLCONV int PerlIO_putc(PerlIO *, int);
76ced9ad 213#endif
76ced9ad 214#ifndef PerlIO_ungetc
fc6bde6f 215PERL_CALLCONV int PerlIO_ungetc(PerlIO *, int);
76ced9ad 216#endif
76ced9ad 217#ifndef PerlIO_fdopen
fc6bde6f 218PERL_CALLCONV PerlIO *PerlIO_fdopen(int, const char *);
76ced9ad
NIS
219#endif
220#ifndef PerlIO_importFILE
fc6bde6f 221PERL_CALLCONV PerlIO *PerlIO_importFILE(FILE *, const char *);
76ced9ad
NIS
222#endif
223#ifndef PerlIO_exportFILE
fc6bde6f 224PERL_CALLCONV FILE *PerlIO_exportFILE(PerlIO *, const char *);
76ced9ad
NIS
225#endif
226#ifndef PerlIO_findFILE
fc6bde6f 227PERL_CALLCONV FILE *PerlIO_findFILE(PerlIO *);
76ced9ad
NIS
228#endif
229#ifndef PerlIO_releaseFILE
fc6bde6f 230PERL_CALLCONV void PerlIO_releaseFILE(PerlIO *, FILE *);
76ced9ad
NIS
231#endif
232#ifndef PerlIO_read
fc6bde6f 233PERL_CALLCONV SSize_t PerlIO_read(PerlIO *, void *, Size_t);
76ced9ad 234#endif
a15cef0c 235#ifndef PerlIO_unread
fc6bde6f 236PERL_CALLCONV SSize_t PerlIO_unread(PerlIO *, const void *, Size_t);
a15cef0c 237#endif
76ced9ad 238#ifndef PerlIO_write
fc6bde6f 239PERL_CALLCONV SSize_t PerlIO_write(PerlIO *, const void *, Size_t);
76ced9ad
NIS
240#endif
241#ifndef PerlIO_setlinebuf
fc6bde6f 242PERL_CALLCONV void PerlIO_setlinebuf(PerlIO *);
76ced9ad
NIS
243#endif
244#ifndef PerlIO_printf
fc6bde6f 245PERL_CALLCONV int PerlIO_printf(PerlIO *, const char *, ...)
287c8091 246 __attribute__format__(__printf__, 2, 3);
76ced9ad 247#endif
76ced9ad 248#ifndef PerlIO_vprintf
fc6bde6f 249PERL_CALLCONV int PerlIO_vprintf(PerlIO *, const char *, va_list);
76ced9ad
NIS
250#endif
251#ifndef PerlIO_tell
fc6bde6f 252PERL_CALLCONV Off_t PerlIO_tell(PerlIO *);
76ced9ad
NIS
253#endif
254#ifndef PerlIO_seek
fc6bde6f 255PERL_CALLCONV int PerlIO_seek(PerlIO *, Off_t, int);
76ced9ad
NIS
256#endif
257#ifndef PerlIO_rewind
fc6bde6f 258PERL_CALLCONV void PerlIO_rewind(PerlIO *);
76ced9ad
NIS
259#endif
260#ifndef PerlIO_has_base
fc6bde6f 261PERL_CALLCONV int PerlIO_has_base(PerlIO *);
76ced9ad
NIS
262#endif
263#ifndef PerlIO_has_cntptr
fc6bde6f 264PERL_CALLCONV int PerlIO_has_cntptr(PerlIO *);
76ced9ad
NIS
265#endif
266#ifndef PerlIO_fast_gets
fc6bde6f 267PERL_CALLCONV int PerlIO_fast_gets(PerlIO *);
76ced9ad
NIS
268#endif
269#ifndef PerlIO_canset_cnt
fc6bde6f 270PERL_CALLCONV int PerlIO_canset_cnt(PerlIO *);
76ced9ad
NIS
271#endif
272#ifndef PerlIO_get_ptr
fc6bde6f 273PERL_CALLCONV STDCHAR *PerlIO_get_ptr(PerlIO *);
76ced9ad
NIS
274#endif
275#ifndef PerlIO_get_cnt
fc6bde6f 276PERL_CALLCONV SSize_t PerlIO_get_cnt(PerlIO *);
76ced9ad
NIS
277#endif
278#ifndef PerlIO_set_cnt
fc6bde6f 279PERL_CALLCONV void PerlIO_set_cnt(PerlIO *, SSize_t);
76ced9ad
NIS
280#endif
281#ifndef PerlIO_set_ptrcnt
fc6bde6f 282PERL_CALLCONV void PerlIO_set_ptrcnt(PerlIO *, STDCHAR *, SSize_t);
76ced9ad
NIS
283#endif
284#ifndef PerlIO_get_base
fc6bde6f 285PERL_CALLCONV STDCHAR *PerlIO_get_base(PerlIO *);
76ced9ad
NIS
286#endif
287#ifndef PerlIO_get_bufsiz
fc6bde6f 288PERL_CALLCONV SSize_t PerlIO_get_bufsiz(PerlIO *);
76ced9ad
NIS
289#endif
290#ifndef PerlIO_tmpfile
fc6bde6f 291PERL_CALLCONV PerlIO *PerlIO_tmpfile(void);
76ced9ad 292#endif
ae73d7ec
TC
293#ifndef PerlIO_tmpfile_flags
294PERL_CALLCONV PerlIO *PerlIO_tmpfile_flags(int flags);
295#endif
76ced9ad 296#ifndef PerlIO_stdin
fc6bde6f 297PERL_CALLCONV PerlIO *PerlIO_stdin(void);
76ced9ad
NIS
298#endif
299#ifndef PerlIO_stdout
fc6bde6f 300PERL_CALLCONV PerlIO *PerlIO_stdout(void);
76ced9ad
NIS
301#endif
302#ifndef PerlIO_stderr
fc6bde6f 303PERL_CALLCONV PerlIO *PerlIO_stderr(void);
76ced9ad
NIS
304#endif
305#ifndef PerlIO_getpos
fc6bde6f 306PERL_CALLCONV int PerlIO_getpos(PerlIO *, SV *);
76ced9ad
NIS
307#endif
308#ifndef PerlIO_setpos
fc6bde6f 309PERL_CALLCONV int PerlIO_setpos(PerlIO *, SV *);
76ced9ad
NIS
310#endif
311#ifndef PerlIO_fdupopen
fc6bde6f 312PERL_CALLCONV PerlIO *PerlIO_fdupopen(pTHX_ PerlIO *, CLONE_PARAMS *, int);
5f1a76d0 313#endif
786296d4 314#if !defined(PerlIO_modestr)
fc6bde6f 315PERL_CALLCONV char *PerlIO_modestr(PerlIO *, char *buf);
76ced9ad
NIS
316#endif
317#ifndef PerlIO_isutf8
fc6bde6f 318PERL_CALLCONV int PerlIO_isutf8(PerlIO *);
76ced9ad 319#endif
156e9b51 320#ifndef PerlIO_apply_layers
fc6bde6f 321PERL_CALLCONV int PerlIO_apply_layers(pTHX_ PerlIO *f, const char *mode,
1604cfb0 322 const char *names);
60382766
NIS
323#endif
324#ifndef PerlIO_binmode
fc6bde6f 325PERL_CALLCONV int PerlIO_binmode(pTHX_ PerlIO *f, int iotype, int omode,
1604cfb0 326 const char *names);
ac27b0f5 327#endif
a15cef0c 328#ifndef PerlIO_getname
fc6bde6f 329PERL_CALLCONV char *PerlIO_getname(PerlIO *, char *);
a15cef0c 330#endif
76ced9ad 331
fc6bde6f 332PERL_CALLCONV void PerlIO_destruct(pTHX);
13621cfb 333
fc6bde6f 334PERL_CALLCONV int PerlIO_intmode2str(int rawmode, char *mode, int *writing);
06c7082d 335
3a1ee7e8 336#ifdef PERLIO_LAYERS
fc6bde6f 337PERL_CALLCONV void PerlIO_cleanup(pTHX);
adb71456 338
fc6bde6f 339PERL_CALLCONV void PerlIO_debug(const char *fmt, ...)
de009b76 340 __attribute__format__(__printf__, 1, 2);
3a1ee7e8
NIS
341typedef struct PerlIO_list_s PerlIO_list_t;
342
11ae941d
CB
343#endif
344
adb71456 345END_EXTERN_C
6a5bc5ac 346#endif /* PERLIO_H_ */
e9a8c099
MHM
347
348/*
14d04a33 349 * ex: set ts=8 sts=4 sw=4 et:
e9a8c099 350 */