This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
VMS fixups for IO::* tests
[perl5.git] / perlsdio.h
1 #ifdef PERLIO_IS_STDIO
2
3 #ifdef NETWARE
4         #include "nwstdio.h"
5 #else
6
7 /*
8  * This file #define-s the PerlIO_xxx abstraction onto stdio functions.
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_isutf8(f)                0
17
18 #define PerlIO_printf                   fprintf
19 #define PerlIO_stdoutf                  printf
20 #define PerlIO_vprintf(f,fmt,a)         vfprintf(f,fmt,a)
21 #define PerlIO_write(f,buf,count)       fwrite1(buf,1,count,f)
22 #define PerlIO_unread(f,buf,count)      (-1)
23 #define PerlIO_open                     fopen
24 #define PerlIO_fdopen                   fdopen
25 #define PerlIO_reopen                   freopen
26 #define PerlIO_close(f)                 fclose(f)
27 #define PerlIO_puts(f,s)                fputs(s,f)
28 #define PerlIO_putc(f,c)                fputc(c,f)
29 #if defined(VMS)
30 #  if defined(__DECC)
31      /* Unusual definition of ungetc() here to accomodate fast_sv_gets()'
32       * belief that it can mix getc/ungetc with reads from stdio buffer */
33      int decc$ungetc(int __c, FILE *__stream);
34 #    define PerlIO_ungetc(f,c) ((c) == EOF ? EOF : \
35             ((*(f) && !((*(f))->_flag & _IONBF) && \
36             ((*(f))->_ptr > (*(f))->_base)) ? \
37             ((*(f))->_cnt++, *(--(*(f))->_ptr) = (c)) : decc$ungetc(c,f)))
38 #  else
39 #    define PerlIO_ungetc(f,c)          ungetc(c,f)
40 #  endif
41    /* Work around bug in DECCRTL/AXP (DECC v5.x) and some versions of old
42     * VAXCRTL which causes read from a pipe after EOF has been returned
43     * once to hang.
44     */
45 #  define PerlIO_getc(f) \
46                 (feof(f) ? EOF : getc(f))
47 #  define PerlIO_read(f,buf,count) \
48                 (feof(f) ? 0 : (SSize_t)fread(buf,1,count,f))
49 #  define PerlIO_tell(f)                ftell(f)
50 #else
51 #  define PerlIO_getc(f)                getc(f)
52 #  define PerlIO_ungetc(f,c)            ungetc(c,f)
53 #  define PerlIO_read(f,buf,count)      (SSize_t)fread(buf,1,count,f)
54 #  define PerlIO_tell(f)                ftell(f)
55 #endif
56 #define PerlIO_eof(f)                   feof(f)
57 #define PerlIO_getname(f,b)             fgetname(f,b)
58 #define PerlIO_error(f)                 ferror(f)
59 #define PerlIO_fileno(f)                fileno(f)
60 #define PerlIO_clearerr(f)              clearerr(f)
61 #define PerlIO_flush(f)                 Fflush(f)
62 #if defined(VMS) && !defined(__DECC)
63 /* Old VAXC RTL doesn't reset EOF on seek; Perl folk seem to expect this */
64 #define PerlIO_seek(f,o,w)      (((f) && (*f) && ((*f)->_flag &= ~_IOEOF)),fseek(f,o,w))
65 #else
66 #  define PerlIO_seek(f,o,w)            fseek(f,o,w)
67 #endif
68
69 #define PerlIO_rewind(f)                rewind(f)
70 #define PerlIO_tmpfile()                tmpfile()
71
72 #define PerlIO_importFILE(f,fl)         (f)
73 #define PerlIO_exportFILE(f,fl)         (f)
74 #define PerlIO_findFILE(f)              (f)
75 #define PerlIO_releaseFILE(p,f)         ((void) 0)
76
77 #ifdef HAS_SETLINEBUF
78 #define PerlIO_setlinebuf(f)            setlinebuf(f);
79 #else
80 #define PerlIO_setlinebuf(f)            setvbuf(f, Nullch, _IOLBF, 0);
81 #endif
82
83 /* Now our interface to Configure's FILE_xxx macros */
84
85 #ifdef USE_STDIO_PTR
86 #define PerlIO_has_cntptr(f)            1
87 #define PerlIO_get_ptr(f)               FILE_ptr(f)
88 #define PerlIO_get_cnt(f)               FILE_cnt(f)
89
90 #ifdef STDIO_CNT_LVALUE
91 #define PerlIO_canset_cnt(f)            1
92 #define PerlIO_set_cnt(f,c)             (FILE_cnt(f) = (c))
93 #ifdef STDIO_PTR_LVALUE
94 #ifdef STDIO_PTR_LVAL_NOCHANGE_CNT
95 #define PerlIO_fast_gets(f)             1
96 #endif
97 #endif /* STDIO_PTR_LVALUE */
98 #else /* STDIO_CNT_LVALUE */
99 #define PerlIO_canset_cnt(f)            0
100 #define PerlIO_set_cnt(f,c)             abort()
101 #endif
102
103 #ifdef STDIO_PTR_LVALUE
104 #ifdef STDIO_PTR_LVAL_NOCHANGE_CNT
105 #define PerlIO_set_ptrcnt(f,p,c)      STMT_START {FILE_ptr(f) = (p), PerlIO_set_cnt(f,c);} STMT_END
106 #else
107 #ifdef STDIO_PTR_LVAL_SETS_CNT
108 /* assert() may pre-process to ""; potential syntax error (FILE_ptr(), ) */
109 #define PerlIO_set_ptrcnt(f,p,c)      STMT_START {FILE_ptr(f) = (p); assert(FILE_cnt(f) == (c));} STMT_END
110 #define PerlIO_fast_gets(f)             1
111 #else
112 #define PerlIO_set_ptrcnt(f,p,c)        abort()
113 #endif
114 #endif
115 #endif
116
117 #else  /* USE_STDIO_PTR */
118
119 #define PerlIO_has_cntptr(f)            0
120 #define PerlIO_canset_cnt(f)            0
121 #define PerlIO_get_cnt(f)               (abort(),0)
122 #define PerlIO_get_ptr(f)               (abort(),(void *)0)
123 #define PerlIO_set_cnt(f,c)             abort()
124 #define PerlIO_set_ptrcnt(f,p,c)        abort()
125
126 #endif /* USE_STDIO_PTR */
127
128 #ifndef PerlIO_fast_gets
129 #define PerlIO_fast_gets(f)             0
130 #endif
131
132
133 #ifdef FILE_base
134 #define PerlIO_has_base(f)              1
135 #define PerlIO_get_base(f)              FILE_base(f)
136 #define PerlIO_get_bufsiz(f)            FILE_bufsiz(f)
137 #else
138 #define PerlIO_has_base(f)              0
139 #define PerlIO_get_base(f)              (abort(),(void *)0)
140 #define PerlIO_get_bufsiz(f)            (abort(),0)
141 #endif
142
143 #endif  /* NETWARE */
144 #endif /* PERLIO_IS_STDIO */