summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl/perlio.h
blob: dd1e3d51a09dec9dfb43a062d6a9506d0319635e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/*    perlio.h
 *
 *    Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003,
 *    by Larry Wall and others
 *
 *    You may distribute under the terms of either the GNU General Public
 *    License or the Artistic License, as specified in the README file.
 *
 */

#ifndef _PERLIO_H
#define _PERLIO_H
/*
  Interface for perl to IO functions.
  There is a hierachy of Configure determined #define controls:
   USE_STDIO   - forces PerlIO_xxx() to be #define-d onto stdio functions.
                 This is used for x2p subdirectory and for conservative
                 builds - "just like perl5.00X used to be".
                 This dominates over the others.

   USE_PERLIO  - The primary Configure variable that enables PerlIO.
                 If USE_PERLIO is _NOT_ set
                   then USE_STDIO above will be set to be conservative.
                 If USE_PERLIO is set
                   then there are two modes determined by USE_SFIO:

   USE_SFIO    - If set causes PerlIO_xxx() to be #define-d onto sfio functions.
                 A backward compatability mode for some specialist applications.

                 If USE_SFIO is not set then PerlIO_xxx() are real functions
                 defined in perlio.c which implement extra functionality
                 required for utf8 support.

   One further note - the table-of-functions scheme controlled
   by PERL_IMPLICIT_SYS turns on USE_PERLIO so that iperlsys.h can
   #define PerlIO_xxx() to go via the function table, without having
   to #undef them from (say) stdio forms.

*/

#if defined(PERL_IMPLICIT_SYS)
#ifndef USE_PERLIO
#ifndef NETWARE
/* # define USE_PERLIO */
#endif
#endif
#endif

#ifndef USE_PERLIO
# define USE_STDIO
#endif

#ifdef USE_STDIO
#  ifndef PERLIO_IS_STDIO
#      define PERLIO_IS_STDIO
#  endif
#endif

/* --------------------  End of Configure controls ---------------------------- */

/*
 * Although we may not want stdio to be used including <stdio.h> here
 * avoids issues where stdio.h has strange side effects
 */
#include <stdio.h>

#ifdef __BEOS__
int fseeko(FILE *stream, off_t offset, int whence);
off_t ftello(FILE *stream);
#endif

#if defined(USE_64_BIT_STDIO) && defined(HAS_FTELLO) && !defined(USE_FTELL64)
#define ftell ftello
#endif

#if defined(USE_64_BIT_STDIO) && defined(HAS_FSEEKO) && !defined(USE_FSEEK64)
#define fseek fseeko
#endif

/* BS2000 includes are sometimes a bit non standard :-( */
#if defined(POSIX_BC) && defined(O_BINARY) && !defined(O_TEXT)
#undef O_BINARY
#endif

#ifdef PERLIO_IS_STDIO
/* #define PerlIO_xxxx() as equivalent stdio function */
#include "perlsdio.h"
#else				/* PERLIO_IS_STDIO */
#ifdef USE_SFIO
/* #define PerlIO_xxxx() as equivalent sfio function */
#include "perlsfio.h"
#endif				/* USE_SFIO */
#endif				/* PERLIO_IS_STDIO */

#ifndef PerlIO
/* ----------- PerlIO implementation ---------- */
/* PerlIO not #define-d to something else - define the implementation */

typedef struct _PerlIO PerlIOl;
typedef struct _PerlIO_funcs PerlIO_funcs;
typedef PerlIOl *PerlIO;
#define PerlIO PerlIO
#define PERLIO_LAYERS 1

extern void PerlIO_define_layer(pTHX_ PerlIO_funcs *tab);
extern PerlIO_funcs *PerlIO_find_layer(pTHX_ const char *name, STRLEN len,
				       int load);
extern PerlIO *PerlIO_push(pTHX_ PerlIO *f, PerlIO_funcs *tab,
			   const char *mode, SV *arg);
extern void PerlIO_pop(pTHX_ PerlIO *f);
extern AV* PerlIO_get_layers(pTHX_ PerlIO *f);
extern void PerlIO_clone(pTHX_ PerlInterpreter *proto, CLONE_PARAMS *param);

#endif				/* PerlIO */

/* ----------- End of implementation choices  ---------- */

#ifndef PERLIO_IS_STDIO
/* Not using stdio _directly_ as PerlIO */

/* We now need to determine  what happens if source trys to use stdio.
 * There are three cases based on PERLIO_NOT_STDIO which XS code
 * can set how it wants.
 */

