Commit | Line | Data |
---|---|---|
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: |
76ced9ad | 16 | USE_STDIO - forces PerlIO_xxx() to be #define-d onto stdio functions. |
c67aee7a | 17 | This is used for conservative |
76ced9ad NIS |
18 | builds - "just like perl5.00X used to be". |
19 | This dominates over the others. | |
20 | ||
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. | |
97cb92d6 | 24 | PerlIO_xxx() are real functions |
76ced9ad NIS |
25 | defined in perlio.c which implement extra functionality |
26 | required for utf8 support. | |
27 | ||
28 | One further note - the table-of-functions scheme controlled | |
29 | by PERL_IMPLICIT_SYS turns on USE_PERLIO so that iperlsys.h can | |
30 | #define PerlIO_xxx() to go via the function table, without having | |
31 | to #undef them from (say) stdio forms. | |
32 | ||
33 | */ | |
34 | ||
35 | #if defined(PERL_IMPLICIT_SYS) | |
36 | #ifndef USE_PERLIO | |
2986a63f | 37 | #ifndef NETWARE |
2cbbe5a1 | 38 | /* # define USE_PERLIO */ |
76ced9ad NIS |
39 | #endif |
40 | #endif | |
2986a63f | 41 | #endif |
76ced9ad NIS |
42 | |
43 | #ifndef USE_PERLIO | |
44 | # define USE_STDIO | |
45 | #endif | |
46 | ||
47 | #ifdef USE_STDIO | |
48 | # ifndef PERLIO_IS_STDIO | |
49 | # define PERLIO_IS_STDIO | |
50 | # endif | |
51 | #endif | |
52 | ||
53 | /* -------------------- End of Configure controls ---------------------------- */ | |
54 | ||
55 | /* | |
56 | * Although we may not want stdio to be used including <stdio.h> here | |
57 | * avoids issues where stdio.h has strange side effects | |
58 | */ | |
59 | #include <stdio.h> | |
60 | ||
61 | #if defined(USE_64_BIT_STDIO) && defined(HAS_FTELLO) && !defined(USE_FTELL64) | |
62 | #define ftell ftello | |
63 | #endif | |
64 | ||
65 | #if defined(USE_64_BIT_STDIO) && defined(HAS_FSEEKO) && !defined(USE_FSEEK64) | |
66 | #define fseek fseeko | |
67 | #endif | |
68 | ||
6f2bd249 JH |
69 | /* BS2000 includes are sometimes a bit non standard :-( */ |
70 | #if defined(POSIX_BC) && defined(O_BINARY) && !defined(O_TEXT) | |
71 | #undef O_BINARY | |
72 | #endif | |
73 | ||
76ced9ad NIS |
74 | #ifdef PERLIO_IS_STDIO |
75 | /* #define PerlIO_xxxx() as equivalent stdio function */ | |
76 | #include "perlsdio.h" | |
14a5cf38 | 77 | #endif /* PERLIO_IS_STDIO */ |
76ced9ad NIS |
78 | |
79 | #ifndef PerlIO | |
80 | /* ----------- PerlIO implementation ---------- */ | |
81 | /* PerlIO not #define-d to something else - define the implementation */ | |
82 | ||
83 | typedef struct _PerlIO PerlIOl; | |
84 | typedef struct _PerlIO_funcs PerlIO_funcs; | |
85 | typedef PerlIOl *PerlIO; | |
86 | #define PerlIO PerlIO | |
a1d180c4 | 87 | #define PERLIO_LAYERS 1 |
76ced9ad | 88 | |
f0e5c859 DD |
89 | /* PERLIO_FUNCS_CONST is now on by default for efficiency, PERLIO_FUNCS_CONST |
90 | can be removed 1 day once stable & then PerlIO vtables are permanently RO */ | |
27da23d5 JH |
91 | #ifdef PERLIO_FUNCS_CONST |
92 | #define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs | |
93 | #define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs) | |
94 | #else | |
95 | #define PERLIO_FUNCS_DECL(funcs) PerlIO_funcs funcs | |
96 | #define PERLIO_FUNCS_CAST(funcs) (funcs) | |
97 | #endif | |
98 | ||
99 | PERL_EXPORT_C void PerlIO_define_layer(pTHX_ PerlIO_funcs *tab); | |
100 | PERL_EXPORT_C PerlIO_funcs *PerlIO_find_layer(pTHX_ const char *name, | |
101 | STRLEN len, | |
102 | int load); | |
103 | PERL_EXPORT_C PerlIO *PerlIO_push(pTHX_ PerlIO *f, PERLIO_FUNCS_DECL(*tab), | |
104 | const char *mode, SV *arg); | |
105 | PERL_EXPORT_C void PerlIO_pop(pTHX_ PerlIO *f); | |
106 | PERL_EXPORT_C AV* PerlIO_get_layers(pTHX_ PerlIO *f); | |
107 | PERL_EXPORT_C void PerlIO_clone(pTHX_ PerlInterpreter *proto, | |
108 | CLONE_PARAMS *param); | |
76ced9ad | 109 | |
14a5cf38 | 110 | #endif /* PerlIO */ |
76ced9ad NIS |
111 | |
112 | /* ----------- End of implementation choices ---------- */ | |
113 | ||
114 | #ifndef PERLIO_IS_STDIO | |
115 | /* Not using stdio _directly_ as PerlIO */ | |
116 | ||
117 | /* We now need to determine what happens if source trys to use stdio. | |
118 | * There are three cases based on PERLIO_NOT_STDIO which XS code | |
119 | * can set how it wants. | |
120 | */ | |
121 | ||
bb02e0c1 | 122 | # ifdef PERL_CORE |
76ced9ad NIS |
123 | /* Make a choice for perl core code |
124 | - currently this is set to try and catch lingering raw stdio calls. | |
125 | This is a known issue with some non UNIX ports which still use | |
126 | "native" stdio features. | |
127 | */ | |
bb02e0c1 KW |
128 | # ifndef PERLIO_NOT_STDIO |
129 | # define PERLIO_NOT_STDIO 1 | |
130 | # endif | |
131 | #else | |
132 | # ifndef PERLIO_NOT_STDIO | |
133 | # define PERLIO_NOT_STDIO 0 | |
134 | # endif | |
76ced9ad NIS |
135 | #endif |
136 | ||
137 | #ifdef PERLIO_NOT_STDIO | |
138 | #if PERLIO_NOT_STDIO | |
139 | /* | |
140 | * PERLIO_NOT_STDIO #define'd as 1 | |
141 | * Case 1: Strong denial of stdio - make all stdio calls (we can think of) errors | |
142 | */ | |
143 | #include "nostdio.h" | |
14a5cf38 | 144 | #else /* if PERLIO_NOT_STDIO */ |
76ced9ad NIS |
145 | /* |
146 | * PERLIO_NOT_STDIO #define'd as 0 | |
147 | * Case 2: Declares that both PerlIO and stdio can be used | |
148 | */ | |
14a5cf38 JH |
149 | #endif /* if PERLIO_NOT_STDIO */ |
150 | #else /* ifdef PERLIO_NOT_STDIO */ | |
76ced9ad NIS |
151 | /* |
152 | * PERLIO_NOT_STDIO not defined | |
153 | * Case 3: Try and fake stdio calls as PerlIO calls | |
154 | */ | |
155 | #include "fakesdio.h" | |
14a5cf38 JH |
156 | #endif /* ifndef PERLIO_NOT_STDIO */ |
157 | #endif /* PERLIO_IS_STDIO */ | |
76ced9ad NIS |
158 | |
159 | /* ----------- fill in things that have not got #define'd ---------- */ | |
160 | ||
161 | #ifndef Fpos_t | |
162 | #define Fpos_t Off_t | |
163 | #endif | |
164 | ||
165 | #ifndef EOF | |
166 | #define EOF (-1) | |
167 | #endif | |
168 | ||
169 | /* This is to catch case with no stdio */ | |
170 | #ifndef BUFSIZ | |
171 | #define BUFSIZ 1024 | |
172 | #endif | |
173 | ||
1810cd7c CB |
174 | /* The default buffer size for the perlio buffering layer */ |
175 | #ifndef PERLIOBUF_DEFAULT_BUFSIZ | |
b83080de | 176 | #define PERLIOBUF_DEFAULT_BUFSIZ (BUFSIZ > 8192 ? BUFSIZ : 8192) |
a3cbd8d0 CB |
177 | #endif |
178 | ||
76ced9ad NIS |
179 | #ifndef SEEK_SET |
180 | #define SEEK_SET 0 | |
181 | #endif | |
182 | ||
183 | #ifndef SEEK_CUR | |
184 | #define SEEK_CUR 1 | |
185 | #endif | |
186 | ||
187 | #ifndef SEEK_END | |
188 | #define SEEK_END 2 | |
189 | #endif | |
190 | ||
ecdeb87c NIS |
191 | #define PERLIO_DUP_CLONE 1 |
192 | #define PERLIO_DUP_FD 2 | |
193 | ||
76ced9ad NIS |
194 | /* --------------------- Now prototypes for functions --------------- */ |
195 | ||
adb71456 | 196 | START_EXTERN_C |
2c2e4525 | 197 | #ifndef __attribute__format__ |
b79c357a RGS |
198 | # ifdef HASATTRIBUTE_FORMAT |
199 | # define __attribute__format__(x,y,z) __attribute__((format(x,y,z))) | |
200 | # else | |
201 | # define __attribute__format__(x,y,z) | |
202 | # endif | |
76ced9ad | 203 | #endif |
76ced9ad | 204 | #ifndef PerlIO_init |
27da23d5 | 205 | PERL_EXPORT_C void PerlIO_init(pTHX); |
76ced9ad NIS |
206 | #endif |
207 | #ifndef PerlIO_stdoutf | |
27da23d5 | 208 | PERL_EXPORT_C int PerlIO_stdoutf(const char *, ...) |
287c8091 | 209 | __attribute__format__(__printf__, 1, 2); |
76ced9ad NIS |
210 | #endif |
211 | #ifndef PerlIO_puts | |
27da23d5 | 212 | PERL_EXPORT_C int PerlIO_puts(PerlIO *, const char *); |
76ced9ad NIS |
213 | #endif |
214 | #ifndef PerlIO_open | |
27da23d5 | 215 | PERL_EXPORT_C PerlIO *PerlIO_open(const char *, const char *); |
76ced9ad | 216 | #endif |
6e60e805 | 217 | #ifndef PerlIO_openn |
27da23d5 JH |
218 | PERL_EXPORT_C PerlIO *PerlIO_openn(pTHX_ const char *layers, const char *mode, |
219 | int fd, int imode, int perm, PerlIO *old, | |
220 | int narg, SV **arg); | |
ee518936 | 221 | #endif |
76ced9ad | 222 | #ifndef PerlIO_eof |
27da23d5 | 223 | PERL_EXPORT_C int PerlIO_eof(PerlIO *); |
76ced9ad NIS |
224 | #endif |
225 | #ifndef PerlIO_error | |
27da23d5 | 226 | PERL_EXPORT_C int PerlIO_error(PerlIO *); |
76ced9ad NIS |
227 | #endif |
228 | #ifndef PerlIO_clearerr | |
27da23d5 | 229 | PERL_EXPORT_C void PerlIO_clearerr(PerlIO *); |
76ced9ad NIS |
230 | #endif |
231 | #ifndef PerlIO_getc | |
27da23d5 | 232 | PERL_EXPORT_C int PerlIO_getc(PerlIO *); |
76ced9ad NIS |
233 | #endif |
234 | #ifndef PerlIO_putc | |
27da23d5 | 235 | PERL_EXPORT_C int PerlIO_putc(PerlIO *, int); |
76ced9ad | 236 | #endif |
76ced9ad | 237 | #ifndef PerlIO_ungetc |
27da23d5 | 238 | PERL_EXPORT_C int PerlIO_ungetc(PerlIO *, int); |
76ced9ad | 239 | #endif |
76ced9ad | 240 | #ifndef PerlIO_fdopen |
27da23d5 | 241 | PERL_EXPORT_C PerlIO *PerlIO_fdopen(int, const char *); |
76ced9ad NIS |
242 | #endif |
243 | #ifndef PerlIO_importFILE | |
27da23d5 | 244 | PERL_EXPORT_C PerlIO *PerlIO_importFILE(FILE *, const char *); |
76ced9ad NIS |
245 | #endif |
246 | #ifndef PerlIO_exportFILE | |
27da23d5 | 247 | PERL_EXPORT_C FILE *PerlIO_exportFILE(PerlIO *, const char *); |
76ced9ad NIS |
248 | #endif |
249 | #ifndef PerlIO_findFILE | |
27da23d5 | 250 | PERL_EXPORT_C FILE *PerlIO_findFILE(PerlIO *); |
76ced9ad NIS |
251 | #endif |
252 | #ifndef PerlIO_releaseFILE | |
27da23d5 | 253 | PERL_EXPORT_C void PerlIO_releaseFILE(PerlIO *, FILE *); |
76ced9ad NIS |
254 | #endif |
255 | #ifndef PerlIO_read | |
27da23d5 | 256 | PERL_EXPORT_C SSize_t PerlIO_read(PerlIO *, void *, Size_t); |
76ced9ad | 257 | #endif |
a15cef0c | 258 | #ifndef PerlIO_unread |
27da23d5 | 259 | PERL_EXPORT_C SSize_t PerlIO_unread(PerlIO *, const void *, Size_t); |
a15cef0c | 260 | #endif |
76ced9ad | 261 | #ifndef PerlIO_write |
27da23d5 | 262 | PERL_EXPORT_C SSize_t PerlIO_write(PerlIO *, const void *, Size_t); |
76ced9ad NIS |
263 | #endif |
264 | #ifndef PerlIO_setlinebuf | |
27da23d5 | 265 | PERL_EXPORT_C void PerlIO_setlinebuf(PerlIO *); |
76ced9ad NIS |
266 | #endif |
267 | #ifndef PerlIO_printf | |
27da23d5 | 268 | PERL_EXPORT_C int PerlIO_printf(PerlIO *, const char *, ...) |
287c8091 | 269 | __attribute__format__(__printf__, 2, 3); |
76ced9ad | 270 | #endif |
76ced9ad | 271 | #ifndef PerlIO_vprintf |
27da23d5 | 272 | PERL_EXPORT_C int PerlIO_vprintf(PerlIO *, const char *, va_list); |
76ced9ad NIS |
273 | #endif |
274 | #ifndef PerlIO_tell | |
27da23d5 | 275 | PERL_EXPORT_C Off_t PerlIO_tell(PerlIO *); |
76ced9ad NIS |
276 | #endif |
277 | #ifndef PerlIO_seek | |
27da23d5 | 278 | PERL_EXPORT_C int PerlIO_seek(PerlIO *, Off_t, int); |
76ced9ad NIS |
279 | #endif |
280 | #ifndef PerlIO_rewind | |
27da23d5 | 281 | PERL_EXPORT_C void PerlIO_rewind(PerlIO *); |
76ced9ad NIS |
282 | #endif |
283 | #ifndef PerlIO_has_base | |
27da23d5 | 284 | PERL_EXPORT_C int PerlIO_has_base(PerlIO *); |
76ced9ad NIS |
285 | #endif |
286 | #ifndef PerlIO_has_cntptr | |
27da23d5 | 287 | PERL_EXPORT_C int PerlIO_has_cntptr(PerlIO *); |
76ced9ad NIS |
288 | #endif |
289 | #ifndef PerlIO_fast_gets | |
27da23d5 | 290 | PERL_EXPORT_C int PerlIO_fast_gets(PerlIO *); |
76ced9ad NIS |
291 | #endif |
292 | #ifndef PerlIO_canset_cnt | |
27da23d5 | 293 | PERL_EXPORT_C int PerlIO_canset_cnt(PerlIO *); |
76ced9ad NIS |
294 | #endif |
295 | #ifndef PerlIO_get_ptr | |
27da23d5 | 296 | PERL_EXPORT_C STDCHAR *PerlIO_get_ptr(PerlIO *); |
76ced9ad NIS |
297 | #endif |
298 | #ifndef PerlIO_get_cnt | |
b66f3475 | 299 | PERL_EXPORT_C SSize_t PerlIO_get_cnt(PerlIO *); |
76ced9ad NIS |
300 | #endif |
301 | #ifndef PerlIO_set_cnt | |
b66f3475 | 302 | PERL_EXPORT_C void PerlIO_set_cnt(PerlIO *, SSize_t); |
76ced9ad NIS |
303 | #endif |
304 | #ifndef PerlIO_set_ptrcnt | |
b66f3475 | 305 | PERL_EXPORT_C void PerlIO_set_ptrcnt(PerlIO *, STDCHAR *, SSize_t); |
76ced9ad NIS |
306 | #endif |
307 | #ifndef PerlIO_get_base | |
27da23d5 | 308 | PERL_EXPORT_C STDCHAR *PerlIO_get_base(PerlIO *); |
76ced9ad NIS |
309 | #endif |
310 | #ifndef PerlIO_get_bufsiz | |
b66f3475 | 311 | PERL_EXPORT_C SSize_t PerlIO_get_bufsiz(PerlIO *); |
76ced9ad NIS |
312 | #endif |
313 | #ifndef PerlIO_tmpfile | |
27da23d5 | 314 | PERL_EXPORT_C PerlIO *PerlIO_tmpfile(void); |
76ced9ad NIS |
315 | #endif |
316 | #ifndef PerlIO_stdin | |
27da23d5 | 317 | PERL_EXPORT_C PerlIO *PerlIO_stdin(void); |
76ced9ad NIS |
318 | #endif |
319 | #ifndef PerlIO_stdout | |
27da23d5 | 320 | PERL_EXPORT_C PerlIO *PerlIO_stdout(void); |
76ced9ad NIS |
321 | #endif |
322 | #ifndef PerlIO_stderr | |
27da23d5 | 323 | PERL_EXPORT_C PerlIO *PerlIO_stderr(void); |
76ced9ad NIS |
324 | #endif |
325 | #ifndef PerlIO_getpos | |
27da23d5 | 326 | PERL_EXPORT_C int PerlIO_getpos(PerlIO *, SV *); |
76ced9ad NIS |
327 | #endif |
328 | #ifndef PerlIO_setpos | |
27da23d5 | 329 | PERL_EXPORT_C int PerlIO_setpos(PerlIO *, SV *); |
76ced9ad NIS |
330 | #endif |
331 | #ifndef PerlIO_fdupopen | |
27da23d5 | 332 | PERL_EXPORT_C PerlIO *PerlIO_fdupopen(pTHX_ PerlIO *, CLONE_PARAMS *, int); |
5f1a76d0 | 333 | #endif |
11ae941d | 334 | #if !defined(PerlIO_modestr) && !defined(PERLIO_IS_STDIO) |
27da23d5 | 335 | PERL_EXPORT_C char *PerlIO_modestr(PerlIO *, char *buf); |
76ced9ad NIS |
336 | #endif |
337 | #ifndef PerlIO_isutf8 | |
27da23d5 | 338 | PERL_EXPORT_C int PerlIO_isutf8(PerlIO *); |
76ced9ad | 339 | #endif |
156e9b51 | 340 | #ifndef PerlIO_apply_layers |
27da23d5 JH |
341 | PERL_EXPORT_C int PerlIO_apply_layers(pTHX_ PerlIO *f, const char *mode, |
342 | const char *names); | |
60382766 NIS |
343 | #endif |
344 | #ifndef PerlIO_binmode | |
27da23d5 JH |
345 | PERL_EXPORT_C int PerlIO_binmode(pTHX_ PerlIO *f, int iotype, int omode, |
346 | const char *names); | |
ac27b0f5 | 347 | #endif |
a15cef0c | 348 | #ifndef PerlIO_getname |
27da23d5 | 349 | PERL_EXPORT_C char *PerlIO_getname(PerlIO *, char *); |
a15cef0c | 350 | #endif |
76ced9ad | 351 | |
27da23d5 | 352 | PERL_EXPORT_C void PerlIO_destruct(pTHX); |
13621cfb | 353 | |
27da23d5 | 354 | PERL_EXPORT_C int PerlIO_intmode2str(int rawmode, char *mode, int *writing); |
06c7082d | 355 | |
3a1ee7e8 | 356 | #ifdef PERLIO_LAYERS |
27da23d5 | 357 | PERL_EXPORT_C void PerlIO_cleanup(pTHX); |
adb71456 | 358 | |
de009b76 AL |
359 | PERL_EXPORT_C void PerlIO_debug(const char *fmt, ...) |
360 | __attribute__format__(__printf__, 1, 2); | |
3a1ee7e8 NIS |
361 | typedef struct PerlIO_list_s PerlIO_list_t; |
362 | ||
88b61e10 | 363 | |
11ae941d CB |
364 | #endif |
365 | ||
adb71456 | 366 | END_EXTERN_C |
14a5cf38 | 367 | #endif /* _PERLIO_H */ |
e9a8c099 MHM |
368 | |
369 | /* | |
370 | * Local variables: | |
371 | * c-indentation-style: bsd | |
372 | * c-basic-offset: 4 | |
14d04a33 | 373 | * indent-tabs-mode: nil |
e9a8c099 MHM |
374 | * End: |
375 | * | |
14d04a33 | 376 | * ex: set ts=8 sts=4 sw=4 et: |
e9a8c099 | 377 | */ |