3 * Copyright (c) 1996-1999, 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
108 PerlIO_fast_gets(PerlIO *f)
110 #if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE)
117 #undef PerlIO_has_cntptr
119 PerlIO_has_cntptr(PerlIO *f)
121 #if defined(USE_STDIO_PTR)
128 #undef PerlIO_canset_cnt
130 PerlIO_canset_cnt(PerlIO *f)
132 #if defined(USE_STDIO_PTR) && defined(STDIO_CNT_LVALUE)
139 #undef PerlIO_set_cnt
141 PerlIO_set_cnt(PerlIO *f, int cnt)
144 warn("Setting cnt to %d\n",cnt);
145 #if defined(USE_STDIO_PTR) && defined(STDIO_CNT_LVALUE)
148 croak("Cannot set 'cnt' of FILE * on this system");
152 #undef PerlIO_set_ptrcnt
154 PerlIO_set_ptrcnt(PerlIO *f, STDCHAR *ptr, int cnt)
157 STDCHAR *e = FILE_base(f) + FILE_bufsiz(f);
160 warn("Setting ptr %p > end+1 %p\n", ptr, e + 1);
162 warn("Setting cnt to %d, ptr implies %d\n",cnt,ec);
164 #if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE)
167 croak("Cannot set 'ptr' of FILE * on this system");
169 #if defined(USE_STDIO_PTR) && defined(STDIO_CNT_LVALUE)
172 croak("Cannot set 'cnt' of FILE * on this system");
176 #undef PerlIO_get_cnt
178 PerlIO_get_cnt(PerlIO *f)
183 croak("Cannot get 'cnt' of FILE * on this system");
188 #undef PerlIO_get_bufsiz
190 PerlIO_get_bufsiz(PerlIO *f)
193 return FILE_bufsiz(f);
195 croak("Cannot get 'bufsiz' of FILE * on this system");
200 #undef PerlIO_get_ptr
202 PerlIO_get_ptr(PerlIO *f)
207 croak("Cannot get 'ptr' of FILE * on this system");
212 #undef PerlIO_get_base
214 PerlIO_get_base(PerlIO *f)
219 croak("Cannot get 'base' of FILE * on this system");
224 #undef PerlIO_has_base
226 PerlIO_has_base(PerlIO *f)
237 PerlIO_puts(PerlIO *f, const char *s)
244 PerlIO_open(const char *path, const char *mode)
246 return fopen(path,mode);
251 PerlIO_fdopen(int fd, const char *mode)
253 return fdopen(fd,mode);
258 PerlIO_reopen(const char *name, const char *mode, PerlIO *f)
260 return freopen(name,mode,f);
265 PerlIO_close(PerlIO *f)
272 PerlIO_eof(PerlIO *f)
277 #undef PerlIO_getname
279 PerlIO_getname(PerlIO *f, char *buf)
282 return fgetname(f,buf);
284 croak("Don't know how to get file name");
291 PerlIO_getc(PerlIO *f)
298 PerlIO_error(PerlIO *f)
303 #undef PerlIO_clearerr
305 PerlIO_clearerr(PerlIO *f)
312 PerlIO_flush(PerlIO *f)
319 PerlIO_fileno(PerlIO *f)
324 #undef PerlIO_setlinebuf
326 PerlIO_setlinebuf(PerlIO *f)
328 #ifdef HAS_SETLINEBUF
331 # ifdef __BORLANDC__ /* Borland doesn't like NULL size for _IOLBF */
332 setvbuf(f, Nullch, _IOLBF, BUFSIZ);
334 setvbuf(f, Nullch, _IOLBF, 0);
341 PerlIO_putc(PerlIO *f, int ch)
348 PerlIO_ungetc(PerlIO *f, int ch)
355 PerlIO_read(PerlIO *f, void *buf, Size_t count)
357 return fread(buf,1,count,f);
362 PerlIO_write(PerlIO *f, const void *buf, Size_t count)
364 return fwrite1(buf,1,count,f);
367 #undef PerlIO_vprintf
369 PerlIO_vprintf(PerlIO *f, const char *fmt, va_list ap)
371 return vfprintf(f,fmt,ap);
376 PerlIO_tell(PerlIO *f)
387 PerlIO_seek(PerlIO *f, Off_t offset, int whence)
390 return fseeko(f,offset,whence);
392 return fseek(f,offset,whence);
398 PerlIO_rewind(PerlIO *f)
405 PerlIO_printf(PerlIO *f,const char *fmt,...)
410 result = vfprintf(f,fmt,ap);
415 #undef PerlIO_stdoutf
417 PerlIO_stdoutf(const char *fmt,...)
422 result = PerlIO_vprintf(PerlIO_stdout(),fmt,ap);
427 #undef PerlIO_tmpfile
434 #undef PerlIO_importFILE
436 PerlIO_importFILE(FILE *f, int fl)
441 #undef PerlIO_exportFILE
443 PerlIO_exportFILE(PerlIO *f, int fl)
448 #undef PerlIO_findFILE
450 PerlIO_findFILE(PerlIO *f)
455 #undef PerlIO_releaseFILE
457 PerlIO_releaseFILE(PerlIO *p, FILE *f)
464 /* Does nothing (yet) except force this file to be included
465 in perl binary. That allows this file to force inclusion
466 of other functions that may be required by loadable
467 extensions e.g. for FileHandle::tmpfile
471 #endif /* USE_SFIO */
472 #endif /* PERLIO_IS_STDIO */
477 PerlIO_setpos(PerlIO *f, const Fpos_t *pos)
479 return PerlIO_seek(f,*pos,0);
482 #ifndef PERLIO_IS_STDIO
485 PerlIO_setpos(PerlIO *f, const Fpos_t *pos)
487 return fsetpos(f, pos);
495 PerlIO_getpos(PerlIO *f, Fpos_t *pos)
497 *pos = PerlIO_tell(f);
501 #ifndef PERLIO_IS_STDIO
504 PerlIO_getpos(PerlIO *f, Fpos_t *pos)
506 return fgetpos(f, pos);
511 #if (defined(PERLIO_IS_STDIO) || !defined(USE_SFIO)) && !defined(HAS_VPRINTF)
514 vprintf(char *pat, char *args)
516 _doprnt(pat, args, stdout);
517 return 0; /* wrong, but perl doesn't use the return value */
521 vfprintf(FILE *fd, char *pat, char *args)
523 _doprnt(pat, args, fd);
524 return 0; /* wrong, but perl doesn't use the return value */
529 #ifndef PerlIO_vsprintf
531 PerlIO_vsprintf(char *s, int n, const char *fmt, va_list ap)
533 int val = vsprintf(s, fmt, ap);
536 if (strlen(s) >= (STRLEN)n)
538 PerlIO_puts(PerlIO_stderr(),"panic: sprintf overflow - memory corrupted!\n");
546 #ifndef PerlIO_sprintf
548 PerlIO_sprintf(char *s, int n, const char *fmt,...)
553 result = PerlIO_vsprintf(s, n, fmt, ap);