#ifdef PERL_CORE
/* Make a choice for perl core code
   - currently this is set to try and catch lingering raw stdio calls.
     This is a known issue with some non UNIX ports which still use
     "native" stdio features.
*/
#ifndef PERLIO_NOT_STDIO
#define PERLIO_NOT_STDIO 1
#endif
#else
#ifndef PERLIO_NOT_STDIO
#define PERLIO_NOT_STDIO 0
#endif
#endif

#ifdef PERLIO_NOT_STDIO
#if PERLIO_NOT_STDIO
/*
 * PERLIO_NOT_STDIO #define'd as 1
 * Case 1: Strong denial of stdio - make all stdio calls (we can think of) errors
 */
#include "nostdio.h"
#else				/* if PERLIO_NOT_STDIO */
/*
 * PERLIO_NOT_STDIO #define'd as 0
 * Case 2: Declares that both PerlIO and stdio can be used
 */
#endif				/* if PERLIO_NOT_STDIO */
#else				/* ifdef PERLIO_NOT_STDIO */
/*
 * PERLIO_NOT_STDIO not defined
 * Case 3: Try and fake stdio calls as PerlIO calls
 */
#include "fakesdio.h"
#endif				/* ifndef PERLIO_NOT_STDIO */
#endif				/* PERLIO_IS_STDIO */

#define specialCopIO(sv) ((sv) == Nullsv)

/* ----------- fill in things that have not got #define'd  ---------- */

#ifndef Fpos_t
#define Fpos_t Off_t
#endif

#ifndef EOF
#define EOF (-1)
#endif

/* This is to catch case with no stdio */
#ifndef BUFSIZ
#define BUFSIZ 1024
#endif

#ifndef SEEK_SET
#define SEEK_SET 0
#endif

#ifndef SEEK_CUR
#define SEEK_CUR 1
#endif

#ifndef SEEK_END
#define SEEK_END 2
#endif

#define PERLIO_DUP_CLONE	1
#define PERLIO_DUP_FD		2

/* --------------------- Now prototypes for functions --------------- */

START_EXTERN_C
#ifndef __attribute__format__
#ifdef CHECK_FORMAT
#define __attribute__format__(x,y,z) __attribute__((__format__(x,y,z)))
#else
#define __attribute__format__(x,y,z)
#endif
#endif
#ifndef NEXT30_NO_ATTRIBUTE
#ifndef HASATTRIBUTE		/* disable GNU-cc attribute checking? */
#ifdef  __attribute__		/* Avoid possible redefinition errors */
#undef  __attribute__
#endif
#define __attribute__(attr)
#endif
#endif
#ifndef PerlIO_init
extern void PerlIO_init(pTHX);
#endif
#ifndef PerlIO_stdoutf
extern int PerlIO_stdoutf(const char *, ...)
    __attribute__format__(__printf__, 1, 2);
#endif
#ifndef PerlIO_puts
extern int PerlIO_puts(PerlIO *, const char *);
#endif
#ifndef PerlIO_open
extern PerlIO *PerlIO_open(const char *, const char *);
#endif
#ifndef PerlIO_openn
extern PerlIO *PerlIO_openn(pTHX_ const char *layers, const char *mode,
			    int fd, int imode, int perm, PerlIO *old,
			    int narg, SV **arg);
#endif
#ifndef PerlIO_eof
extern int PerlIO_eof(PerlIO *);
#endif
#ifndef PerlIO_error
extern int PerlIO_error(PerlIO *);
#endif
#ifndef PerlIO_clearerr
extern void PerlIO_clearerr(PerlIO *);
#endif
#ifndef PerlIO_getc
extern int PerlIO_getc(PerlIO *);
#endif
#ifndef PerlIO_putc
extern int PerlIO_putc(PerlIO *, int);
#endif
#ifndef PerlIO_ungetc
extern int PerlIO_ungetc(PerlIO *, int);
#endif
#ifndef PerlIO_fdopen
extern PerlIO *PerlIO_fdopen(int, const char *);
#endif
#ifndef PerlIO_importFILE
extern PerlIO *PerlIO_importFILE(FILE *, const char *);
#endif
#ifndef PerlIO_exportFILE
extern FILE *PerlIO_exportFILE(PerlIO *, const char *);
#endif
#ifndef PerlIO_findFILE
extern FILE *PerlIO_findFILE(PerlIO *);
#endif
#ifndef PerlIO_releaseFILE
extern void PerlIO_releaseFILE(PerlIO *, FILE *);
#endif
#ifndef PerlIO_read
extern SSize_t PerlIO_read(PerlIO *, void *, Size_t);
#endif
#ifndef PerlIO_unread
extern SSize_t PerlIO_unread(PerlIO *, const void *, Size_t);
#endif
#ifndef PerlIO_write
extern SSize_t PerlIO_write(PerlIO *, const void *, Size_t);
#endif
#ifndef PerlIO_setlinebuf
extern void PerlIO_setlinebuf(PerlIO *);
#endif
#ifndef PerlIO_printf
extern int PerlIO_printf(PerlIO *, const char *, ...)
    __attribute__format__(__printf__, 2, 3);
