<?xml version="1.0" encoding="windows-1252"?>
<node id="384" title="perlman:perlapio" created="1999-08-25 02:20:26" updated="2005-08-11 23:04:53">
<type id="116">
perlman</type>
<author id="114">
gods</author>
<data>
<field name="doctext">


&lt;HR&gt;
&lt;P&gt;
&lt;H1&gt;&lt;A NAME="NAME"&gt;NAME&lt;/A&gt;&lt;/H1&gt;
&lt;P&gt;
perlapio - perl's 
&lt;FONT SIZE=-1&gt;IO&lt;/FONT&gt; abstraction interface.

&lt;P&gt;
&lt;HR&gt;
&lt;H1&gt;&lt;A NAME="SYNOPSIS"&gt;SYNOPSIS&lt;/A&gt;&lt;/H1&gt;
&lt;P&gt;
&lt;PRE&gt;    PerlIO *PerlIO_stdin(void);
    PerlIO *PerlIO_stdout(void);
    PerlIO *PerlIO_stderr(void);
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;    PerlIO *PerlIO_open(const char *,const char *);
    int     PerlIO_close(PerlIO *);
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;    int     PerlIO_stdoutf(const char *,...)
    int     PerlIO_puts(PerlIO *,const char *);
    int     PerlIO_putc(PerlIO *,int);
    int     PerlIO_write(PerlIO *,const void *,size_t);
    int     PerlIO_printf(PerlIO *, const char *,...);
    int     PerlIO_vprintf(PerlIO *, const char *, va_list);
    int     PerlIO_flush(PerlIO *);
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;    int     PerlIO_eof(PerlIO *);
    int     PerlIO_error(PerlIO *);
    void    PerlIO_clearerr(PerlIO *);
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;    int     PerlIO_getc(PerlIO *);
    int     PerlIO_ungetc(PerlIO *,int);
    int     PerlIO_read(PerlIO *,void *,size_t);
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;    int     PerlIO_fileno(PerlIO *);
    PerlIO *PerlIO_fdopen(int, const char *);
    PerlIO *PerlIO_importFILE(FILE *, int flags);
    FILE   *PerlIO_exportFILE(PerlIO *, int flags);
    FILE   *PerlIO_findFILE(PerlIO *);
    void    PerlIO_releaseFILE(PerlIO *,FILE *);
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;    void    PerlIO_setlinebuf(PerlIO *);
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;    long    PerlIO_tell(PerlIO *);
    int     PerlIO_seek(PerlIO *,off_t,int);
    int     PerlIO_getpos(PerlIO *,Fpos_t *)
    int     PerlIO_setpos(PerlIO *,Fpos_t *)
    void    PerlIO_rewind(PerlIO *);
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;    int     PerlIO_has_base(PerlIO *);
    int     PerlIO_has_cntptr(PerlIO *);
    int     PerlIO_fast_gets(PerlIO *);
    int     PerlIO_canset_cnt(PerlIO *);
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;    char   *PerlIO_get_ptr(PerlIO *);
    int     PerlIO_get_cnt(PerlIO *);
    void    PerlIO_set_cnt(PerlIO *,int);
    void    PerlIO_set_ptrcnt(PerlIO *,char *,int);
    char   *PerlIO_get_base(PerlIO *);
    int     PerlIO_get_bufsiz(PerlIO *);
&lt;/PRE&gt;
&lt;P&gt;
&lt;HR&gt;
&lt;H1&gt;&lt;A NAME="DESCRIPTION"&gt;DESCRIPTION&lt;/A&gt;&lt;/H1&gt;
&lt;P&gt;
Perl's source code should use the above functions instead of those defined in 
&lt;FONT SIZE=-1&gt;ANSI&lt;/FONT&gt; C's
 &lt;EM&gt;stdio.h&lt;/EM&gt;. The perl headers will &lt;CODE&gt;#define&lt;/CODE&gt; them to the 
&lt;FONT SIZE=-1&gt;I/O&lt;/FONT&gt; mechanism selected at Configure time.

&lt;P&gt;
The functions are modeled on those in &lt;EM&gt;stdio.h&lt;/EM&gt;, but parameter order has been ``tidied up a little''.

