#define PerlIO_printf fprintf
#define PerlIO_stdoutf printf
#define PerlIO_vprintf(f,fmt,a) vfprintf(f,fmt,a)
-#define PerlIO_read(f,buf,count) fread(buf,1,count,f)
#define PerlIO_write(f,buf,count) fwrite1(buf,1,count,f)
-#define PerlIO_open(path,mode) fopen(path,mode)
-#define PerlIO_fdopen(fd,mode) fdopen(fd,mode)
+#define PerlIO_open fopen
+#define PerlIO_fdopen fdopen
+#define PerlIO_reopen freopen
#define PerlIO_close(f) fclose(f)
#define PerlIO_puts(f,s) fputs(s,f)
#define PerlIO_putc(f,c) fputc(c,f)
-#define PerlIO_ungetc(f,c) ungetc(c,f)
-#define PerlIO_getc(f) getc(f)
+#if defined(VMS)
+# if defined(__DECC)
+ /* Unusual definition of ungetc() here to accomodate fast_sv_gets()'
+ * belief that it can mix getc/ungetc with reads from stdio buffer */
+ int decc$ungetc(int __c, FILE *__stream);
+# define PerlIO_ungetc(f,c) ((c) == EOF ? EOF : \
+ ((*(f) && !((*(f))->_flag & _IONBF) && \
+ ((*(f))->_ptr > (*(f))->_base)) ? \
+ ((*(f))->_cnt++, *(--(*(f))->_ptr) = (c)) : decc$ungetc(c,f)))
+# else
+# define PerlIO_ungetc(f,c) ungetc(c,f)
+# endif
+ /* Work around bug in DECCRTL/AXP (DECC v5.x) and some versions of old
+ * VAXCRTL which causes read from a pipe after EOF has been returned
+ * once to hang.
+ */
+# define PerlIO_getc(f) \
+ (feof(f) ? EOF : getc(f))
+# define PerlIO_read(f,buf,count) \
+ (feof(f) ? 0 : (SSize_t)fread(buf,1,count,f))
+#else
+# define PerlIO_ungetc(f,c) ungetc(c,f)
+# define PerlIO_getc(f) getc(f)
+# define PerlIO_read(f,buf,count) (SSize_t)fread(buf,1,count,f)
+#endif
#define PerlIO_eof(f) feof(f)
+#define PerlIO_getname(f,b) fgetname(f,b)
#define PerlIO_error(f) ferror(f)
#define PerlIO_fileno(f) fileno(f)
#define PerlIO_clearerr(f) clearerr(f)
#define PerlIO_flush(f) Fflush(f)
#define PerlIO_tell(f) ftell(f)
-#define PerlIO_seek(f,o,w) fseek(f,o,w)
+#if defined(VMS) && !defined(__DECC)
+ /* Old VAXC RTL doesn't reset EOF on seek; Perl folk seem to expect this */
+# define PerlIO_seek(f,o,w) (((f) && (*f) && ((*f)->_flag &= ~_IOEOF)),fseek(f,o,w))
+#else
+# define PerlIO_seek(f,o,w) fseek(f,o,w)
+#endif
#ifdef HAS_FGETPOS
#define PerlIO_getpos(f,p) fgetpos(f,p)
#endif
#define PerlIO_get_ptr(f) FILE_ptr(f)
#define PerlIO_get_cnt(f) FILE_cnt(f)
-#ifdef FILE_CNT_LVALUE
+#ifdef STDIO_CNT_LVALUE
#define PerlIO_canset_cnt(f) 1
-#ifdef FILE_PTR_LVALUE
+#ifdef STDIO_PTR_LVALUE
#define PerlIO_fast_gets(f) 1
#endif
#define PerlIO_set_cnt(f,c) (FILE_cnt(f) = (c))
#define PerlIO_set_cnt(f,c) abort()
#endif
-#ifdef FILE_PTR_LVALUE
+#ifdef STDIO_PTR_LVALUE
#define PerlIO_set_ptrcnt(f,p,c) (FILE_ptr(f) = (p), PerlIO_set_cnt(f,c))
#else
#define PerlIO_set_ptrcnt(f,p,c) abort()
#else /* USE_STDIO_PTR */
#define PerlIO_has_cntptr(f) 0
-#define PerlIO_get_cnt(f) abort()
-#define PerlIO_get_ptr(f) abort()
+#define PerlIO_canset_cnt(f) 0
+#define PerlIO_get_cnt(f) (abort(),0)
+#define PerlIO_get_ptr(f) (abort(),(void *)0)
#define PerlIO_set_cnt(f,c) abort()
#define PerlIO_set_ptrcnt(f,p,c) abort()
#define PerlIO_get_bufsiz(f) FILE_bufsiz(f)
#else
#define PerlIO_has_base(f) 0
-#define PerlIO_get_base(f) abort()
-#define PerlIO_get_bufsiz(f) abort()
+#define PerlIO_get_base(f) (abort(),(void *)0)
+#define PerlIO_get_bufsiz(f) (abort(),0)
#endif
#else /* PERLIO_IS_STDIO */
#ifdef PERL_CORE
* Strong denial of stdio - make all stdio calls (we can think of) errors
*/
#include "nostdio.h"
+#undef fprintf
+#undef tmpfile
+#undef fclose
+#undef fopen
+#undef vfprintf
+#undef fgetc
+#undef fputc
+#undef fputs
+#undef ungetc
+#undef fread
+#undef fwrite
+#undef fgetpos
+#undef fseek
+#undef fsetpos
+#undef ftell
+#undef rewind
+#undef fdopen
+#undef popen
+#undef pclose
+#undef getw
+#undef putw
+#undef freopen
+#undef setbuf
+#undef setvbuf
+#undef fscanf
+#undef fgets
+#undef getc_unlocked
+#undef putc_unlocked
#define fprintf _CANNOT _fprintf_
#define stdin _CANNOT _stdin_
#define stdout _CANNOT _stdout_
#include "nostdio.h"
#undef FILE
#define FILE PerlIO
+#undef fprintf
+#undef tmpfile
+#undef fclose
+#undef fopen
+#undef vfprintf
+#undef fgetc
+#undef getc_unlocked
+#undef fputc
+#undef putc_unlocked
+#undef fputs
+#undef ungetc
+#undef fread
+#undef fwrite
+#undef fgetpos
+#undef fseek
+#undef fsetpos
+#undef ftell
+#undef rewind
+#undef fdopen
+#undef popen
+#undef pclose
+#undef getw
+#undef putw
+#undef freopen
+#undef setbuf
+#undef setvbuf
+#undef fscanf
+#undef fgets
#define fprintf PerlIO_printf
#define stdin PerlIO_stdin()
#define stdout PerlIO_stdout()