1 /* perlio.h 2 * 3 * Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 4 * 2004, 2005, 2006, 2007, by Larry Wall and others 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 11 #ifndef PERLIO_H_ 12 #define PERLIO_H_ 13 /* 14 Interface for perl to IO functions. 15 There is a hierarchy of Configure determined #define controls: 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. 19 20 USE_PERLIO - The primary Configure variable that enables PerlIO. 21 PerlIO_xxx() are real functions 22 defined in perlio.c which implement extra functionality 23 required for utf8 support. 24 25 */ 26 27 #ifndef USE_PERLIO 28 # define USE_STDIO 29 #endif 30 31 #ifdef USE_STDIO 32 # error "stdio is no longer supported as the default base layer -- use perlio." 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 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 56 #ifndef PerlIO 57 /* ----------- PerlIO implementation ---------- */ 58 /* PerlIO not #define-d to something else - define the implementation */ 59 60 typedef struct _PerlIO PerlIOl; 61 typedef struct _PerlIO_funcs PerlIO_funcs; 62 typedef PerlIOl *PerlIO; 63 #define PerlIO PerlIO 64 #define PERLIO_LAYERS 1 65 66 /* 67 =for apidoc_section $io 68 =for apidoc Amu||PERLIO_FUNCS_DECL|PerlIO * ftab 69 Declare C<ftab> to be a PerlIO function table, that is, of type 70 C<PerlIO_funcs>. 71 72 =for apidoc Ay|PerlIO_funcs *|PERLIO_FUNCS_CAST|PerlIO * func 73 Cast the pointer C<func> to be of type S<C<PerlIO_funcs *>>. 74 75 =cut 76 */ 77 #define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs 78 #define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs) 79 80 PERL_CALLCONV void PerlIO_define_layer(pTHX_ PerlIO_funcs *tab); 81 PERL_CALLCONV PerlIO_funcs *PerlIO_find_layer(pTHX_ const char *name, 82 STRLEN len, 83 int load); 84 PERL_CALLCONV PerlIO *PerlIO_push(pTHX_ PerlIO *f, PERLIO_FUNCS_DECL(*tab), 85 const char *mode, SV *arg); 86 PERL_CALLCONV void PerlIO_pop(pTHX_ PerlIO *f); 87 PERL_CALLCONV AV* PerlIO_get_layers(pTHX_ PerlIO *f); 88 PERL_CALLCONV void PerlIO_clone(pTHX_ PerlInterpreter *proto, 89 CLONE_PARAMS *param); 90 91 #endif /* PerlIO */ 92 93 /* ----------- End of implementation choices ---------- */ 94 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 100 #ifdef PERL_CORE 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 */ 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 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" 122 #else /* if PERLIO_NOT_STDIO */ 123 /* 124 * PERLIO_NOT_STDIO #define'd as 0 125 * Case 2: Declares that both PerlIO and stdio can be used 126 */ 127 #endif /* if PERLIO_NOT_STDIO */ 128 #else /* ifdef PERLIO_NOT_STDIO */ 129 /* 130 * PERLIO_NOT_STDIO not defined 131 * Case 3: Try and fake stdio calls as PerlIO calls 132 */ 133 #include "fakesdio.h" 134 #endif /* ifndef PERLIO_NOT_STDIO */ 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 151 /* The default buffer size for the perlio buffering layer */ 152 #ifndef PERLIOBUF_DEFAULT_BUFSIZ 153 #define PERLIOBUF_DEFAULT_BUFSIZ (BUFSIZ > 8192 ? BUFSIZ : 8192) 154 #endif 155 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 168 #define PERLIO_DUP_CLONE 1 169 #define PERLIO_DUP_FD 2 170 171 /* --------------------- Now prototypes for functions --------------- */ 172 173 START_EXTERN_C 174 #ifndef __attribute__format__ 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 180 #endif 181 #ifndef PerlIO_init 182 PERL_CALLCONV void PerlIO_init(pTHX); 183 #endif 184 #ifndef PerlIO_stdoutf 185 PERL_CALLCONV int PerlIO_stdoutf(const char *, ...) 186 __attribute__format__(__printf__, 1, 2); 187 #endif 188 #ifndef PerlIO_puts 189 PERL_CALLCONV int PerlIO_puts(PerlIO *, const char *); 190 #endif 191 #ifndef PerlIO_open 192 PERL_CALLCONV PerlIO *PerlIO_open(const char *, const char *); 193 #endif 194 #ifndef PerlIO_openn 195 PERL_CALLCONV PerlIO *PerlIO_openn(pTHX_ const char *layers, const char *mode, 196 int fd, int imode, int perm, PerlIO *old, 197 int narg, SV **arg); 198 #endif 199 #ifndef PerlIO_eof 200 PERL_CALLCONV int PerlIO_eof(PerlIO *); 201 #endif 202 #ifndef PerlIO_error 203 PERL_CALLCONV int PerlIO_error(PerlIO *); 204 #endif 205 #ifndef PerlIO_clearerr 206 PERL_CALLCONV void PerlIO_clearerr(PerlIO *); 207 #endif 208 #ifndef PerlIO_getc 209 PERL_CALLCONV int PerlIO_getc(PerlIO *); 210 #endif 211 #ifndef PerlIO_putc 212 PERL_CALLCONV int PerlIO_putc(PerlIO *, int); 213 #endif 214 #ifndef PerlIO_ungetc 215 PERL_CALLCONV int PerlIO_ungetc(PerlIO *, int); 216 #endif 217 #ifndef PerlIO_fdopen 218 PERL_CALLCONV PerlIO *PerlIO_fdopen(int, const char *); 219 #endif 220 #ifndef PerlIO_importFILE 221 PERL_CALLCONV PerlIO *PerlIO_importFILE(FILE *, const char *); 222 #endif 223 #ifndef PerlIO_exportFILE 224 PERL_CALLCONV FILE *PerlIO_exportFILE(PerlIO *, const char *); 225 #endif 226 #ifndef PerlIO_findFILE 227 PERL_CALLCONV FILE *PerlIO_findFILE(PerlIO *); 228 #endif 229 #ifndef PerlIO_releaseFILE 230 PERL_CALLCONV void PerlIO_releaseFILE(PerlIO *, FILE *); 231 #endif 232 #ifndef PerlIO_read 233 PERL_CALLCONV SSize_t PerlIO_read(PerlIO *, void *, Size_t); 234 #endif 235 #ifndef PerlIO_unread 236 PERL_CALLCONV SSize_t PerlIO_unread(PerlIO *, const void *, Size_t); 237 #endif 238 #ifndef PerlIO_write 239 PERL_CALLCONV SSize_t PerlIO_write(PerlIO *, const void *, Size_t); 240 #endif 241 #ifndef PerlIO_setlinebuf 242 PERL_CALLCONV void PerlIO_setlinebuf(PerlIO *); 243 #endif 244 #ifndef PerlIO_printf 245 PERL_CALLCONV int PerlIO_printf(PerlIO *, const char *, ...) 246 __attribute__format__(__printf__, 2, 3); 247 #endif 248 #ifndef PerlIO_vprintf 249 PERL_CALLCONV int PerlIO_vprintf(PerlIO *, const char *, va_list); 250 #endif 251 #ifndef PerlIO_tell 252 PERL_CALLCONV Off_t PerlIO_tell(PerlIO *); 253 #endif 254 #ifndef PerlIO_seek 255 PERL_CALLCONV int PerlIO_seek(PerlIO *, Off_t, int); 256 #endif 257 #ifndef PerlIO_rewind 258 PERL_CALLCONV void PerlIO_rewind(PerlIO *); 259 #endif 260 #ifndef PerlIO_has_base 261 PERL_CALLCONV int PerlIO_has_base(PerlIO *); 262 #endif 263 #ifndef PerlIO_has_cntptr 264 PERL_CALLCONV int PerlIO_has_cntptr(PerlIO *); 265 #endif 266 #ifndef PerlIO_fast_gets 267 PERL_CALLCONV int PerlIO_fast_gets(PerlIO *); 268 #endif 269 #ifndef PerlIO_canset_cnt 270 PERL_CALLCONV int PerlIO_canset_cnt(PerlIO *); 271 #endif 272 #ifndef PerlIO_get_ptr 273 PERL_CALLCONV STDCHAR *PerlIO_get_ptr(PerlIO *); 274 #endif 275 #ifndef PerlIO_get_cnt 276 PERL_CALLCONV SSize_t PerlIO_get_cnt(PerlIO *); 277 #endif 278 #ifndef PerlIO_set_cnt 279 PERL_CALLCONV void PerlIO_set_cnt(PerlIO *, SSize_t); 280 #endif 281 #ifndef PerlIO_set_ptrcnt 282 PERL_CALLCONV void PerlIO_set_ptrcnt(PerlIO *, STDCHAR *, SSize_t); 283 #endif 284 #ifndef PerlIO_get_base 285 PERL_CALLCONV STDCHAR *PerlIO_get_base(PerlIO *); 286 #endif 287 #ifndef PerlIO_get_bufsiz 288 PERL_CALLCONV SSize_t PerlIO_get_bufsiz(PerlIO *); 289 #endif 290 #ifndef PerlIO_tmpfile 291 PERL_CALLCONV PerlIO *PerlIO_tmpfile(void); 292 #endif 293 #ifndef PerlIO_tmpfile_flags 294 PERL_CALLCONV PerlIO *PerlIO_tmpfile_flags(int flags); 295 #endif 296 #ifndef PerlIO_stdin 297 PERL_CALLCONV PerlIO *PerlIO_stdin(void); 298 #endif 299 #ifndef PerlIO_stdout 300 PERL_CALLCONV PerlIO *PerlIO_stdout(void); 301 #endif 302 #ifndef PerlIO_stderr 303 PERL_CALLCONV PerlIO *PerlIO_stderr(void); 304 #endif 305 #ifndef PerlIO_getpos 306 PERL_CALLCONV int PerlIO_getpos(PerlIO *, SV *); 307 #endif 308 #ifndef PerlIO_setpos 309 PERL_CALLCONV int PerlIO_setpos(PerlIO *, SV *); 310 #endif 311 #ifndef PerlIO_fdupopen 312 PERL_CALLCONV PerlIO *PerlIO_fdupopen(pTHX_ PerlIO *, CLONE_PARAMS *, int); 313 #endif 314 #if !defined(PerlIO_modestr) 315 PERL_CALLCONV char *PerlIO_modestr(PerlIO *, char *buf); 316 #endif 317 #ifndef PerlIO_isutf8 318 PERL_CALLCONV int PerlIO_isutf8(PerlIO *); 319 #endif 320 #ifndef PerlIO_apply_layers 321 PERL_CALLCONV int PerlIO_apply_layers(pTHX_ PerlIO *f, const char *mode, 322 const char *names); 323 #endif 324 #ifndef PerlIO_binmode 325 PERL_CALLCONV int PerlIO_binmode(pTHX_ PerlIO *f, int iotype, int omode, 326 const char *names); 327 #endif 328 #ifndef PerlIO_getname 329 PERL_CALLCONV char *PerlIO_getname(PerlIO *, char *); 330 #endif 331 332 PERL_CALLCONV void PerlIO_destruct(pTHX); 333 334 PERL_CALLCONV int PerlIO_intmode2str(int rawmode, char *mode, int *writing); 335 336 #ifdef PERLIO_LAYERS 337 PERL_CALLCONV void PerlIO_cleanup(pTHX); 338 339 PERL_CALLCONV void PerlIO_debug(const char *fmt, ...) 340 __attribute__format__(__printf__, 1, 2); 341 typedef struct PerlIO_list_s PerlIO_list_t; 342 343 #endif 344 345 END_EXTERN_C 346 #endif /* PERLIO_H_ */ 347 348 /* 349 * ex: set ts=8 sts=4 sw=4 et: 350 */ 351