&lt;DL&gt;
&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO"&gt;PerlIO *&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
This takes the place of 
&lt;FONT SIZE=-1&gt;FILE&lt;/FONT&gt; *. Like 
&lt;FONT SIZE=-1&gt;FILE&lt;/FONT&gt; * it should be treated as opaque (it is probably safe to assume it is a pointer to something).

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_stdin"&gt;PerlIO_stdin(), PerlIO_stdout(), PerlIO_stderr()&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Use these rather than &lt;CODE&gt;stdin&lt;/CODE&gt;, &lt;CODE&gt;stdout&lt;/CODE&gt;, &lt;CODE&gt;stderr&lt;/CODE&gt;. They are written to look like ``function calls'' rather than variables
because this makes it easier to &lt;EM&gt;make them&lt;/EM&gt; function calls if platform cannot export data to loaded modules, or if
(say) different ``threads'' might have different values.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_open"&gt;PerlIO_open(path, mode), PerlIO_fdopen(fd,mode)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
These correspond to 
&lt;CODE&gt;fopen()/fdopen()&lt;/CODE&gt;
arguments are the same.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_printf"&gt;PerlIO_printf(f,fmt,...), PerlIO_vprintf(f,fmt,a)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
These are 
&lt;CODE&gt;fprintf()/vfprintf()&lt;/CODE&gt;
equivalents.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_stdoutf"&gt;PerlIO_stdoutf(fmt,...)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
This is 
&lt;CODE&gt;printf()&lt;/CODE&gt; equivalent. printf
is #defined to this function, so it is (currently) legal to use [perlfunc:printf|printf(fmt,...)] in perl sources.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_read"&gt;PerlIO_read(f,buf,count), PerlIO_write(f,buf,count)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
These correspond to 
&lt;CODE&gt;fread()&lt;/CODE&gt; and 
&lt;CODE&gt;fwrite().&lt;/CODE&gt; Note that arguments are different, there is only one ``count'' and order has ``file'' first.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_close"&gt;PerlIO_close(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;DD&gt;
&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_puts"&gt;PerlIO_puts(f,s), PerlIO_putc(f,c)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
These correspond to 
&lt;CODE&gt;fputs()&lt;/CODE&gt; and 
&lt;CODE&gt;fputc().&lt;/CODE&gt; Note that arguments have been revised to have ``file'' first.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_ungetc"&gt;PerlIO_ungetc(f,c)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
This corresponds to 
&lt;CODE&gt;ungetc().&lt;/CODE&gt; Note that arguments
have been revised to have ``file'' first.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_getc"&gt;PerlIO_getc(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
This corresponds to 
&lt;CODE&gt;getc().&lt;/CODE&gt;

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_eof"&gt;PerlIO_eof(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
This corresponds to 
&lt;CODE&gt;feof().&lt;/CODE&gt;

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_error"&gt;PerlIO_error(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
This corresponds to 
&lt;CODE&gt;ferror().&lt;/CODE&gt;

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_fileno"&gt;PerlIO_fileno(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
This corresponds to 
&lt;CODE&gt;fileno(),&lt;/CODE&gt; note that on some
platforms, the meaning of ``fileno'' may not match Unix.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_clearerr"&gt;PerlIO_clearerr(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
This corresponds to 
&lt;CODE&gt;clearerr(),&lt;/CODE&gt; i.e., clears
'eof' and 'error' flags for the ``stream''.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_flush"&gt;PerlIO_flush(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
This corresponds to 
&lt;CODE&gt;fflush().&lt;/CODE&gt;

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_tell"&gt;PerlIO_tell(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
This corresponds to 
&lt;CODE&gt;ftell().&lt;/CODE&gt;

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_seek"&gt;PerlIO_seek(f,o,w)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
This corresponds to 
&lt;CODE&gt;fseek().&lt;/CODE&gt;

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_getpos"&gt;PerlIO_getpos(f,p), PerlIO_setpos(f,p)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
These correspond to 
&lt;CODE&gt;fgetpos()&lt;/CODE&gt; and 
&lt;CODE&gt;fsetpos().&lt;/CODE&gt; If platform does not have the stdio calls then they are implemented in terms of 
&lt;CODE&gt;PerlIO_tell()&lt;/CODE&gt; and 
&lt;CODE&gt;PerlIO_seek().&lt;/CODE&gt;

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_rewind"&gt;PerlIO_rewind(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
This corresponds to 
&lt;CODE&gt;rewind().&lt;/CODE&gt; Note may be redefined in terms of 
&lt;CODE&gt;PerlIO_seek()&lt;/CODE&gt; at some point.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_tmpfile"&gt;PerlIO_tmpfile()&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
This corresponds to 
&lt;CODE&gt;tmpfile(),&lt;/CODE&gt; i.e., returns an
anonymous PerlIO which will automatically be deleted when closed.

&lt;/DL&gt;
&lt;P&gt;
&lt;HR&gt;
&lt;H2&gt;&lt;A NAME="Co_existence_with_stdio"&gt;Co-existence with stdio&lt;/A&gt;&lt;/H2&gt;
&lt;P&gt;
There is outline support for co-existence of PerlIO with stdio. Obviously if PerlIO is implemented in terms of stdio there is no problem. However if perlio is implemented on top of (say) sfio then mechanisms must exist to create a 
&lt;FONT SIZE=-1&gt;FILE&lt;/FONT&gt; * which can be passed to library code which is going to use stdio calls.

