3 * This file #define-s the PerlIO_xxx abstraction onto stdio functions.
4 * Make this as close to original stdio as possible.
7 #define PerlIO_stderr() stderr
8 #define PerlIO_stdout() stdout
9 #define PerlIO_stdin() stdin
11 #define PerlIO_fdupopen(f) (f)
12 #define PerlIO_isutf8(f) 0
14 #define PerlIO_printf fprintf
15 #define PerlIO_stdoutf printf
16 #define PerlIO_vprintf(f,fmt,a) vfprintf(f,fmt,a)
17 #define PerlIO_write(f,buf,count) fwrite1(buf,1,count,f)
18 #define PerlIO_open fopen
19 #define PerlIO_fdopen fdopen
20 #define PerlIO_reopen freopen
21 #ifdef SOCKS_64BIT_BUG
22 # define PerlIO_close(f) (Perl_do_s64_delete_buffer(aTHX_ f), fclose(f))
24 # define PerlIO_close(f) fclose(f)
26 #define PerlIO_puts(f,s) fputs(s,f)
27 #define PerlIO_putc(f,c) fputc(c,f)
30 /* Unusual definition of ungetc() here to accomodate fast_sv_gets()'
31 * belief that it can mix getc/ungetc with reads from stdio buffer */
32 int decc$ungetc(int __c, FILE *__stream);
33 # define PerlIO_ungetc(f,c) ((c) == EOF ? EOF : \
34 ((*(f) && !((*(f))->_flag & _IONBF) && \
35 ((*(f))->_ptr > (*(f))->_base)) ? \
36 ((*(f))->_cnt++, *(--(*(f))->_ptr) = (c)) : decc$ungetc(c,f)))
38 # define PerlIO_ungetc(f,c) ungetc(c,f)
40 /* Work around bug in DECCRTL/AXP (DECC v5.x) and some versions of old
41 * VAXCRTL which causes read from a pipe after EOF has been returned
44 # define PerlIO_getc(f) \
45 (feof(f) ? EOF : getc(f))
46 # define PerlIO_read(f,buf,count) \
47 (feof(f) ? 0 : (SSize_t)fread(buf,1,count,f))
48 # define PerlIO_tell(f) ftell(f)
50 # ifdef SOCKS_64BIT_BUG
51 # define PerlIO_getc(f) Perl_do_s64_getc(aTHX_ f)
52 # define PerlIO_ungetc(f,c) Perl_do_s64_ungetc(aTHX_ c,f)
53 # define PerlIO_read(f,buf,count) Perl_do_s64_fread(aTHX_ buf,count,f)
54 # define PerlIO_tell(f) Perl_do_s64_tell(aTHX_ f)
56 # define PerlIO_getc(f) getc(f)
57 # define PerlIO_ungetc(f,c) ungetc(c,f)
58 # define PerlIO_read(f,buf,count) (SSize_t)fread(buf,1,count,f)
59 # define PerlIO_tell(f) ftell(f)
60 # endif /* SOCKS_64BIT_BUG */
62 #define PerlIO_eof(f) feof(f)
63 #define PerlIO_getname(f,b) fgetname(f,b)
64 #define PerlIO_error(f) ferror(f)
65 #define PerlIO_fileno(f) fileno(f)
66 #define PerlIO_clearerr(f) clearerr(f)
67 #define PerlIO_flush(f) Fflush(f)
68 #ifdef SOCKS_64BIT_BUG
69 # define PerlIO_seek(f,o,w) Perl_do_s64_seek(aTHX_ f,o,w)
71 # if defined(VMS) && !defined(__DECC)
72 /* Old VAXC RTL doesn't reset EOF on seek; Perl folk seem to expect this */
73 # define PerlIO_seek(f,o,w) (((f) && (*f) && ((*f)->_flag &= ~_IOEOF)),fseek(f,o,w))
75 # define PerlIO_seek(f,o,w) fseek(f,o,w)
79 #define PerlIO_getpos(f,p) fgetpos(f,p)
82 #define PerlIO_setpos(f,p) fsetpos(f,p)
85 #define PerlIO_rewind(f) rewind(f)
86 #define PerlIO_tmpfile() tmpfile()
88 #define PerlIO_importFILE(f,fl) (f)
89 #define PerlIO_exportFILE(f,fl) (f)
90 #define PerlIO_findFILE(f) (f)
91 #define PerlIO_releaseFILE(p,f) ((void) 0)
94 #define PerlIO_setlinebuf(f) setlinebuf(f);
96 #define PerlIO_setlinebuf(f) setvbuf(f, Nullch, _IOLBF, 0);
99 /* Now our interface to Configure's FILE_xxx macros */
102 #define PerlIO_has_cntptr(f) 1
103 #define PerlIO_get_ptr(f) FILE_ptr(f)
104 #define PerlIO_get_cnt(f) FILE_cnt(f)
106 #ifdef STDIO_CNT_LVALUE
107 #define PerlIO_canset_cnt(f) 1
108 #define PerlIO_set_cnt(f,c) (FILE_cnt(f) = (c))
109 #ifdef STDIO_PTR_LVALUE
110 #ifdef STDIO_PTR_LVAL_NOCHANGE_CNT
111 #define PerlIO_fast_gets(f) 1
113 #endif /* STDIO_PTR_LVALUE */
114 #else /* STDIO_CNT_LVALUE */
115 #define PerlIO_canset_cnt(f) 0
116 #define PerlIO_set_cnt(f,c) abort()
119 #ifdef STDIO_PTR_LVALUE
120 #ifdef STDIO_PTR_LVAL_NOCHANGE_CNT
121 #define PerlIO_set_ptrcnt(f,p,c) STMT_START {FILE_ptr(f) = (p), PerlIO_set_cnt(f,c);} STMT_END
123 #ifdef STDIO_PTR_LVAL_SETS_CNT
124 /* assert() may pre-process to ""; potential syntax error (FILE_ptr(), ) */
125 #define PerlIO_set_ptrcnt(f,p,c) STMT_START {FILE_ptr(f) = (p); assert(FILE_cnt(f) == (c));} STMT_END
126 #define PerlIO_fast_gets(f) 1
128 #define PerlIO_set_ptrcnt(f,p,c) abort()
133 #else /* USE_STDIO_PTR */
135 #define PerlIO_has_cntptr(f) 0
136 #define PerlIO_canset_cnt(f) 0
137 #define PerlIO_get_cnt(f) (abort(),0)
138 #define PerlIO_get_ptr(f) (abort(),(void *)0)
139 #define PerlIO_set_cnt(f,c) abort()
140 #define PerlIO_set_ptrcnt(f,p,c) abort()
142 #endif /* USE_STDIO_PTR */
144 #ifndef PerlIO_fast_gets
145 #define PerlIO_fast_gets(f) 0
150 #define PerlIO_has_base(f) 1
151 #define PerlIO_get_base(f) FILE_base(f)
152 #define PerlIO_get_bufsiz(f) FILE_bufsiz(f)
154 #define PerlIO_has_base(f) 0
155 #define PerlIO_get_base(f) (abort(),(void *)0)
156 #define PerlIO_get_bufsiz(f) (abort(),0)
159 #endif /* PERLIO_IS_STDIO */