179cd0b9aSmillert /* perlio.h 279cd0b9aSmillert * 3f64b279aSmillert * Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 47bfa9f44Smillert * 2004, 2005, 2006, 2007, by Larry Wall and others 579cd0b9aSmillert * 679cd0b9aSmillert * You may distribute under the terms of either the GNU General Public 779cd0b9aSmillert * License or the Artistic License, as specified in the README file. 879cd0b9aSmillert * 979cd0b9aSmillert */ 1079cd0b9aSmillert 119f11ffb7Safresh1 #ifndef PERLIO_H_ 129f11ffb7Safresh1 #define PERLIO_H_ 1379cd0b9aSmillert /* 1479cd0b9aSmillert Interface for perl to IO functions. 15f3142520Smillert There is a hierarchy of Configure determined #define controls: 16b8851fccSafresh1 USE_STDIO - No longer available via Configure. Formerly forced 17b8851fccSafresh1 PerlIO_xxx() to be #define-d onto stdio functions. 18b8851fccSafresh1 Now generates compile-time error. 1979cd0b9aSmillert 2079cd0b9aSmillert USE_PERLIO - The primary Configure variable that enables PerlIO. 21e5157e49Safresh1 PerlIO_xxx() are real functions 2279cd0b9aSmillert defined in perlio.c which implement extra functionality 2379cd0b9aSmillert required for utf8 support. 2479cd0b9aSmillert 2579cd0b9aSmillert */ 2679cd0b9aSmillert 2779cd0b9aSmillert #ifndef USE_PERLIO 2879cd0b9aSmillert # define USE_STDIO 2979cd0b9aSmillert #endif 3079cd0b9aSmillert 3179cd0b9aSmillert #ifdef USE_STDIO 32b8851fccSafresh1 # error "stdio is no longer supported as the default base layer -- use perlio." 3379cd0b9aSmillert #endif 3479cd0b9aSmillert 35*e0680481Safresh1 /*-------------------- End of Configure controls ---------------------------*/ 3679cd0b9aSmillert 3779cd0b9aSmillert /* 3879cd0b9aSmillert * Although we may not want stdio to be used including <stdio.h> here 3979cd0b9aSmillert * avoids issues where stdio.h has strange side effects 4079cd0b9aSmillert */ 4179cd0b9aSmillert #include <stdio.h> 4279cd0b9aSmillert 4379cd0b9aSmillert #if defined(USE_64_BIT_STDIO) && defined(HAS_FTELLO) && !defined(USE_FTELL64) 4479cd0b9aSmillert #define ftell ftello 4579cd0b9aSmillert #endif 4679cd0b9aSmillert 4779cd0b9aSmillert #if defined(USE_64_BIT_STDIO) && defined(HAS_FSEEKO) && !defined(USE_FSEEK64) 4879cd0b9aSmillert #define fseek fseeko 4979cd0b9aSmillert #endif 5079cd0b9aSmillert 5179cd0b9aSmillert /* BS2000 includes are sometimes a bit non standard :-( */ 5279cd0b9aSmillert #if defined(POSIX_BC) && defined(O_BINARY) && !defined(O_TEXT) 5379cd0b9aSmillert #undef O_BINARY 5479cd0b9aSmillert #endif 5579cd0b9aSmillert 5679cd0b9aSmillert #ifndef PerlIO 5779cd0b9aSmillert /* ----------- PerlIO implementation ---------- */ 5879cd0b9aSmillert /* PerlIO not #define-d to something else - define the implementation */ 5979cd0b9aSmillert 6079cd0b9aSmillert typedef struct _PerlIO PerlIOl; 6179cd0b9aSmillert typedef struct _PerlIO_funcs PerlIO_funcs; 6279cd0b9aSmillert typedef PerlIOl *PerlIO; 6379cd0b9aSmillert #define PerlIO PerlIO 6479cd0b9aSmillert #define PERLIO_LAYERS 1 6579cd0b9aSmillert 66eac174f2Safresh1 /* 67eac174f2Safresh1 =for apidoc_section $io 68eac174f2Safresh1 =for apidoc Amu||PERLIO_FUNCS_DECL|PerlIO * ftab 69eac174f2Safresh1 Declare C<ftab> to be a PerlIO function table, that is, of type 70eac174f2Safresh1 C<PerlIO_funcs>. 71eac174f2Safresh1 72eac174f2Safresh1 =for apidoc Ay|PerlIO_funcs *|PERLIO_FUNCS_CAST|PerlIO * func 73eac174f2Safresh1 Cast the pointer C<func> to be of type S<C<PerlIO_funcs *>>. 74eac174f2Safresh1 75eac174f2Safresh1 =cut 76eac174f2Safresh1 */ 77ad15181aSmillert #define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs 78ad15181aSmillert #define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs) 79ad15181aSmillert 80b8851fccSafresh1 PERL_CALLCONV void PerlIO_define_layer(pTHX_ PerlIO_funcs *tab); 81b8851fccSafresh1 PERL_CALLCONV PerlIO_funcs *PerlIO_find_layer(pTHX_ const char *name, 82ad15181aSmillert STRLEN len, 8379cd0b9aSmillert int load); 84b8851fccSafresh1 PERL_CALLCONV PerlIO *PerlIO_push(pTHX_ PerlIO *f, PERLIO_FUNCS_DECL(*tab), 8579cd0b9aSmillert const char *mode, SV *arg); 86b8851fccSafresh1 PERL_CALLCONV void PerlIO_pop(pTHX_ PerlIO *f); 87b8851fccSafresh1 PERL_CALLCONV AV* PerlIO_get_layers(pTHX_ PerlIO *f); 88b8851fccSafresh1 PERL_CALLCONV void PerlIO_clone(pTHX_ PerlInterpreter *proto, 89ad15181aSmillert CLONE_PARAMS *param); 9079cd0b9aSmillert 9179cd0b9aSmillert #endif /* PerlIO */ 9279cd0b9aSmillert 9379cd0b9aSmillert /* ----------- End of implementation choices ---------- */ 9479cd0b9aSmillert 9579cd0b9aSmillert /* We now need to determine what happens if source trys to use stdio. 9679cd0b9aSmillert * There are three cases based on PERLIO_NOT_STDIO which XS code 9779cd0b9aSmillert * can set how it wants. 9879cd0b9aSmillert */ 9979cd0b9aSmillert 10079cd0b9aSmillert #ifdef PERL_CORE 10179cd0b9aSmillert /* Make a choice for perl core code 10279cd0b9aSmillert - currently this is set to try and catch lingering raw stdio calls. 10379cd0b9aSmillert This is a known issue with some non UNIX ports which still use 10479cd0b9aSmillert "native" stdio features. 10579cd0b9aSmillert */ 10679cd0b9aSmillert # ifndef PERLIO_NOT_STDIO 10779cd0b9aSmillert # define PERLIO_NOT_STDIO 1 10879cd0b9aSmillert # endif 10979cd0b9aSmillert #else 11079cd0b9aSmillert # ifndef PERLIO_NOT_STDIO 11179cd0b9aSmillert # define PERLIO_NOT_STDIO 0 11279cd0b9aSmillert # endif 11379cd0b9aSmillert #endif 11479cd0b9aSmillert 11579cd0b9aSmillert #ifdef PERLIO_NOT_STDIO 11679cd0b9aSmillert #if PERLIO_NOT_STDIO 11779cd0b9aSmillert /* 11879cd0b9aSmillert * PERLIO_NOT_STDIO #define'd as 1 11979cd0b9aSmillert * Case 1: Strong denial of stdio - make all stdio calls (we can think of) errors 12079cd0b9aSmillert */ 12179cd0b9aSmillert #include "nostdio.h" 12279cd0b9aSmillert #else /* if PERLIO_NOT_STDIO */ 12379cd0b9aSmillert /* 12479cd0b9aSmillert * PERLIO_NOT_STDIO #define'd as 0 12579cd0b9aSmillert * Case 2: Declares that both PerlIO and stdio can be used 12679cd0b9aSmillert */ 12779cd0b9aSmillert #endif /* if PERLIO_NOT_STDIO */ 12879cd0b9aSmillert #else /* ifdef PERLIO_NOT_STDIO */ 12979cd0b9aSmillert /* 13079cd0b9aSmillert * PERLIO_NOT_STDIO not defined 13179cd0b9aSmillert * Case 3: Try and fake stdio calls as PerlIO calls 13279cd0b9aSmillert */ 13379cd0b9aSmillert #include "fakesdio.h" 13479cd0b9aSmillert #endif /* ifndef PERLIO_NOT_STDIO */ 13579cd0b9aSmillert 13679cd0b9aSmillert /* ----------- fill in things that have not got #define'd ---------- */ 13779cd0b9aSmillert 13879cd0b9aSmillert #ifndef Fpos_t 13979cd0b9aSmillert #define Fpos_t Off_t 14079cd0b9aSmillert #endif 14179cd0b9aSmillert 14279cd0b9aSmillert #ifndef EOF 14379cd0b9aSmillert #define EOF (-1) 14479cd0b9aSmillert #endif 14579cd0b9aSmillert 14679cd0b9aSmillert /* This is to catch case with no stdio */ 14779cd0b9aSmillert #ifndef BUFSIZ 14879cd0b9aSmillert #define BUFSIZ 1024 14979cd0b9aSmillert #endif 15079cd0b9aSmillert 15148950c12Ssthen /* The default buffer size for the perlio buffering layer */ 15248950c12Ssthen #ifndef PERLIOBUF_DEFAULT_BUFSIZ 15348950c12Ssthen #define PERLIOBUF_DEFAULT_BUFSIZ (BUFSIZ > 8192 ? BUFSIZ : 8192) 15448950c12Ssthen #endif 15548950c12Ssthen 15679cd0b9aSmillert #ifndef SEEK_SET 15779cd0b9aSmillert #define SEEK_SET 0 15879cd0b9aSmillert #endif 15979cd0b9aSmillert 16079cd0b9aSmillert #ifndef SEEK_CUR 16179cd0b9aSmillert #define SEEK_CUR 1 16279cd0b9aSmillert #endif 16379cd0b9aSmillert 16479cd0b9aSmillert #ifndef SEEK_END 16579cd0b9aSmillert #define SEEK_END 2 16679cd0b9aSmillert #endif 16779cd0b9aSmillert 16879cd0b9aSmillert #define PERLIO_DUP_CLONE 1 16979cd0b9aSmillert #define PERLIO_DUP_FD 2 17079cd0b9aSmillert 17179cd0b9aSmillert /* --------------------- Now prototypes for functions --------------- */ 17279cd0b9aSmillert 17379cd0b9aSmillert START_EXTERN_C 174f64b279aSmillert #ifndef __attribute__format__ 175ad15181aSmillert # ifdef HASATTRIBUTE_FORMAT 176ad15181aSmillert # define __attribute__format__(x,y,z) __attribute__((format(x,y,z))) 177f64b279aSmillert # else 178f64b279aSmillert # define __attribute__format__(x,y,z) 179f64b279aSmillert # endif 180f64b279aSmillert #endif 18179cd0b9aSmillert #ifndef PerlIO_init 182b8851fccSafresh1 PERL_CALLCONV void PerlIO_init(pTHX); 18379cd0b9aSmillert #endif 18479cd0b9aSmillert #ifndef PerlIO_stdoutf 185b8851fccSafresh1 PERL_CALLCONV int PerlIO_stdoutf(const char *, ...) 186f64b279aSmillert __attribute__format__(__printf__, 1, 2); 18779cd0b9aSmillert #endif 18879cd0b9aSmillert #ifndef PerlIO_puts 189b8851fccSafresh1 PERL_CALLCONV int PerlIO_puts(PerlIO *, const char *); 19079cd0b9aSmillert #endif 19179cd0b9aSmillert #ifndef PerlIO_open 192b8851fccSafresh1 PERL_CALLCONV PerlIO *PerlIO_open(const char *, const char *); 19379cd0b9aSmillert #endif 19479cd0b9aSmillert #ifndef PerlIO_openn 195b8851fccSafresh1 PERL_CALLCONV PerlIO *PerlIO_openn(pTHX_ const char *layers, const char *mode, 19679cd0b9aSmillert int fd, int imode, int perm, PerlIO *old, 19779cd0b9aSmillert int narg, SV **arg); 19879cd0b9aSmillert #endif 19979cd0b9aSmillert #ifndef PerlIO_eof 200b8851fccSafresh1 PERL_CALLCONV int PerlIO_eof(PerlIO *); 20179cd0b9aSmillert #endif 20279cd0b9aSmillert #ifndef PerlIO_error 203b8851fccSafresh1 PERL_CALLCONV int PerlIO_error(PerlIO *); 20479cd0b9aSmillert #endif 20579cd0b9aSmillert #ifndef PerlIO_clearerr 206b8851fccSafresh1 PERL_CALLCONV void PerlIO_clearerr(PerlIO *); 20779cd0b9aSmillert #endif 20879cd0b9aSmillert #ifndef PerlIO_getc 209b8851fccSafresh1 PERL_CALLCONV int PerlIO_getc(PerlIO *); 21079cd0b9aSmillert #endif 21179cd0b9aSmillert #ifndef PerlIO_putc 212b8851fccSafresh1 PERL_CALLCONV int PerlIO_putc(PerlIO *, int); 21379cd0b9aSmillert #endif 21479cd0b9aSmillert #ifndef PerlIO_ungetc 215b8851fccSafresh1 PERL_CALLCONV int PerlIO_ungetc(PerlIO *, int); 21679cd0b9aSmillert #endif 21779cd0b9aSmillert #ifndef PerlIO_fdopen 218b8851fccSafresh1 PERL_CALLCONV PerlIO *PerlIO_fdopen(int, const char *); 21979cd0b9aSmillert #endif 22079cd0b9aSmillert #ifndef PerlIO_importFILE 221b8851fccSafresh1 PERL_CALLCONV PerlIO *PerlIO_importFILE(FILE *, const char *); 22279cd0b9aSmillert #endif 22379cd0b9aSmillert #ifndef PerlIO_exportFILE 224b8851fccSafresh1 PERL_CALLCONV FILE *PerlIO_exportFILE(PerlIO *, const char *); 22579cd0b9aSmillert #endif 22679cd0b9aSmillert #ifndef PerlIO_findFILE 227b8851fccSafresh1 PERL_CALLCONV FILE *PerlIO_findFILE(PerlIO *); 22879cd0b9aSmillert #endif 22979cd0b9aSmillert #ifndef PerlIO_releaseFILE 230b8851fccSafresh1 PERL_CALLCONV void PerlIO_releaseFILE(PerlIO *, FILE *); 23179cd0b9aSmillert #endif 23279cd0b9aSmillert #ifndef PerlIO_read 233b8851fccSafresh1 PERL_CALLCONV SSize_t PerlIO_read(PerlIO *, void *, Size_t); 23479cd0b9aSmillert #endif 23579cd0b9aSmillert #ifndef PerlIO_unread 236b8851fccSafresh1 PERL_CALLCONV SSize_t PerlIO_unread(PerlIO *, const void *, Size_t); 23779cd0b9aSmillert #endif 23879cd0b9aSmillert #ifndef PerlIO_write 239b8851fccSafresh1 PERL_CALLCONV SSize_t PerlIO_write(PerlIO *, const void *, Size_t); 24079cd0b9aSmillert #endif 24179cd0b9aSmillert #ifndef PerlIO_setlinebuf 242b8851fccSafresh1 PERL_CALLCONV void PerlIO_setlinebuf(PerlIO *); 24379cd0b9aSmillert #endif 24479cd0b9aSmillert #ifndef PerlIO_printf 245b8851fccSafresh1 PERL_CALLCONV int PerlIO_printf(PerlIO *, const char *, ...) 246f64b279aSmillert __attribute__format__(__printf__, 2, 3); 24779cd0b9aSmillert #endif 24879cd0b9aSmillert #ifndef PerlIO_vprintf 249b8851fccSafresh1 PERL_CALLCONV int PerlIO_vprintf(PerlIO *, const char *, va_list); 25079cd0b9aSmillert #endif 25179cd0b9aSmillert #ifndef PerlIO_tell 252b8851fccSafresh1 PERL_CALLCONV Off_t PerlIO_tell(PerlIO *); 25379cd0b9aSmillert #endif 25479cd0b9aSmillert #ifndef PerlIO_seek 255b8851fccSafresh1 PERL_CALLCONV int PerlIO_seek(PerlIO *, Off_t, int); 25679cd0b9aSmillert #endif 25779cd0b9aSmillert #ifndef PerlIO_rewind 258b8851fccSafresh1 PERL_CALLCONV void PerlIO_rewind(PerlIO *); 25979cd0b9aSmillert #endif 26079cd0b9aSmillert #ifndef PerlIO_has_base 261b8851fccSafresh1 PERL_CALLCONV int PerlIO_has_base(PerlIO *); 26279cd0b9aSmillert #endif 26379cd0b9aSmillert #ifndef PerlIO_has_cntptr 264b8851fccSafresh1 PERL_CALLCONV int PerlIO_has_cntptr(PerlIO *); 26579cd0b9aSmillert #endif 26679cd0b9aSmillert #ifndef PerlIO_fast_gets 267b8851fccSafresh1 PERL_CALLCONV int PerlIO_fast_gets(PerlIO *); 26879cd0b9aSmillert #endif 26979cd0b9aSmillert #ifndef PerlIO_canset_cnt 270b8851fccSafresh1 PERL_CALLCONV int PerlIO_canset_cnt(PerlIO *); 27179cd0b9aSmillert #endif 27279cd0b9aSmillert #ifndef PerlIO_get_ptr 273b8851fccSafresh1 PERL_CALLCONV STDCHAR *PerlIO_get_ptr(PerlIO *); 27479cd0b9aSmillert #endif 27579cd0b9aSmillert #ifndef PerlIO_get_cnt 276b8851fccSafresh1 PERL_CALLCONV SSize_t PerlIO_get_cnt(PerlIO *); 27779cd0b9aSmillert #endif 27879cd0b9aSmillert #ifndef PerlIO_set_cnt 279b8851fccSafresh1 PERL_CALLCONV void PerlIO_set_cnt(PerlIO *, SSize_t); 28079cd0b9aSmillert #endif 28179cd0b9aSmillert #ifndef PerlIO_set_ptrcnt 282b8851fccSafresh1 PERL_CALLCONV void PerlIO_set_ptrcnt(PerlIO *, STDCHAR *, SSize_t); 28379cd0b9aSmillert #endif 28479cd0b9aSmillert #ifndef PerlIO_get_base 285b8851fccSafresh1 PERL_CALLCONV STDCHAR *PerlIO_get_base(PerlIO *); 28679cd0b9aSmillert #endif 28779cd0b9aSmillert #ifndef PerlIO_get_bufsiz 288b8851fccSafresh1 PERL_CALLCONV SSize_t PerlIO_get_bufsiz(PerlIO *); 28979cd0b9aSmillert #endif 29079cd0b9aSmillert #ifndef PerlIO_tmpfile 291b8851fccSafresh1 PERL_CALLCONV PerlIO *PerlIO_tmpfile(void); 29279cd0b9aSmillert #endif 29356d68f1eSafresh1 #ifndef PerlIO_tmpfile_flags 29456d68f1eSafresh1 PERL_CALLCONV PerlIO *PerlIO_tmpfile_flags(int flags); 29556d68f1eSafresh1 #endif 29679cd0b9aSmillert #ifndef PerlIO_stdin 297b8851fccSafresh1 PERL_CALLCONV PerlIO *PerlIO_stdin(void); 29879cd0b9aSmillert #endif 29979cd0b9aSmillert #ifndef PerlIO_stdout 300b8851fccSafresh1 PERL_CALLCONV PerlIO *PerlIO_stdout(void); 30179cd0b9aSmillert #endif 30279cd0b9aSmillert #ifndef PerlIO_stderr 303b8851fccSafresh1 PERL_CALLCONV PerlIO *PerlIO_stderr(void); 30479cd0b9aSmillert #endif 30579cd0b9aSmillert #ifndef PerlIO_getpos 306b8851fccSafresh1 PERL_CALLCONV int PerlIO_getpos(PerlIO *, SV *); 30779cd0b9aSmillert #endif 30879cd0b9aSmillert #ifndef PerlIO_setpos 309b8851fccSafresh1 PERL_CALLCONV int PerlIO_setpos(PerlIO *, SV *); 31079cd0b9aSmillert #endif 31179cd0b9aSmillert #ifndef PerlIO_fdupopen 312b8851fccSafresh1 PERL_CALLCONV PerlIO *PerlIO_fdupopen(pTHX_ PerlIO *, CLONE_PARAMS *, int); 31379cd0b9aSmillert #endif 314b8851fccSafresh1 #if !defined(PerlIO_modestr) 315b8851fccSafresh1 PERL_CALLCONV char *PerlIO_modestr(PerlIO *, char *buf); 31679cd0b9aSmillert #endif 31779cd0b9aSmillert #ifndef PerlIO_isutf8 318b8851fccSafresh1 PERL_CALLCONV int PerlIO_isutf8(PerlIO *); 31979cd0b9aSmillert #endif 32079cd0b9aSmillert #ifndef PerlIO_apply_layers 321b8851fccSafresh1 PERL_CALLCONV int PerlIO_apply_layers(pTHX_ PerlIO *f, const char *mode, 32279cd0b9aSmillert const char *names); 32379cd0b9aSmillert #endif 32479cd0b9aSmillert #ifndef PerlIO_binmode 325b8851fccSafresh1 PERL_CALLCONV int PerlIO_binmode(pTHX_ PerlIO *f, int iotype, int omode, 32679cd0b9aSmillert const char *names); 32779cd0b9aSmillert #endif 32879cd0b9aSmillert #ifndef PerlIO_getname 329b8851fccSafresh1 PERL_CALLCONV char *PerlIO_getname(PerlIO *, char *); 33079cd0b9aSmillert #endif 33179cd0b9aSmillert 332b8851fccSafresh1 PERL_CALLCONV void PerlIO_destruct(pTHX); 33379cd0b9aSmillert 334b8851fccSafresh1 PERL_CALLCONV int PerlIO_intmode2str(int rawmode, char *mode, int *writing); 33579cd0b9aSmillert 33679cd0b9aSmillert #ifdef PERLIO_LAYERS 337b8851fccSafresh1 PERL_CALLCONV void PerlIO_cleanup(pTHX); 33879cd0b9aSmillert 339b8851fccSafresh1 PERL_CALLCONV void PerlIO_debug(const char *fmt, ...) 340ad15181aSmillert __attribute__format__(__printf__, 1, 2); 34179cd0b9aSmillert typedef struct PerlIO_list_s PerlIO_list_t; 34279cd0b9aSmillert 34379cd0b9aSmillert #endif 34479cd0b9aSmillert 34579cd0b9aSmillert END_EXTERN_C 3469f11ffb7Safresh1 #endif /* PERLIO_H_ */ 347df042708Smillert 348df042708Smillert /* 349e9ce3842Safresh1 * ex: set ts=8 sts=4 sw=4 et: 350df042708Smillert */ 351