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