xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/perlsdio.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*    perlsdio.h
2*0Sstevel@tonic-gate  *
3*0Sstevel@tonic-gate  *    Copyright (C) 1996, 1997, 1998, 1999,
4*0Sstevel@tonic-gate  *    2000, 2001, 2002, by Larry Wall and others
5*0Sstevel@tonic-gate  *
6*0Sstevel@tonic-gate  *    You may distribute under the terms of either the GNU General Public
7*0Sstevel@tonic-gate  *    License or the Artistic License, as specified in the README file.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  */
10*0Sstevel@tonic-gate 
11*0Sstevel@tonic-gate #ifdef PERLIO_IS_STDIO
12*0Sstevel@tonic-gate 
13*0Sstevel@tonic-gate #ifdef NETWARE
14*0Sstevel@tonic-gate 	#include "nwstdio.h"
15*0Sstevel@tonic-gate #else
16*0Sstevel@tonic-gate 
17*0Sstevel@tonic-gate /*
18*0Sstevel@tonic-gate  * This file #define-s the PerlIO_xxx abstraction onto stdio functions.
19*0Sstevel@tonic-gate  * Make this as close to original stdio as possible.
20*0Sstevel@tonic-gate  */
21*0Sstevel@tonic-gate #define PerlIO				FILE
22*0Sstevel@tonic-gate #define PerlIO_stderr()			PerlSIO_stderr
23*0Sstevel@tonic-gate #define PerlIO_stdout()			PerlSIO_stdout
24*0Sstevel@tonic-gate #define PerlIO_stdin()			PerlSIO_stdin
25*0Sstevel@tonic-gate 
26*0Sstevel@tonic-gate #define PerlIO_isutf8(f)		0
27*0Sstevel@tonic-gate 
28*0Sstevel@tonic-gate #define PerlIO_printf			PerlSIO_printf
29*0Sstevel@tonic-gate #define PerlIO_stdoutf			PerlSIO_stdoutf
30*0Sstevel@tonic-gate #define PerlIO_vprintf(f,fmt,a)		PerlSIO_vprintf(f,fmt,a)
31*0Sstevel@tonic-gate #define PerlIO_write(f,buf,count)	PerlSIO_fwrite(buf,1,count,f)
32*0Sstevel@tonic-gate #define PerlIO_unread(f,buf,count)	(-1)
33*0Sstevel@tonic-gate #define PerlIO_open			PerlSIO_fopen
34*0Sstevel@tonic-gate #define PerlIO_fdopen			PerlSIO_fdopen
35*0Sstevel@tonic-gate #define PerlIO_reopen			PerlSIO_freopen
36*0Sstevel@tonic-gate #define PerlIO_close(f)			PerlSIO_fclose(f)
37*0Sstevel@tonic-gate #define PerlIO_puts(f,s)		PerlSIO_fputs(f,s)
38*0Sstevel@tonic-gate #define PerlIO_putc(f,c)		PerlSIO_fputc(f,c)
39*0Sstevel@tonic-gate #if defined(VMS)
40*0Sstevel@tonic-gate #  if defined(__DECC)
41*0Sstevel@tonic-gate      /* Unusual definition of ungetc() here to accomodate fast_sv_gets()'
42*0Sstevel@tonic-gate       * belief that it can mix getc/ungetc with reads from stdio buffer */
43*0Sstevel@tonic-gate      int decc$ungetc(int __c, FILE *__stream);
44*0Sstevel@tonic-gate #    define PerlIO_ungetc(f,c) ((c) == EOF ? EOF : \
45*0Sstevel@tonic-gate             ((*(f) && !((*(f))->_flag & _IONBF) && \
46*0Sstevel@tonic-gate             ((*(f))->_ptr > (*(f))->_base)) ? \
47*0Sstevel@tonic-gate             ((*(f))->_cnt++, *(--(*(f))->_ptr) = (c)) : decc$ungetc(c,f)))
48*0Sstevel@tonic-gate #  else
49*0Sstevel@tonic-gate #    define PerlIO_ungetc(f,c)		ungetc(c,f)
50*0Sstevel@tonic-gate #  endif
51*0Sstevel@tonic-gate    /* Work around bug in DECCRTL/AXP (DECC v5.x) and some versions of old
52*0Sstevel@tonic-gate     * VAXCRTL which causes read from a pipe after EOF has been returned
53*0Sstevel@tonic-gate     * once to hang.
54*0Sstevel@tonic-gate     */
55*0Sstevel@tonic-gate #  define PerlIO_getc(f) \
56*0Sstevel@tonic-gate 		(feof(f) ? EOF : getc(f))
57*0Sstevel@tonic-gate #  define PerlIO_read(f,buf,count) \
58*0Sstevel@tonic-gate 		(feof(f) ? 0 : (SSize_t)fread(buf,1,count,f))
59*0Sstevel@tonic-gate #  define PerlIO_tell(f)		ftell(f)
60*0Sstevel@tonic-gate #else
61*0Sstevel@tonic-gate #  define PerlIO_getc(f)		PerlSIO_fgetc(f)
62*0Sstevel@tonic-gate #  define PerlIO_ungetc(f,c)		PerlSIO_ungetc(c,f)
63*0Sstevel@tonic-gate #  define PerlIO_read(f,buf,count)	(SSize_t)PerlSIO_fread(buf,1,count,f)
64*0Sstevel@tonic-gate #  define PerlIO_tell(f)		PerlSIO_ftell(f)
65*0Sstevel@tonic-gate #endif
66*0Sstevel@tonic-gate #define PerlIO_eof(f)			PerlSIO_feof(f)
67*0Sstevel@tonic-gate #define PerlIO_getname(f,b)		fgetname(f,b)
68*0Sstevel@tonic-gate #define PerlIO_error(f)			PerlSIO_ferror(f)
69*0Sstevel@tonic-gate #define PerlIO_fileno(f)		PerlSIO_fileno(f)
70*0Sstevel@tonic-gate #define PerlIO_clearerr(f)		PerlSIO_clearerr(f)
71*0Sstevel@tonic-gate #define PerlIO_flush(f)			PerlSIO_fflush(f)
72*0Sstevel@tonic-gate #if defined(VMS) && !defined(__DECC)
73*0Sstevel@tonic-gate /* Old VAXC RTL doesn't reset EOF on seek; Perl folk seem to expect this */
74*0Sstevel@tonic-gate #define PerlIO_seek(f,o,w)	(((f) && (*f) && ((*f)->_flag &= ~_IOEOF)),fseek(f,o,w))
75*0Sstevel@tonic-gate #else
76*0Sstevel@tonic-gate #  define PerlIO_seek(f,o,w)		PerlSIO_fseek(f,o,w)
77*0Sstevel@tonic-gate #endif
78*0Sstevel@tonic-gate 
79*0Sstevel@tonic-gate #define PerlIO_rewind(f)		PerlSIO_rewind(f)
80*0Sstevel@tonic-gate #define PerlIO_tmpfile()		PerlSIO_tmpfile()
81*0Sstevel@tonic-gate 
82*0Sstevel@tonic-gate #define PerlIO_importFILE(f,fl)		(f)
83*0Sstevel@tonic-gate #define PerlIO_exportFILE(f,fl)		(f)
84*0Sstevel@tonic-gate #define PerlIO_findFILE(f)		(f)
85*0Sstevel@tonic-gate #define PerlIO_releaseFILE(p,f)		((void) 0)
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate #ifdef HAS_SETLINEBUF
88*0Sstevel@tonic-gate #define PerlIO_setlinebuf(f)		PerlSIO_setlinebuf(f);
89*0Sstevel@tonic-gate #else
90*0Sstevel@tonic-gate #define PerlIO_setlinebuf(f)		PerlSIO_setvbuf(f, Nullch, _IOLBF, 0);
91*0Sstevel@tonic-gate #endif
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate /* Now our interface to Configure's FILE_xxx macros */
94*0Sstevel@tonic-gate 
95*0Sstevel@tonic-gate #ifdef USE_STDIO_PTR
96*0Sstevel@tonic-gate #define PerlIO_has_cntptr(f)		1
97*0Sstevel@tonic-gate #define PerlIO_get_ptr(f)		PerlSIO_get_ptr(f)
98*0Sstevel@tonic-gate #define PerlIO_get_cnt(f)		PerlSIO_get_cnt(f)
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate #ifdef STDIO_CNT_LVALUE
101*0Sstevel@tonic-gate #define PerlIO_canset_cnt(f)		1
102*0Sstevel@tonic-gate #define PerlIO_set_cnt(f,c)		PerlSIO_set_cnt(f,c)
103*0Sstevel@tonic-gate #ifdef STDIO_PTR_LVALUE
104*0Sstevel@tonic-gate #ifdef STDIO_PTR_LVAL_NOCHANGE_CNT
105*0Sstevel@tonic-gate #define PerlIO_fast_gets(f)		1
106*0Sstevel@tonic-gate #endif
107*0Sstevel@tonic-gate #endif /* STDIO_PTR_LVALUE */
108*0Sstevel@tonic-gate #else /* STDIO_CNT_LVALUE */
109*0Sstevel@tonic-gate #define PerlIO_canset_cnt(f)		0
110*0Sstevel@tonic-gate #define PerlIO_set_cnt(f,c)		abort()
111*0Sstevel@tonic-gate #endif
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate #ifdef STDIO_PTR_LVALUE
114*0Sstevel@tonic-gate #ifdef STDIO_PTR_LVAL_NOCHANGE_CNT
115*0Sstevel@tonic-gate #define PerlIO_set_ptrcnt(f,p,c)      STMT_START {PerlSIO_set_ptr(f,p), PerlIO_set_cnt(f,c);} STMT_END
116*0Sstevel@tonic-gate #else
117*0Sstevel@tonic-gate #ifdef STDIO_PTR_LVAL_SETS_CNT
118*0Sstevel@tonic-gate /* assert() may pre-process to ""; potential syntax error (FILE_ptr(), ) */
119*0Sstevel@tonic-gate #define PerlIO_set_ptrcnt(f,p,c)      STMT_START {PerlSIO_set_ptr(f,p); assert(PerlSIO_get_cnt(f) == (c));} STMT_END
120*0Sstevel@tonic-gate #define PerlIO_fast_gets(f)		1
121*0Sstevel@tonic-gate #else
122*0Sstevel@tonic-gate #define PerlIO_set_ptrcnt(f,p,c)	abort()
123*0Sstevel@tonic-gate #endif
124*0Sstevel@tonic-gate #endif
125*0Sstevel@tonic-gate #endif
126*0Sstevel@tonic-gate 
127*0Sstevel@tonic-gate #else  /* USE_STDIO_PTR */
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate #define PerlIO_has_cntptr(f)		0
130*0Sstevel@tonic-gate #define PerlIO_canset_cnt(f)		0
131*0Sstevel@tonic-gate #define PerlIO_get_cnt(f)		(abort(),0)
132*0Sstevel@tonic-gate #define PerlIO_get_ptr(f)		(abort(),(void *)0)
133*0Sstevel@tonic-gate #define PerlIO_set_cnt(f,c)		abort()
134*0Sstevel@tonic-gate #define PerlIO_set_ptrcnt(f,p,c)	abort()
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate #endif /* USE_STDIO_PTR */
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate #ifndef PerlIO_fast_gets
139*0Sstevel@tonic-gate #define PerlIO_fast_gets(f)		0
140*0Sstevel@tonic-gate #endif
141*0Sstevel@tonic-gate 
142*0Sstevel@tonic-gate 
143*0Sstevel@tonic-gate #ifdef FILE_base
144*0Sstevel@tonic-gate #define PerlIO_has_base(f)		1
145*0Sstevel@tonic-gate #define PerlIO_get_base(f)		PerlSIO_get_base(f)
146*0Sstevel@tonic-gate #define PerlIO_get_bufsiz(f)		PerlSIO_get_bufsiz(f)
147*0Sstevel@tonic-gate #else
148*0Sstevel@tonic-gate #define PerlIO_has_base(f)		0
149*0Sstevel@tonic-gate #define PerlIO_get_base(f)		(abort(),(void *)0)
150*0Sstevel@tonic-gate #define PerlIO_get_bufsiz(f)		(abort(),0)
151*0Sstevel@tonic-gate #endif
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate #endif	/* NETWARE */
154*0Sstevel@tonic-gate #endif /* PERLIO_IS_STDIO */
155