This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate mainline ...
[perl5.git] / perlsdio.h
CommitLineData
760ac839
LW
1/*
2 * Although we may not want stdio to be used including <stdio.h> here
3 * avoids issues where stdio.h has strange side effects
4 */
5#include <stdio.h>
6
7#ifdef PERLIO_IS_STDIO
8/*
9 * Make this as close to original stdio as possible.
10 */
11#define PerlIO FILE
12#define PerlIO_stderr() stderr
13#define PerlIO_stdout() stdout
14#define PerlIO_stdin() stdin
15
16#define PerlIO_printf fprintf
17#define PerlIO_stdoutf printf
18#define PerlIO_vprintf(f,fmt,a) vfprintf(f,fmt,a)
760ac839 19#define PerlIO_write(f,buf,count) fwrite1(buf,1,count,f)
c7ae39e5
PP
20#define PerlIO_open fopen
21#define PerlIO_fdopen fdopen
22#define PerlIO_reopen freopen
760ac839
LW
23#define PerlIO_close(f) fclose(f)
24#define PerlIO_puts(f,s) fputs(s,f)
25#define PerlIO_putc(f,c) fputc(c,f)
9607fc9c
PP
26#if defined(VMS)
27# if defined(__DECC)
28 /* Unusual definition of ungetc() here to accomodate fast_sv_gets()'
29 * belief that it can mix getc/ungetc with reads from stdio buffer */
30 int decc$ungetc(int __c, FILE *__stream);
31# define PerlIO_ungetc(f,c) ((c) == EOF ? EOF : \
32 ((*(f) && !((*(f))->_flag & _IONBF) && \
33 ((*(f))->_ptr > (*(f))->_base)) ? \
34 ((*(f))->_cnt++, *(--(*(f))->_ptr) = (c)) : decc$ungetc(c,f)))
35# else
36# define PerlIO_ungetc(f,c) ungetc(c,f)
37# endif
38 /* Work around bug in DECCRTL/AXP (DECC v5.x) and some versions of old
39 * VAXCRTL which causes read from a pipe after EOF has been returned
40 * once to hang.
aa689395 41 */
5b54f415
CS
42# define PerlIO_getc(f) \
43 (feof(f) ? EOF : getc(f))
44# define PerlIO_read(f,buf,count) \
45 (feof(f) ? 0 : (SSize_t)fread(buf,1,count,f))
1ac5d68d
PP
46#else
47# define PerlIO_ungetc(f,c) ungetc(c,f)
aa689395 48# define PerlIO_getc(f) getc(f)
5b54f415 49# define PerlIO_read(f,buf,count) (SSize_t)fread(buf,1,count,f)
1ac5d68d 50#endif
760ac839 51#define PerlIO_eof(f) feof(f)
a20bf0c3 52#define PerlIO_getname(f,b) fgetname(f,b)
760ac839
LW
53#define PerlIO_error(f) ferror(f)
54#define PerlIO_fileno(f) fileno(f)
55#define PerlIO_clearerr(f) clearerr(f)
56#define PerlIO_flush(f) Fflush(f)
57#define PerlIO_tell(f) ftell(f)
d9b3e12d
JH
58#if defined(USE_64_BIT_STDIO) && defined(HAS_FTELLO) && !defined(USE_FTELL64)
59#define ftell ftello
60#endif
17f28c40
CB
61#if defined(VMS) && !defined(__DECC)
62 /* Old VAXC RTL doesn't reset EOF on seek; Perl folk seem to expect this */
63# define PerlIO_seek(f,o,w) (((f) && (*f) && ((*f)->_flag &= ~_IOEOF)),fseek(f,o,w))
64#else
65# define PerlIO_seek(f,o,w) fseek(f,o,w)
66#endif
d9b3e12d
JH
67#if defined(USE_64_BIT_STDIO) && defined(HAS_FSEEKO) && !defined(USE_FSEEK64)
68#define fseek fseeko
69#endif
760ac839
LW
70#ifdef HAS_FGETPOS
71#define PerlIO_getpos(f,p) fgetpos(f,p)
72#endif
73#ifdef HAS_FSETPOS
74#define PerlIO_setpos(f,p) fsetpos(f,p)
75#endif
76
77#define PerlIO_rewind(f) rewind(f)
78#define PerlIO_tmpfile() tmpfile()
79
80#define PerlIO_importFILE(f,fl) (f)
81#define PerlIO_exportFILE(f,fl) (f)
82#define PerlIO_findFILE(f) (f)
83#define PerlIO_releaseFILE(p,f) ((void) 0)
84
85#ifdef HAS_SETLINEBUF
86#define PerlIO_setlinebuf(f) setlinebuf(f);
87#else
4fabb596 88#define PerlIO_setlinebuf(f) setvbuf(f, Nullch, _IOLBF, 0);
760ac839
LW
89#endif
90
91/* Now our interface to Configure's FILE_xxx macros */
92
93#ifdef USE_STDIO_PTR
94#define PerlIO_has_cntptr(f) 1
a20bf0c3
JH
95#define PerlIO_get_ptr(f) FILE_ptr(f)
96#define PerlIO_get_cnt(f) FILE_cnt(f)
760ac839 97
c7ae39e5 98#ifdef STDIO_CNT_LVALUE
760ac839 99#define PerlIO_canset_cnt(f) 1
a7ffa9b9 100#define PerlIO_set_cnt(f,c) (FILE_cnt(f) = (c))
c7ae39e5 101#ifdef STDIO_PTR_LVALUE
a7ffa9b9 102#ifdef STDIO_PTR_LVAL_NOCHANGE_CNT
760ac839
LW
103#define PerlIO_fast_gets(f) 1
104#endif
a7ffa9b9
NC
105#endif /* STDIO_PTR_LVALUE */
106#else /* STDIO_CNT_LVALUE */
760ac839 107#define PerlIO_canset_cnt(f) 0
a20bf0c3 108#define PerlIO_set_cnt(f,c) abort()
760ac839
LW
109#endif
110
c7ae39e5 111#ifdef STDIO_PTR_LVALUE
a7ffa9b9 112#ifdef STDIO_PTR_LVAL_NOCHANGE_CNT
bd0e0981 113#define PerlIO_set_ptrcnt(f,p,c) STMT_START {FILE_ptr(f) = (p), PerlIO_set_cnt(f,c);} STMT_END
a7ffa9b9
NC
114#else
115#ifdef STDIO_PTR_LVAL_SETS_CNT
116/* assert() may pre-process to ""; potential syntax error (FILE_ptr(), ) */
bd0e0981 117#define PerlIO_set_ptrcnt(f,p,c) STMT_START {FILE_ptr(f) = (p); assert(FILE_cnt(f) == (c));} STMT_END
a7ffa9b9 118#define PerlIO_fast_gets(f) 1
760ac839 119#else
a20bf0c3 120#define PerlIO_set_ptrcnt(f,p,c) abort()
760ac839 121#endif
a7ffa9b9
NC
122#endif
123#endif
760ac839
LW
124
125#else /* USE_STDIO_PTR */
126
127#define PerlIO_has_cntptr(f) 0
c7ae39e5 128#define PerlIO_canset_cnt(f) 0
a20bf0c3
JH
129#define PerlIO_get_cnt(f) (abort(),0)
130#define PerlIO_get_ptr(f) (abort(),(void *)0)
131#define PerlIO_set_cnt(f,c) abort()
132#define PerlIO_set_ptrcnt(f,p,c) abort()
760ac839
LW
133
134#endif /* USE_STDIO_PTR */
135
136#ifndef PerlIO_fast_gets
137#define PerlIO_fast_gets(f) 0
138#endif
139
140
141#ifdef FILE_base
142#define PerlIO_has_base(f) 1
a20bf0c3
JH
143#define PerlIO_get_base(f) FILE_base(f)
144#define PerlIO_get_bufsiz(f) FILE_bufsiz(f)
760ac839
LW
145#else
146#define PerlIO_has_base(f) 0
a20bf0c3
JH
147#define PerlIO_get_base(f) (abort(),(void *)0)
148#define PerlIO_get_bufsiz(f) (abort(),0)
760ac839
LW
149#endif
150#else /* PERLIO_IS_STDIO */
151#ifdef PERL_CORE
152#ifndef PERLIO_NOT_STDIO
153#define PERLIO_NOT_STDIO 1
154#endif
155#endif
156#ifdef PERLIO_NOT_STDIO
157#if PERLIO_NOT_STDIO
158/*
159 * Strong denial of stdio - make all stdio calls (we can think of) errors
160 */
161#include "nostdio.h"
33dcbb9a
PP
162#undef fprintf
163#undef tmpfile
164#undef fclose
165#undef fopen
166#undef vfprintf
167#undef fgetc
168#undef fputc
169#undef fputs
170#undef ungetc
171#undef fread
172#undef fwrite
173#undef fgetpos
174#undef fseek
175#undef fsetpos
176#undef ftell
177#undef rewind
178#undef fdopen
179#undef popen
180#undef pclose
181#undef getw
182#undef putw
183#undef freopen
184#undef setbuf
185#undef setvbuf
186#undef fscanf
187#undef fgets
1ac5d68d
PP
188#undef getc_unlocked
189#undef putc_unlocked
760ac839
LW
190#define fprintf _CANNOT _fprintf_
191#define stdin _CANNOT _stdin_
192#define stdout _CANNOT _stdout_
193#define stderr _CANNOT _stderr_
194#define tmpfile() _CANNOT _tmpfile_
195#define fclose(f) _CANNOT _fclose_
196#define fflush(f) _CANNOT _fflush_
197#define fopen(p,m) _CANNOT _fopen_
198#define freopen(p,m,f) _CANNOT _freopen_
199#define setbuf(f,b) _CANNOT _setbuf_
200#define setvbuf(f,b,x,s) _CANNOT _setvbuf_
201#define fscanf _CANNOT _fscanf_
202#define vfprintf(f,fmt,a) _CANNOT _vfprintf_
203#define fgetc(f) _CANNOT _fgetc_
204#define fgets(s,n,f) _CANNOT _fgets_
205#define fputc(c,f) _CANNOT _fputc_
206#define fputs(s,f) _CANNOT _fputs_
207#define getc(f) _CANNOT _getc_
208#define putc(c,f) _CANNOT _putc_
209#define ungetc(c,f) _CANNOT _ungetc_
210#define fread(b,s,c,f) _CANNOT _fread_
211#define fwrite(b,s,c,f) _CANNOT _fwrite_
212#define fgetpos(f,p) _CANNOT _fgetpos_
213#define fseek(f,o,w) _CANNOT _fseek_
214#define fsetpos(f,p) _CANNOT _fsetpos_
215#define ftell(f) _CANNOT _ftell_
216#define rewind(f) _CANNOT _rewind_
217#define clearerr(f) _CANNOT _clearerr_
218#define feof(f) _CANNOT _feof_
219#define ferror(f) _CANNOT _ferror_
220#define __filbuf(f) _CANNOT __filbuf_
221#define __flsbuf(c,f) _CANNOT __flsbuf_
222#define _filbuf(f) _CANNOT _filbuf_
223#define _flsbuf(c,f) _CANNOT _flsbuf_
224#define fdopen(fd,p) _CANNOT _fdopen_
225#define fileno(f) _CANNOT _fileno_
25259385 226#if SFIO_VERSION < 20000101L
760ac839
LW
227#define flockfile(f) _CANNOT _flockfile_
228#define ftrylockfile(f) _CANNOT _ftrylockfile_
229#define funlockfile(f) _CANNOT _funlockfile_
25259385 230#endif
760ac839
LW
231#define getc_unlocked(f) _CANNOT _getc_unlocked_
232#define putc_unlocked(c,f) _CANNOT _putc_unlocked_
233#define popen(c,m) _CANNOT _popen_
234#define getw(f) _CANNOT _getw_
235#define putw(v,f) _CANNOT _putw_
236#define pclose(f) _CANNOT _pclose_
237
238#else /* if PERLIO_NOT_STDIO */
239/*
240 * PERLIO_NOT_STDIO defined as 0
241 * Declares that both PerlIO and stdio can be used
242 */
243#endif /* if PERLIO_NOT_STDIO */
244#else /* ifdef PERLIO_NOT_STDIO */
245/*
246 * PERLIO_NOT_STDIO not defined
247 * This is "source level" stdio compatibility mode.
248 */
249#include "nostdio.h"
250#undef FILE
251#define FILE PerlIO
33dcbb9a
PP
252#undef fprintf
253#undef tmpfile
254#undef fclose
255#undef fopen
256#undef vfprintf
257#undef fgetc
4b534093 258#undef getc_unlocked
33dcbb9a 259#undef fputc
4b534093 260#undef putc_unlocked
33dcbb9a
PP
261#undef fputs
262#undef ungetc
263#undef fread
264#undef fwrite
265#undef fgetpos
266#undef fseek
267#undef fsetpos
268#undef ftell
269#undef rewind
270#undef fdopen
271#undef popen
272#undef pclose
273#undef getw
274#undef putw
275#undef freopen
276#undef setbuf
277#undef setvbuf
278#undef fscanf
279#undef fgets
760ac839
LW
280#define fprintf PerlIO_printf
281#define stdin PerlIO_stdin()
282#define stdout PerlIO_stdout()
283#define stderr PerlIO_stderr()
284#define tmpfile() PerlIO_tmpfile()
285#define fclose(f) PerlIO_close(f)
286#define fflush(f) PerlIO_flush(f)
287#define fopen(p,m) PerlIO_open(p,m)
288#define vfprintf(f,fmt,a) PerlIO_vprintf(f,fmt,a)
289#define fgetc(f) PerlIO_getc(f)
290#define fputc(c,f) PerlIO_putc(f,c)
291#define fputs(s,f) PerlIO_puts(f,s)
292#define getc(f) PerlIO_getc(f)
43051805
GS
293#ifdef getc_unlocked
294#undef getc_unlocked
295#endif
760ac839
LW
296#define getc_unlocked(f) PerlIO_getc(f)
297#define putc(c,f) PerlIO_putc(f,c)
43051805
GS
298#ifdef putc_unlocked
299#undef putc_unlocked
300#endif
760ac839
LW
301#define putc_unlocked(c,f) PerlIO_putc(c,f)
302#define ungetc(c,f) PerlIO_ungetc(f,c)
303#if 0
304/* return values of read/write need work */
305#define fread(b,s,c,f) PerlIO_read(f,b,(s*c))
306#define fwrite(b,s,c,f) PerlIO_write(f,b,(s*c))
307#else
308#define fread(b,s,c,f) _CANNOT fread
309#define fwrite(b,s,c,f) _CANNOT fwrite
310#endif
311#define fgetpos(f,p) PerlIO_getpos(f,p)
312#define fseek(f,o,w) PerlIO_seek(f,o,w)
313#define fsetpos(f,p) PerlIO_setpos(f,p)
314#define ftell(f) PerlIO_tell(f)
315#define rewind(f) PerlIO_rewind(f)
316#define clearerr(f) PerlIO_clearerr(f)
317#define feof(f) PerlIO_eof(f)
318#define ferror(f) PerlIO_error(f)
319#define fdopen(fd,p) PerlIO_fdopen(fd,p)
320#define fileno(f) PerlIO_fileno(f)
321#define popen(c,m) my_popen(c,m)
322#define pclose(f) my_pclose(f)
323
324#define __filbuf(f) _CANNOT __filbuf_
325#define _filbuf(f) _CANNOT _filbuf_
326#define __flsbuf(c,f) _CANNOT __flsbuf_
327#define _flsbuf(c,f) _CANNOT _flsbuf_
328#define getw(f) _CANNOT _getw_
329#define putw(v,f) _CANNOT _putw_
25259385 330#if SFIO_VERSION < 20000101L
760ac839
LW
331#define flockfile(f) _CANNOT _flockfile_
332#define ftrylockfile(f) _CANNOT _ftrylockfile_
333#define funlockfile(f) _CANNOT _funlockfile_
25259385 334#endif
760ac839
LW
335#define freopen(p,m,f) _CANNOT _freopen_
336#define setbuf(f,b) _CANNOT _setbuf_
337#define setvbuf(f,b,x,s) _CANNOT _setvbuf_
338#define fscanf _CANNOT _fscanf_
339#define fgets(s,n,f) _CANNOT _fgets_
340
341#endif /* ifdef PERLIO_NOT_STDIO */
342#endif /* PERLIO_IS_STDIO */