optimize XSUBs to use targets if the -nooptimize xsubpp option is
[p5sagit/p5-mst-13.2.git] / perlsdio.h
CommitLineData
760ac839 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 20#define PerlIO_open fopen
21#define PerlIO_fdopen fdopen
22#define PerlIO_reopen freopen
760ac839 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 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 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 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 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 58#if defined(USE_64_BIT_STDIO) && defined(HAS_FTELLO) && !defined(USE_FTELL64)
59#define ftell ftello
60#endif
17f28c40 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 67#if defined(USE_64_BIT_STDIO) && defined(HAS_FSEEKO) && !defined(USE_FSEEK64)
68#define fseek fseeko
69#endif
760ac839 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
2c2d71f5 88# ifdef CYGWIN
89# define PerlIO_setlinebuf(f)
90# else
91# define PerlIO_setlinebuf(f) setvbuf(f, Nullch, _IOLBF, 0);
92# endif
760ac839 93#endif
94
95/* Now our interface to Configure's FILE_xxx macros */
96
97#ifdef USE_STDIO_PTR
98#define PerlIO_has_cntptr(f) 1
a20bf0c3 99#define PerlIO_get_ptr(f) FILE_ptr(f)
100#define PerlIO_get_cnt(f) FILE_cnt(f)
760ac839 101
c7ae39e5 102#ifdef STDIO_CNT_LVALUE
760ac839 103#define PerlIO_canset_cnt(f) 1
c7ae39e5 104#ifdef STDIO_PTR_LVALUE
760ac839 105#define PerlIO_fast_gets(f) 1
106#endif
a20bf0c3 107#define PerlIO_set_cnt(f,c) (FILE_cnt(f) = (c))
760ac839 108#else
109#define PerlIO_canset_cnt(f) 0
a20bf0c3 110#define PerlIO_set_cnt(f,c) abort()
760ac839 111#endif
112
c7ae39e5 113#ifdef STDIO_PTR_LVALUE
a20bf0c3 114#define PerlIO_set_ptrcnt(f,p,c) (FILE_ptr(f) = (p), PerlIO_set_cnt(f,c))
760ac839 115#else
a20bf0c3 116#define PerlIO_set_ptrcnt(f,p,c) abort()
760ac839 117#endif
118
119#else /* USE_STDIO_PTR */
120
121#define PerlIO_has_cntptr(f) 0
c7ae39e5 122#define PerlIO_canset_cnt(f) 0
a20bf0c3 123#define PerlIO_get_cnt(f) (abort(),0)
124#define PerlIO_get_ptr(f) (abort(),(void *)0)
125#define PerlIO_set_cnt(f,c) abort()
126#define PerlIO_set_ptrcnt(f,p,c) abort()
760ac839 127
128#endif /* USE_STDIO_PTR */
129
130#ifndef PerlIO_fast_gets
131#define PerlIO_fast_gets(f) 0
132#endif
133
134
135#ifdef FILE_base
136#define PerlIO_has_base(f) 1
a20bf0c3 137#define PerlIO_get_base(f) FILE_base(f)
138#define PerlIO_get_bufsiz(f) FILE_bufsiz(f)
760ac839 139#else
140#define PerlIO_has_base(f) 0
a20bf0c3 141#define PerlIO_get_base(f) (abort(),(void *)0)
142#define PerlIO_get_bufsiz(f) (abort(),0)
760ac839 143#endif
144#else /* PERLIO_IS_STDIO */
145#ifdef PERL_CORE
146#ifndef PERLIO_NOT_STDIO
147#define PERLIO_NOT_STDIO 1
148#endif
149#endif
150#ifdef PERLIO_NOT_STDIO
151#if PERLIO_NOT_STDIO
152/*
153 * Strong denial of stdio - make all stdio calls (we can think of) errors
154 */
155#include "nostdio.h"
33dcbb9a 156#undef fprintf
157#undef tmpfile
158#undef fclose
159#undef fopen
160#undef vfprintf
161#undef fgetc
162#undef fputc
163#undef fputs
164#undef ungetc
165#undef fread
166#undef fwrite
167#undef fgetpos
168#undef fseek
169#undef fsetpos
170#undef ftell
171#undef rewind
172#undef fdopen
173#undef popen
174#undef pclose
175#undef getw
176#undef putw
177#undef freopen
178#undef setbuf
179#undef setvbuf
180#undef fscanf
181#undef fgets
1ac5d68d 182#undef getc_unlocked
183#undef putc_unlocked
760ac839 184#define fprintf _CANNOT _fprintf_
185#define stdin _CANNOT _stdin_
186#define stdout _CANNOT _stdout_
187#define stderr _CANNOT _stderr_
188#define tmpfile() _CANNOT _tmpfile_
189#define fclose(f) _CANNOT _fclose_
190#define fflush(f) _CANNOT _fflush_
191#define fopen(p,m) _CANNOT _fopen_
192#define freopen(p,m,f) _CANNOT _freopen_
193#define setbuf(f,b) _CANNOT _setbuf_
194#define setvbuf(f,b,x,s) _CANNOT _setvbuf_
195#define fscanf _CANNOT _fscanf_
196#define vfprintf(f,fmt,a) _CANNOT _vfprintf_
197#define fgetc(f) _CANNOT _fgetc_
198#define fgets(s,n,f) _CANNOT _fgets_
199#define fputc(c,f) _CANNOT _fputc_
200#define fputs(s,f) _CANNOT _fputs_
201#define getc(f) _CANNOT _getc_
202#define putc(c,f) _CANNOT _putc_
203#define ungetc(c,f) _CANNOT _ungetc_
204#define fread(b,s,c,f) _CANNOT _fread_
205#define fwrite(b,s,c,f) _CANNOT _fwrite_
206#define fgetpos(f,p) _CANNOT _fgetpos_
207#define fseek(f,o,w) _CANNOT _fseek_
208#define fsetpos(f,p) _CANNOT _fsetpos_
209#define ftell(f) _CANNOT _ftell_
210#define rewind(f) _CANNOT _rewind_
211#define clearerr(f) _CANNOT _clearerr_
212#define feof(f) _CANNOT _feof_
213#define ferror(f) _CANNOT _ferror_
214#define __filbuf(f) _CANNOT __filbuf_
215#define __flsbuf(c,f) _CANNOT __flsbuf_
216#define _filbuf(f) _CANNOT _filbuf_
217#define _flsbuf(c,f) _CANNOT _flsbuf_
218#define fdopen(fd,p) _CANNOT _fdopen_
219#define fileno(f) _CANNOT _fileno_
220#define flockfile(f) _CANNOT _flockfile_
221#define ftrylockfile(f) _CANNOT _ftrylockfile_
222#define funlockfile(f) _CANNOT _funlockfile_
223#define getc_unlocked(f) _CANNOT _getc_unlocked_
224#define putc_unlocked(c,f) _CANNOT _putc_unlocked_
225#define popen(c,m) _CANNOT _popen_
226#define getw(f) _CANNOT _getw_
227#define putw(v,f) _CANNOT _putw_
228#define pclose(f) _CANNOT _pclose_
229
230#else /* if PERLIO_NOT_STDIO */
231/*
232 * PERLIO_NOT_STDIO defined as 0
233 * Declares that both PerlIO and stdio can be used
234 */
235#endif /* if PERLIO_NOT_STDIO */
236#else /* ifdef PERLIO_NOT_STDIO */
237/*
238 * PERLIO_NOT_STDIO not defined
239 * This is "source level" stdio compatibility mode.
240 */
241#include "nostdio.h"
242#undef FILE
243#define FILE PerlIO
33dcbb9a 244#undef fprintf
245#undef tmpfile
246#undef fclose
247#undef fopen
248#undef vfprintf
249#undef fgetc
4b534093 250#undef getc_unlocked
33dcbb9a 251#undef fputc
4b534093 252#undef putc_unlocked
33dcbb9a 253#undef fputs
254#undef ungetc
255#undef fread
256#undef fwrite
257#undef fgetpos
258#undef fseek
259#undef fsetpos
260#undef ftell
261#undef rewind
262#undef fdopen
263#undef popen
264#undef pclose
265#undef getw
266#undef putw
267#undef freopen
268#undef setbuf
269#undef setvbuf
270#undef fscanf
271#undef fgets
760ac839 272#define fprintf PerlIO_printf
273#define stdin PerlIO_stdin()
274#define stdout PerlIO_stdout()
275#define stderr PerlIO_stderr()
276#define tmpfile() PerlIO_tmpfile()
277#define fclose(f) PerlIO_close(f)
278#define fflush(f) PerlIO_flush(f)
279#define fopen(p,m) PerlIO_open(p,m)
280#define vfprintf(f,fmt,a) PerlIO_vprintf(f,fmt,a)
281#define fgetc(f) PerlIO_getc(f)
282#define fputc(c,f) PerlIO_putc(f,c)
283#define fputs(s,f) PerlIO_puts(f,s)
284#define getc(f) PerlIO_getc(f)
43051805 285#ifdef getc_unlocked
286#undef getc_unlocked
287#endif
760ac839 288#define getc_unlocked(f) PerlIO_getc(f)
289#define putc(c,f) PerlIO_putc(f,c)
43051805 290#ifdef putc_unlocked
291#undef putc_unlocked
292#endif
760ac839 293#define putc_unlocked(c,f) PerlIO_putc(c,f)
294#define ungetc(c,f) PerlIO_ungetc(f,c)
295#if 0
296/* return values of read/write need work */
297#define fread(b,s,c,f) PerlIO_read(f,b,(s*c))
298#define fwrite(b,s,c,f) PerlIO_write(f,b,(s*c))
299#else
300#define fread(b,s,c,f) _CANNOT fread
301#define fwrite(b,s,c,f) _CANNOT fwrite
302#endif
303#define fgetpos(f,p) PerlIO_getpos(f,p)
304#define fseek(f,o,w) PerlIO_seek(f,o,w)
305#define fsetpos(f,p) PerlIO_setpos(f,p)
306#define ftell(f) PerlIO_tell(f)
307#define rewind(f) PerlIO_rewind(f)
308#define clearerr(f) PerlIO_clearerr(f)
309#define feof(f) PerlIO_eof(f)
310#define ferror(f) PerlIO_error(f)
311#define fdopen(fd,p) PerlIO_fdopen(fd,p)
312#define fileno(f) PerlIO_fileno(f)
313#define popen(c,m) my_popen(c,m)
314#define pclose(f) my_pclose(f)
315
316#define __filbuf(f) _CANNOT __filbuf_
317#define _filbuf(f) _CANNOT _filbuf_
318#define __flsbuf(c,f) _CANNOT __flsbuf_
319#define _flsbuf(c,f) _CANNOT _flsbuf_
320#define getw(f) _CANNOT _getw_
321#define putw(v,f) _CANNOT _putw_
322#define flockfile(f) _CANNOT _flockfile_
323#define ftrylockfile(f) _CANNOT _ftrylockfile_
324#define funlockfile(f) _CANNOT _funlockfile_
325#define freopen(p,m,f) _CANNOT _freopen_
326#define setbuf(f,b) _CANNOT _setbuf_
327#define setvbuf(f,b,x,s) _CANNOT _setvbuf_
328#define fscanf _CANNOT _fscanf_
329#define fgets(s,n,f) _CANNOT _fgets_
330
331#endif /* ifdef PERLIO_NOT_STDIO */
332#endif /* PERLIO_IS_STDIO */