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