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 # 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);
449 PerlIO_printf(PerlIO *f,const char *fmt,...)
451 PerlIO_printf(f,fmt,va_alist)
464 result = vfprintf(f,fmt,ap);
469 #undef PerlIO_stdoutf
472 PerlIO_stdoutf(const char *fmt,...)
474 PerlIO_stdoutf(fmt, va_alist)
486 result = PerlIO_vprintf(PerlIO_stdout(),fmt,ap);
491 #undef PerlIO_tmpfile
498 #undef PerlIO_importFILE
500 PerlIO_importFILE(f,fl)
507 #undef PerlIO_exportFILE
509 PerlIO_exportFILE(f,fl)
516 #undef PerlIO_findFILE
524 #undef PerlIO_releaseFILE
526 PerlIO_releaseFILE(p,f)
535 /* Does nothing (yet) except force this file to be included
536 in perl binary. That allows this file to force inclusion
537 of other functions that may be required by loadable
538 extensions e.g. for FileHandle::tmpfile
542 #endif /* USE_SFIO */
543 #endif /* PERLIO_IS_STDIO */
552 return PerlIO_seek(f,*pos,0);
555 #ifndef PERLIO_IS_STDIO
562 return fsetpos(f, pos);
574 *pos = PerlIO_tell(f);
578 #ifndef PERLIO_IS_STDIO
585 return fgetpos(f, pos);
590 #if (defined(PERLIO_IS_STDIO) || !defined(USE_SFIO)) && !defined(HAS_VPRINTF)
596 _doprnt(pat, args, stdout);
597 return 0; /* wrong, but perl doesn't use the return value */
601 vfprintf(fd, pat, args)
605 _doprnt(pat, args, fd);
606 return 0; /* wrong, but perl doesn't use the return value */
611 #ifndef PerlIO_vsprintf
613 PerlIO_vsprintf(char *s, int n, const char *fmt, va_list 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);