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);
433 PerlIO_seek(f,offset,whence)
439 return fseeko(f,offset,whence);
441 return fseek(f,offset,whence);
455 PerlIO_printf(PerlIO *f,const char *fmt,...)
460 result = vfprintf(f,fmt,ap);
465 #undef PerlIO_stdoutf
467 PerlIO_stdoutf(const char *fmt,...)
472 result = PerlIO_vprintf(PerlIO_stdout(),fmt,ap);
477 #undef PerlIO_tmpfile
484 #undef PerlIO_importFILE
486 PerlIO_importFILE(f,fl)
493 #undef PerlIO_exportFILE
495 PerlIO_exportFILE(f,fl)
502 #undef PerlIO_findFILE
510 #undef PerlIO_releaseFILE
512 PerlIO_releaseFILE(p,f)
521 /* Does nothing (yet) except force this file to be included
522 in perl binary. That allows this file to force inclusion
523 of other functions that may be required by loadable
524 extensions e.g. for FileHandle::tmpfile
528 #endif /* USE_SFIO */
529 #endif /* PERLIO_IS_STDIO */
538 return PerlIO_seek(f,*pos,0);
541 #ifndef PERLIO_IS_STDIO
548 return fsetpos(f, pos);
560 *pos = PerlIO_tell(f);
564 #ifndef PERLIO_IS_STDIO
571 return fgetpos(f, pos);
576 #if (defined(PERLIO_IS_STDIO) || !defined(USE_SFIO)) && !defined(HAS_VPRINTF)
582 _doprnt(pat, args, stdout);
583 return 0; /* wrong, but perl doesn't use the return value */
587 vfprintf(fd, pat, args)
591 _doprnt(pat, args, fd);
592 return 0; /* wrong, but perl doesn't use the return value */
597 #ifndef PerlIO_vsprintf
599 PerlIO_vsprintf(char *s, int n, const char *fmt, va_list ap)
601 int val = vsprintf(s, fmt, ap);
604 if (strlen(s) >= (STRLEN)n)
606 PerlIO_puts(PerlIO_stderr(),"panic: sprintf overflow - memory corrupted!\n");
614 #ifndef PerlIO_sprintf
616 PerlIO_sprintf(char *s, int n, const char *fmt,...)
621 result = PerlIO_vsprintf(s, n, fmt, ap);