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