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 perlio.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 setvbuf(f, Nullch, _IOLBF, 0);
387 PerlIO_read(f,buf,count)
392 return fread(buf,1,count,f);
397 PerlIO_write(f,buf,count)
402 return fwrite1(buf,1,count,f);
405 #undef PerlIO_vprintf
407 PerlIO_vprintf(f,fmt,ap)
412 return vfprintf(f,fmt,ap);
426 PerlIO_seek(f,offset,whence)
431 return fseek(f,offset,whence);
445 PerlIO_printf(PerlIO *f,const char *fmt,...)
447 PerlIO_printf(f,fmt,va_alist)
460 result = vfprintf(f,fmt,ap);
465 #undef PerlIO_stdoutf
468 PerlIO_stdoutf(const char *fmt,...)
470 PerlIO_stdoutf(fmt, va_alist)
482 result = PerlIO_vprintf(PerlIO_stdout(),fmt,ap);
487 #undef PerlIO_tmpfile
494 #undef PerlIO_importFILE
496 PerlIO_importFILE(f,fl)
503 #undef PerlIO_exportFILE
505 PerlIO_exportFILE(f,fl)
512 #undef PerlIO_findFILE
520 #undef PerlIO_releaseFILE
522 PerlIO_releaseFILE(p,f)
531 /* Does nothing (yet) except force this file to be included
532 in perl binary. That allows this file to force inclusion
533 of other functions that may be required by loadable
534 extensions e.g. for FileHandle::tmpfile
538 #endif /* USE_SFIO */
539 #endif /* PERLIO_IS_STDIO */
548 return PerlIO_seek(f,*pos,0);
551 #ifndef PERLIO_IS_STDIO
558 return fsetpos(f, pos);
570 *pos = PerlIO_tell(f);
574 #ifndef PERLIO_IS_STDIO
581 return fgetpos(f, pos);
586 #if (defined(PERLIO_IS_STDIO) || !defined(USE_SFIO)) && !defined(HAS_VPRINTF)
592 _doprnt(pat, args, stdout);
593 return 0; /* wrong, but perl doesn't use the return value */
597 vfprintf(fd, pat, args)
601 _doprnt(pat, args, fd);
602 return 0; /* wrong, but perl doesn't use the return value */
607 #ifndef PerlIO_vsprintf
609 PerlIO_vsprintf(s,n,fmt,ap)
615 int val = vsprintf(s, fmt, ap);
618 if (strlen(s) >= (STRLEN)n)
620 PerlIO_puts(PerlIO_stderr(),"panic: sprintf overflow - memory corrupted!\n");
628 #ifndef PerlIO_sprintf
631 PerlIO_sprintf(char *s, int n, const char *fmt,...)
633 PerlIO_sprintf(s, n, fmt, va_alist)
647 result = PerlIO_vsprintf(s, n, fmt, ap);