3 * Copyright (c) 1996, Nick Ing-Simmons
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
13 #define PERLIO_NOT_STDIO 0
14 #if !defined(PERLIO_IS_STDIO) && !defined(USE_SFIO)
18 * This file provides those parts of PerlIO abstraction
19 * which are not #defined in iperlsys.h.
20 * Which these are depends on various Configure #ifdef's
26 #ifdef PERLIO_IS_STDIO
31 /* Does nothing (yet) except force this file to be included
32 in perl binary. That allows this file to force inclusion
33 of other functions that may be required by loadable
34 extensions e.g. for FileHandle::tmpfile
45 #else /* PERLIO_IS_STDIO */
52 /* This section is just to make sure these functions
53 get pulled in from libsfio.a
66 /* Force this file to be included in perl binary. Which allows
67 * this file to force inclusion of other functions that may be
68 * required by loadable extensions e.g. for FileHandle::tmpfile
72 * sfio does its own 'autoflush' on stdout in common cases.
73 * Flush results in a lot of lseek()s to regular files and
74 * lot of small writes to pipes.
76 sfset(sfstdout,SF_SHARE,0);
81 /* Implement all the PerlIO interface using stdio.
82 - this should be only file to include <stdio.h>
89 return (PerlIO *) stderr;
96 return (PerlIO *) stdin;
103 return (PerlIO *) stdout;
106 #undef PerlIO_fast_gets
111 #if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE)
118 #undef PerlIO_has_cntptr
123 #if defined(USE_STDIO_PTR)
130 #undef PerlIO_canset_cnt
135 #if defined(USE_STDIO_PTR) && defined(STDIO_CNT_LVALUE)
142 #undef PerlIO_set_cnt
144 PerlIO_set_cnt(f,cnt)
149 warn("Setting cnt to %d\n",cnt);
150 #if defined(USE_STDIO_PTR) && defined(STDIO_CNT_LVALUE)
153 croak("Cannot set 'cnt' of FILE * on this system");
157 #undef PerlIO_set_ptrcnt
159 PerlIO_set_ptrcnt(f,ptr,cnt)
165 STDCHAR *e = FILE_base(f) + FILE_bufsiz(f);
168 warn("Setting ptr %p > end+1 %p\n", ptr, e + 1);
170 warn("Setting cnt to %d, ptr implies %d\n",cnt,ec);
172 #if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE)
175 croak("Cannot set 'ptr' of FILE * on this system");
177 #if defined(USE_STDIO_PTR) && defined(STDIO_CNT_LVALUE)
180 croak("Cannot set 'cnt' of FILE * on this system");
184 #undef PerlIO_get_cnt
192 croak("Cannot get 'cnt' of FILE * on this system");
197 #undef PerlIO_get_bufsiz
203 return FILE_bufsiz(f);
205 croak("Cannot get 'bufsiz' of FILE * on this system");
210 #undef PerlIO_get_ptr
218 croak("Cannot get 'ptr' of FILE * on this system");
223 #undef PerlIO_get_base
231 croak("Cannot get 'base' of FILE * on this system");
236 #undef PerlIO_has_base
259 PerlIO_open(path,mode)
263 return fopen(path,mode);
268 PerlIO_fdopen(fd,mode)
272 return fdopen(fd,mode);
277 PerlIO_reopen(name, mode, f)
282 return freopen(name,mode,f);
301 #undef PerlIO_getname
303 PerlIO_getname(f,buf)
308 return fgetname(f,buf);
310 croak("Don't know how to get file name");
331 #undef PerlIO_clearerr
355 #undef PerlIO_setlinebuf
360 #ifdef HAS_SETLINEBUF
363 # ifdef __BORLANDC__ /* Borland doesn't like NULL size for _IOLBF */
364 setvbuf(f, Nullch, _IOLBF, BUFSIZ);
366 setvbuf(f, Nullch, _IOLBF, 0);
391 PerlIO_read(f,buf,count)
396 return fread(buf,1,count,f);
401 PerlIO_write(f,buf,count)
406 return fwrite1(buf,1,count,f);
409 #undef PerlIO_vprintf
411 PerlIO_vprintf(f,fmt,ap)
416 return vfprintf(f,fmt,ap);
430 PerlIO_seek(f,offset,whence)
435 return fseek(f,offset,whence);
448 PerlIO_printf(PerlIO *f,const char *fmt,...)
453 result = vfprintf(f,fmt,ap);
458 #undef PerlIO_stdoutf
460 PerlIO_stdoutf(const char *fmt,...)
465 result = PerlIO_vprintf(PerlIO_stdout(),fmt,ap);
470 #undef PerlIO_tmpfile
477 #undef PerlIO_importFILE
479 PerlIO_importFILE(f,fl)
486 #undef PerlIO_exportFILE
488 PerlIO_exportFILE(f,fl)
495 #undef PerlIO_findFILE
503 #undef PerlIO_releaseFILE
505 PerlIO_releaseFILE(p,f)
514 /* Does nothing (yet) except force this file to be included
515 in perl binary. That allows this file to force inclusion
516 of other functions that may be required by loadable
517 extensions e.g. for FileHandle::tmpfile
521 #endif /* USE_SFIO */
522 #endif /* PERLIO_IS_STDIO */
531 return PerlIO_seek(f,*pos,0);
534 #ifndef PERLIO_IS_STDIO
541 return fsetpos(f, pos);
553 *pos = PerlIO_tell(f);
557 #ifndef PERLIO_IS_STDIO
564 return fgetpos(f, pos);
569 #if (defined(PERLIO_IS_STDIO) || !defined(USE_SFIO)) && !defined(HAS_VPRINTF)
575 _doprnt(pat, args, stdout);
576 return 0; /* wrong, but perl doesn't use the return value */
580 vfprintf(fd, pat, args)
584 _doprnt(pat, args, fd);
585 return 0; /* wrong, but perl doesn't use the return value */
590 #ifndef PerlIO_vsprintf
592 PerlIO_vsprintf(char *s, int n, const char *fmt, va_list ap)
594 int val = vsprintf(s, fmt, ap);
597 if (strlen(s) >= (STRLEN)n)
599 PerlIO_puts(PerlIO_stderr(),"panic: sprintf overflow - memory corrupted!\n");
607 #ifndef PerlIO_sprintf
609 PerlIO_sprintf(char *s, int n, const char *fmt,...)
614 result = PerlIO_vsprintf(s, n, fmt, ap);