This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Undo #7848. Some of the code seems to use walkoptree(),
[perl5.git] / perlsdio.h
CommitLineData
760ac839
LW
1#ifdef PERLIO_IS_STDIO
2/*
76ced9ad 3 * This file #define-s the PerlIO_xxx abstraction onto stdio functions.
760ac839
LW
4 * Make this as close to original stdio as possible.
5 */
76ced9ad 6#define PerlIO FILE
760ac839
LW
7#define PerlIO_stderr() stderr
8#define PerlIO_stdout() stdout
9#define PerlIO_stdin() stdin
10
76ced9ad
NIS
11#define PerlIO_fdupopen(f) (f)
12#define PerlIO_isutf8(f) 0
13
760ac839
LW
14#define PerlIO_printf fprintf
15#define PerlIO_stdoutf printf
76ced9ad 16#define PerlIO_vprintf(f,fmt,a) vfprintf(f,fmt,a)
760ac839 17#define PerlIO_write(f,buf,count) fwrite1(buf,1,count,f)
c7ae39e5
PP
18#define PerlIO_open fopen
19#define PerlIO_fdopen fdopen
76ced9ad 20#define PerlIO_reopen freopen
fab3f3a7 21#ifdef SOCKS_64BIT_BUG
ad2ffb3e 22# define PerlIO_close(f) (Perl_do_s64_delete_buffer(aTHX_ f), fclose(f))
fab3f3a7
JH
23#else
24# define PerlIO_close(f) fclose(f)
25#endif
760ac839
LW
26#define PerlIO_puts(f,s) fputs(s,f)
27#define PerlIO_putc(f,c) fputc(c,f)
9607fc9c
PP
28#if defined(VMS)
29# if defined(__DECC)
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)))
37# else
38# define PerlIO_ungetc(f,c) ungetc(c,f)
39# endif
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
42 * once to hang.
aa689395 43 */
5b54f415
CS
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))
bf348c40 48# define PerlIO_tell(f) ftell(f)
1ac5d68d 49#else
fab3f3a7 50# ifdef SOCKS_64BIT_BUG
ad2ffb3e
JH
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)
fab3f3a7
JH
55# else
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)
0e32cd81 59# define PerlIO_tell(f) ftell(f)
fab3f3a7 60# endif /* SOCKS_64BIT_BUG */
1ac5d68d 61#endif
760ac839 62#define PerlIO_eof(f) feof(f)
a20bf0c3 63#define PerlIO_getname(f,b) fgetname(f,b)
760ac839
LW
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)
fab3f3a7 68#ifdef SOCKS_64BIT_BUG
ad2ffb3e 69# define PerlIO_seek(f,o,w) Perl_do_s64_seek(aTHX_ f,o,w)
fab3f3a7 70#else
0e32cd81 71# if defined(VMS) && !defined(__DECC)
17f28c40
CB
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))
fab3f3a7
JH
74# else
75# define PerlIO_seek(f,o,w) fseek(f,o,w)
76# endif
17f28c40 77#endif
760ac839
LW
78#ifdef HAS_FGETPOS
79#define PerlIO_getpos(f,p) fgetpos(f,p)
80#endif
81#ifdef HAS_FSETPOS
82#define PerlIO_setpos(f,p) fsetpos(f,p)
83#endif
84
85#define PerlIO_rewind(f) rewind(f)
86#define PerlIO_tmpfile() tmpfile()
87
76ced9ad
NIS
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)
760ac839
LW
92
93#ifdef HAS_SETLINEBUF
94#define PerlIO_setlinebuf(f) setlinebuf(f);
95#else
4fabb596 96#define PerlIO_setlinebuf(f) setvbuf(f, Nullch, _IOLBF, 0);
760ac839
LW
97#endif
98
99/* Now our interface to Configure's FILE_xxx macros */
100
101#ifdef USE_STDIO_PTR
76ced9ad
NIS
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)
760ac839 105
c7ae39e5 106#ifdef STDIO_CNT_LVALUE
76ced9ad
NIS
107#define PerlIO_canset_cnt(f) 1
108#define PerlIO_set_cnt(f,c) (FILE_cnt(f) = (c))
c7ae39e5 109#ifdef STDIO_PTR_LVALUE
a7ffa9b9 110#ifdef STDIO_PTR_LVAL_NOCHANGE_CNT
76ced9ad 111#define PerlIO_fast_gets(f) 1
760ac839 112#endif
a7ffa9b9
NC
113#endif /* STDIO_PTR_LVALUE */
114#else /* STDIO_CNT_LVALUE */
76ced9ad 115#define PerlIO_canset_cnt(f) 0
a20bf0c3 116#define PerlIO_set_cnt(f,c) abort()
760ac839
LW
117#endif
118
c7ae39e5 119#ifdef STDIO_PTR_LVALUE
a7ffa9b9 120#ifdef STDIO_PTR_LVAL_NOCHANGE_CNT
bd0e0981 121#define PerlIO_set_ptrcnt(f,p,c) STMT_START {FILE_ptr(f) = (p), PerlIO_set_cnt(f,c);} STMT_END
a7ffa9b9
NC
122#else
123#ifdef STDIO_PTR_LVAL_SETS_CNT
124/* assert() may pre-process to ""; potential syntax error (FILE_ptr(), ) */
bd0e0981 125#define PerlIO_set_ptrcnt(f,p,c) STMT_START {FILE_ptr(f) = (p); assert(FILE_cnt(f) == (c));} STMT_END
76ced9ad 126#define PerlIO_fast_gets(f) 1
760ac839 127#else
a20bf0c3 128#define PerlIO_set_ptrcnt(f,p,c) abort()
760ac839 129#endif
a7ffa9b9
NC
130#endif
131#endif
760ac839
LW
132
133#else /* USE_STDIO_PTR */
134
135#define PerlIO_has_cntptr(f) 0
c7ae39e5 136#define PerlIO_canset_cnt(f) 0
a20bf0c3
JH
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()
760ac839
LW
141
142#endif /* USE_STDIO_PTR */
143
144#ifndef PerlIO_fast_gets
76ced9ad 145#define PerlIO_fast_gets(f) 0
760ac839
LW
146#endif
147
148
149#ifdef FILE_base
76ced9ad
NIS
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)
760ac839
LW
153#else
154#define PerlIO_has_base(f) 0
a20bf0c3
JH
155#define PerlIO_get_base(f) (abort(),(void *)0)
156#define PerlIO_get_bufsiz(f) (abort(),0)
760ac839 157#endif
760ac839 158
760ac839 159#endif /* PERLIO_IS_STDIO */