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