This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.003_05: perlio.c
[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)
19#define PerlIO_read(f,buf,count) fread(buf,1,count,f)
20#define PerlIO_write(f,buf,count) fwrite1(buf,1,count,f)
21#define PerlIO_open(path,mode) fopen(path,mode)
22#define PerlIO_fdopen(fd,mode) fdopen(fd,mode)
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)
26#define PerlIO_ungetc(f,c) ungetc(c,f)
27#define PerlIO_getc(f) getc(f)
28#define PerlIO_eof(f) feof(f)
29#define PerlIO_error(f) ferror(f)
30#define PerlIO_fileno(f) fileno(f)
31#define PerlIO_clearerr(f) clearerr(f)
32#define PerlIO_flush(f) Fflush(f)
33#define PerlIO_tell(f) ftell(f)
34#define PerlIO_seek(f,o,w) fseek(f,o,w)
35#ifdef HAS_FGETPOS
36#define PerlIO_getpos(f,p) fgetpos(f,p)
37#endif
38#ifdef HAS_FSETPOS
39#define PerlIO_setpos(f,p) fsetpos(f,p)
40#endif
41
42#define PerlIO_rewind(f) rewind(f)
43#define PerlIO_tmpfile() tmpfile()
44
45#define PerlIO_importFILE(f,fl) (f)
46#define PerlIO_exportFILE(f,fl) (f)
47#define PerlIO_findFILE(f) (f)
48#define PerlIO_releaseFILE(p,f) ((void) 0)
49
50#ifdef HAS_SETLINEBUF
51#define PerlIO_setlinebuf(f) setlinebuf(f);
52#else
53#define PerlIO_setlinebuf(f) setvbuf(f, Nullch, _IOLBF, 0);
54#endif
55
56/* Now our interface to Configure's FILE_xxx macros */
57
58#ifdef USE_STDIO_PTR
59#define PerlIO_has_cntptr(f) 1
60#define PerlIO_get_ptr(f) FILE_ptr(f)
61#define PerlIO_get_cnt(f) FILE_cnt(f)
62
63#ifdef FILE_CNT_LVALUE
64#define PerlIO_canset_cnt(f) 1
65#ifdef FILE_PTR_LVALUE
66#define PerlIO_fast_gets(f) 1
67#endif
68#define PerlIO_set_cnt(f,c) (FILE_cnt(f) = (c))
69#else
70#define PerlIO_canset_cnt(f) 0
71#define PerlIO_set_cnt(f,c) abort()
72#endif
73
74#ifdef FILE_PTR_LVALUE
75#define PerlIO_set_ptrcnt(f,p,c) (FILE_ptr(f) = (p), PerlIO_set_cnt(f,c))
76#else
77#define PerlIO_set_ptrcnt(f,p,c) abort()
78#endif
79
80#else /* USE_STDIO_PTR */
81
82#define PerlIO_has_cntptr(f) 0
33dcbb9a
PP
83#define PerlIO_get_cnt(f) (abort(),0)
84#define PerlIO_get_ptr(f) (abort(),0)
760ac839
LW
85#define PerlIO_set_cnt(f,c) abort()
86#define PerlIO_set_ptrcnt(f,p,c) abort()
87
88#endif /* USE_STDIO_PTR */
89
90#ifndef PerlIO_fast_gets
91#define PerlIO_fast_gets(f) 0
92#endif
93
94
95#ifdef FILE_base
96#define PerlIO_has_base(f) 1
97#define PerlIO_get_base(f) FILE_base(f)
98#define PerlIO_get_bufsiz(f) FILE_bufsiz(f)
99#else
100#define PerlIO_has_base(f) 0
33dcbb9a
PP
101#define PerlIO_get_base(f) (abort(),0)
102#define PerlIO_get_bufsiz(f) (abort(),0)
760ac839
LW
103#endif
104#else /* PERLIO_IS_STDIO */
105#ifdef PERL_CORE
106#ifndef PERLIO_NOT_STDIO
107#define PERLIO_NOT_STDIO 1
108#endif
109#endif
110#ifdef PERLIO_NOT_STDIO
111#if PERLIO_NOT_STDIO
112/*
113 * Strong denial of stdio - make all stdio calls (we can think of) errors
114 */
115#include "nostdio.h"
33dcbb9a
PP
116#undef fprintf
117#undef tmpfile
118#undef fclose
119#undef fopen
120#undef vfprintf
121#undef fgetc
122#undef fputc
123#undef fputs
124#undef ungetc
125#undef fread
126#undef fwrite
127#undef fgetpos
128#undef fseek
129#undef fsetpos
130#undef ftell
131#undef rewind
132#undef fdopen
133#undef popen
134#undef pclose
135#undef getw
136#undef putw
137#undef freopen
138#undef setbuf
139#undef setvbuf
140#undef fscanf
141#undef fgets
760ac839
LW
142#define fprintf _CANNOT _fprintf_
143#define stdin _CANNOT _stdin_
144#define stdout _CANNOT _stdout_
145#define stderr _CANNOT _stderr_
146#define tmpfile() _CANNOT _tmpfile_
147#define fclose(f) _CANNOT _fclose_
148#define fflush(f) _CANNOT _fflush_
149#define fopen(p,m) _CANNOT _fopen_
150#define freopen(p,m,f) _CANNOT _freopen_
151#define setbuf(f,b) _CANNOT _setbuf_
152#define setvbuf(f,b,x,s) _CANNOT _setvbuf_
153#define fscanf _CANNOT _fscanf_
154#define vfprintf(f,fmt,a) _CANNOT _vfprintf_
155#define fgetc(f) _CANNOT _fgetc_
156#define fgets(s,n,f) _CANNOT _fgets_
157#define fputc(c,f) _CANNOT _fputc_
158#define fputs(s,f) _CANNOT _fputs_
159#define getc(f) _CANNOT _getc_
160#define putc(c,f) _CANNOT _putc_
161#define ungetc(c,f) _CANNOT _ungetc_
162#define fread(b,s,c,f) _CANNOT _fread_
163#define fwrite(b,s,c,f) _CANNOT _fwrite_
164#define fgetpos(f,p) _CANNOT _fgetpos_
165#define fseek(f,o,w) _CANNOT _fseek_
166#define fsetpos(f,p) _CANNOT _fsetpos_
167#define ftell(f) _CANNOT _ftell_
168#define rewind(f) _CANNOT _rewind_
169#define clearerr(f) _CANNOT _clearerr_
170#define feof(f) _CANNOT _feof_
171#define ferror(f) _CANNOT _ferror_
172#define __filbuf(f) _CANNOT __filbuf_
173#define __flsbuf(c,f) _CANNOT __flsbuf_
174#define _filbuf(f) _CANNOT _filbuf_
175#define _flsbuf(c,f) _CANNOT _flsbuf_
176#define fdopen(fd,p) _CANNOT _fdopen_
177#define fileno(f) _CANNOT _fileno_
178#define flockfile(f) _CANNOT _flockfile_
179#define ftrylockfile(f) _CANNOT _ftrylockfile_
180#define funlockfile(f) _CANNOT _funlockfile_
181#define getc_unlocked(f) _CANNOT _getc_unlocked_
182#define putc_unlocked(c,f) _CANNOT _putc_unlocked_
183#define popen(c,m) _CANNOT _popen_
184#define getw(f) _CANNOT _getw_
185#define putw(v,f) _CANNOT _putw_
186#define pclose(f) _CANNOT _pclose_
187
188#else /* if PERLIO_NOT_STDIO */
189/*
190 * PERLIO_NOT_STDIO defined as 0
191 * Declares that both PerlIO and stdio can be used
192 */
193#endif /* if PERLIO_NOT_STDIO */
194#else /* ifdef PERLIO_NOT_STDIO */
195/*
196 * PERLIO_NOT_STDIO not defined
197 * This is "source level" stdio compatibility mode.
198 */
199#include "nostdio.h"
200#undef FILE
201#define FILE PerlIO
33dcbb9a
PP
202#undef fprintf
203#undef tmpfile
204#undef fclose
205#undef fopen
206#undef vfprintf
207#undef fgetc
208#undef fputc
209#undef fputs
210#undef ungetc
211#undef fread
212#undef fwrite
213#undef fgetpos
214#undef fseek
215#undef fsetpos
216#undef ftell
217#undef rewind
218#undef fdopen
219#undef popen
220#undef pclose
221#undef getw
222#undef putw
223#undef freopen
224#undef setbuf
225#undef setvbuf
226#undef fscanf
227#undef fgets
760ac839
LW
228#define fprintf PerlIO_printf
229#define stdin PerlIO_stdin()
230#define stdout PerlIO_stdout()
231#define stderr PerlIO_stderr()
232#define tmpfile() PerlIO_tmpfile()
233#define fclose(f) PerlIO_close(f)
234#define fflush(f) PerlIO_flush(f)
235#define fopen(p,m) PerlIO_open(p,m)
236#define vfprintf(f,fmt,a) PerlIO_vprintf(f,fmt,a)
237#define fgetc(f) PerlIO_getc(f)
238#define fputc(c,f) PerlIO_putc(f,c)
239#define fputs(s,f) PerlIO_puts(f,s)
240#define getc(f) PerlIO_getc(f)
241#define getc_unlocked(f) PerlIO_getc(f)
242#define putc(c,f) PerlIO_putc(f,c)
243#define putc_unlocked(c,f) PerlIO_putc(c,f)
244#define ungetc(c,f) PerlIO_ungetc(f,c)
245#if 0
246/* return values of read/write need work */
247#define fread(b,s,c,f) PerlIO_read(f,b,(s*c))
248#define fwrite(b,s,c,f) PerlIO_write(f,b,(s*c))
249#else
250#define fread(b,s,c,f) _CANNOT fread
251#define fwrite(b,s,c,f) _CANNOT fwrite
252#endif
253#define fgetpos(f,p) PerlIO_getpos(f,p)
254#define fseek(f,o,w) PerlIO_seek(f,o,w)
255#define fsetpos(f,p) PerlIO_setpos(f,p)
256#define ftell(f) PerlIO_tell(f)
257#define rewind(f) PerlIO_rewind(f)
258#define clearerr(f) PerlIO_clearerr(f)
259#define feof(f) PerlIO_eof(f)
260#define ferror(f) PerlIO_error(f)
261#define fdopen(fd,p) PerlIO_fdopen(fd,p)
262#define fileno(f) PerlIO_fileno(f)
263#define popen(c,m) my_popen(c,m)
264#define pclose(f) my_pclose(f)
265
266#define __filbuf(f) _CANNOT __filbuf_
267#define _filbuf(f) _CANNOT _filbuf_
268#define __flsbuf(c,f) _CANNOT __flsbuf_
269#define _flsbuf(c,f) _CANNOT _flsbuf_
270#define getw(f) _CANNOT _getw_
271#define putw(v,f) _CANNOT _putw_
272#define flockfile(f) _CANNOT _flockfile_
273#define ftrylockfile(f) _CANNOT _ftrylockfile_
274#define funlockfile(f) _CANNOT _funlockfile_
275#define freopen(p,m,f) _CANNOT _freopen_
276#define setbuf(f,b) _CANNOT _setbuf_
277#define setvbuf(f,b,x,s) _CANNOT _setvbuf_
278#define fscanf _CANNOT _fscanf_
279#define fgets(s,n,f) _CANNOT _fgets_
280
281#endif /* ifdef PERLIO_NOT_STDIO */
282#endif /* PERLIO_IS_STDIO */