#endif
#ifndef PerlIO_sprintf
extern int PerlIO_sprintf(char *, int, const char *, ...)
    __attribute__format__(__printf__, 3, 4);
#endif
#ifndef PerlIO_vprintf
extern int PerlIO_vprintf(PerlIO *, const char *, va_list);
#endif
#ifndef PerlIO_tell
extern Off_t PerlIO_tell(PerlIO *);
#endif
#ifndef PerlIO_seek
extern int PerlIO_seek(PerlIO *, Off_t, int);
#endif
#ifndef PerlIO_rewind
extern void PerlIO_rewind(PerlIO *);
#endif
#ifndef PerlIO_has_base
extern int PerlIO_has_base(PerlIO *);
#endif
#ifndef PerlIO_has_cntptr
extern int PerlIO_has_cntptr(PerlIO *);
#endif
#ifndef PerlIO_fast_gets
extern int PerlIO_fast_gets(PerlIO *);
#endif
#ifndef PerlIO_canset_cnt
extern int PerlIO_canset_cnt(PerlIO *);
#endif
#ifndef PerlIO_get_ptr
extern STDCHAR *PerlIO_get_ptr(PerlIO *);
#endif
#ifndef PerlIO_get_cnt
extern int PerlIO_get_cnt(PerlIO *);
#endif
#ifndef PerlIO_set_cnt
extern void PerlIO_set_cnt(PerlIO *, int);
#endif
#ifndef PerlIO_set_ptrcnt
extern void PerlIO_set_ptrcnt(PerlIO *, STDCHAR *, int);
#endif
#ifndef PerlIO_get_base
extern STDCHAR *PerlIO_get_base(PerlIO *);
#endif
#ifndef PerlIO_get_bufsiz
extern int PerlIO_get_bufsiz(PerlIO *);
#endif
#ifndef PerlIO_tmpfile
extern PerlIO *PerlIO_tmpfile(void);
#endif
#ifndef PerlIO_stdin
extern PerlIO *PerlIO_stdin(void);
#endif
#ifndef PerlIO_stdout
extern PerlIO *PerlIO_stdout(void);
#endif
#ifndef PerlIO_stderr
extern PerlIO *PerlIO_stderr(void);
#endif
#ifndef PerlIO_getpos
extern int PerlIO_getpos(PerlIO *, SV *);
#endif
#ifndef PerlIO_setpos
extern int PerlIO_setpos(PerlIO *, SV *);
#endif
#ifndef PerlIO_fdupopen
extern PerlIO *PerlIO_fdupopen(pTHX_ PerlIO *, CLONE_PARAMS *, int);
#endif
#if !defined(PerlIO_modestr) && !defined(PERLIO_IS_STDIO)
extern char *PerlIO_modestr(PerlIO *, char *buf);
#endif
#ifndef PerlIO_isutf8
extern int PerlIO_isutf8(PerlIO *);
#endif
#ifndef PerlIO_apply_layers
extern int PerlIO_apply_layers(pTHX_ PerlIO *f, const char *mode,
			       const char *names);
#endif
#ifndef PerlIO_binmode
extern int PerlIO_binmode(pTHX_ PerlIO *f, int iotype, int omode,
			  const char *names);
#endif
#ifndef PerlIO_getname
extern char *PerlIO_getname(PerlIO *, char *);
#endif

extern void PerlIO_destruct(pTHX);

extern int PerlIO_intmode2str(int rawmode, char *mode, int *writing);

#ifdef PERLIO_LAYERS
extern void PerlIO_cleanup(pTHX);

extern void PerlIO_debug(const char *fmt, ...);
typedef struct PerlIO_list_s PerlIO_list_t;


#endif

END_EXTERN_C
#endif				/* _PERLIO_H */