&lt;DL&gt;
&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_importFILE"&gt;PerlIO_importFILE(f,flags)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Used to get a PerlIO * from a 
&lt;FONT SIZE=-1&gt;FILE&lt;/FONT&gt; *. May need additional arguments, interface under
review.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_exportFILE"&gt;PerlIO_exportFILE(f,flags)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Given an PerlIO * return a 'native' 
&lt;FONT SIZE=-1&gt;FILE&lt;/FONT&gt; * suitable for passing to code expecting to be compiled and linked with 
&lt;FONT SIZE=-1&gt;ANSI&lt;/FONT&gt; 
&lt;FONT SIZE=-1&gt;C&lt;/FONT&gt;
 &lt;EM&gt;stdio.h&lt;/EM&gt;.

&lt;P&gt;
The fact that such a 
&lt;FONT SIZE=-1&gt;FILE&lt;/FONT&gt; * has been 'exported' is recorded, and may affect
future PerlIO operations on the original PerlIO *.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_findFILE"&gt;PerlIO_findFILE(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Returns previously 'exported' 
&lt;FONT SIZE=-1&gt;FILE&lt;/FONT&gt; * (if any). Place holder until interface is fully
defined.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_releaseFILE"&gt;PerlIO_releaseFILE(p,f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Calling PerlIO_releaseFILE informs PerlIO that all use of 
&lt;FONT SIZE=-1&gt;FILE&lt;/FONT&gt; * is complete. It is removed from list of 'exported' 
&lt;FONT SIZE=-1&gt;FILE&lt;/FONT&gt; *s, and associated PerlIO * should revert to original behaviour.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_setlinebuf"&gt;PerlIO_setlinebuf(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
This corresponds to 
&lt;CODE&gt;setlinebuf().&lt;/CODE&gt; Use is
deprecated pending further discussion. (Perl core uses it &lt;EM&gt;only&lt;/EM&gt; when ``dumping''; it has nothing to do with $| auto-flush.)

&lt;/DL&gt;
&lt;P&gt;
In addition to user 
&lt;FONT SIZE=-1&gt;API&lt;/FONT&gt; above there is an ``implementation'' interface
which allows perl to get at internals of PerlIO. The following calls
correspond to the various FILE_xxx macros determined by Configure. This
section is really of interest to only those concerned with detailed
perl-core behaviour or implementing a PerlIO mapping.

&lt;DL&gt;
&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_has_cntptr"&gt;PerlIO_has_cntptr(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Implementation can return pointer to current position in the ``buffer'' and
a count of bytes available in the buffer.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_get_ptr"&gt;PerlIO_get_ptr(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Return pointer to next readable byte in buffer.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_get_cnt"&gt;PerlIO_get_cnt(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Return count of readable bytes in the buffer.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_canset_cnt"&gt;PerlIO_canset_cnt(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Implementation can adjust its idea of number of bytes in the buffer.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_fast_gets"&gt;PerlIO_fast_gets(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Implementation has all the interfaces required to allow perl's fast code to handle 
&lt;FONT SIZE=-1&gt;&amp;lt;FILE&amp;gt;&lt;/FONT&gt; mechanism.

&lt;P&gt;
&lt;PRE&gt;  PerlIO_fast_gets(f) = PerlIO_has_cntptr(f) &amp;amp;&amp;amp; \
                        PerlIO_canset_cnt(f) &amp;amp;&amp;amp; \
                        `Can set pointer into buffer'
&lt;/PRE&gt;
&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_set_ptrcnt"&gt;PerlIO_set_ptrcnt(f,p,c)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Set pointer into buffer, and a count of bytes still in the buffer. Should
be used only to set pointer to within range implied by previous calls to &lt;CODE&gt;PerlIO_get_ptr&lt;/CODE&gt; and &lt;CODE&gt;PerlIO_get_cnt&lt;/CODE&gt;.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_set_cnt"&gt;PerlIO_set_cnt(f,c)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Obscure - set count of bytes in the buffer. Deprecated. Currently used in
only doio.c to force count &amp;lt; -1 to -1. Perhaps should be
PerlIO_set_empty or similar. This call may actually do nothing if ``count''
is deduced from pointer and a ``limit''.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_has_base"&gt;PerlIO_has_base(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Implementation has a buffer, and can return pointer to whole buffer and its
size. Used by perl for &lt;STRONG&gt;-T&lt;/STRONG&gt; / &lt;STRONG&gt;-B&lt;/STRONG&gt; tests. Other uses would be very obscure...

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_get_base"&gt;PerlIO_get_base(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Return &lt;EM&gt;start&lt;/EM&gt; of buffer.

&lt;P&gt;&lt;DT&gt;&lt;STRONG&gt;&lt;A NAME="item_PerlIO_get_bufsiz"&gt;PerlIO_get_bufsiz(f)&lt;/A&gt;&lt;/STRONG&gt;&lt;P&gt;
&lt;DD&gt;
Return &lt;EM&gt;total size&lt;/EM&gt; of buffer.

&lt;/DL&gt;
&lt;HR&gt;
&lt;BR&gt;Return to the [Library]&lt;BR&gt;</field>
</data>
</node>
