perlapio.html
来自「perl教程」· HTML 代码 · 共 663 行 · 第 1/3 页
HTML
663 行
to disassociate it from the PerlIO *. (Do not use <a href="#item_perlio_importfile"><code>PerlIO_importFILE()</code></a>
for doing the disassociation.)</p>
</dd>
<dd>
<p>Calling this function repeatedly will create a FILE * on each call
(and will push an :stdio layer each time as well).</p>
</dd>
</li>
<dt><strong><a name="item_perlio_releasefile"><strong>PerlIO_releaseFILE(p,f)</strong></a></strong>
<dd>
<p>Calling PerlIO_releaseFILE informs PerlIO that all use of FILE * is
complete. It is removed from the list of 'exported' FILE *s, and the
associated PerlIO * should revert to its original behaviour.</p>
</dd>
<dd>
<p>Use this to disassociate a file from a PerlIO * that was associated
using PerlIO_exportFILE().</p>
</dd>
</li>
<dt><strong><a name="item_perlio_findfile"><strong>PerlIO_findFILE(f)</strong></a></strong>
<dd>
<p>Returns a native FILE * used by a stdio layer. If there is none, it
will create one with PerlIO_exportFILE. In either case the FILE *
should be considered as belonging to PerlIO subsystem and should
only be closed by calling <a href="#item_perlio_close"><code>PerlIO_close()</code></a>.</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="fast_gets_functions">"Fast gets" Functions</a></h2>
<p>In addition to standard-like API defined so far 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 - or their equivalent in other
implementations. This section is really of interest to only those
concerned with detailed perl-core behaviour, implementing a PerlIO
mapping or writing code which can make use of the "read ahead" that
has been done by the IO system in the same way perl does. Note that
any code that uses these interfaces must be prepared to do things the
traditional way if a handle does not support them.</p>
<dl>
<dt><strong><a name="item_perlio_fast_gets"><strong>PerlIO_fast_gets(f)</strong></a></strong>
<dd>
<p>Returns true if implementation has all the interfaces required to
allow perl's <code>sv_gets</code> to "bypass" normal IO mechanism. This can
vary from handle to handle.</p>
</dd>
<dd>
<pre>
PerlIO_fast_gets(f) = PerlIO_has_cntptr(f) && \
PerlIO_canset_cnt(f) && \
`Can set pointer into buffer'</pre>
</dd>
</li>
<dt><strong><a name="item_perlio_has_cntptr"><strong>PerlIO_has_cntptr(f)</strong></a></strong>
<dd>
<p>Implementation can return pointer to current position in the "buffer"
and a count of bytes available in the buffer. Do not use this - use
PerlIO_fast_gets.</p>
</dd>
</li>
<dt><strong><a name="item_perlio_get_cnt"><strong>PerlIO_get_cnt(f)</strong></a></strong>
<dd>
<p>Return count of readable bytes in the buffer. Zero or negative return
means no more bytes available.</p>
</dd>
</li>
<dt><strong><a name="item_perlio_get_ptr"><strong>PerlIO_get_ptr(f)</strong></a></strong>
<dd>
<p>Return pointer to next readable byte in buffer, accessing via the
pointer (dereferencing) is only safe if <a href="#item_perlio_get_cnt"><code>PerlIO_get_cnt()</code></a> has returned
a positive value. Only positive offsets up to value returned by
<a href="#item_perlio_get_cnt"><code>PerlIO_get_cnt()</code></a> are allowed.</p>
</dd>
</li>
<dt><strong><a name="item_perlio_set_ptrcnt"><strong>PerlIO_set_ptrcnt(f,p,c)</strong></a></strong>
<dd>
<p>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 <a href="#item_perlio_get_ptr"><code>PerlIO_get_ptr</code></a> and <a href="#item_perlio_get_cnt"><code>PerlIO_get_cnt</code></a>. The two
values <em>must</em> be consistent with each other (implementation may only
use one or the other or may require both).</p>
</dd>
</li>
<dt><strong><a name="item_perlio_canset_cnt"><strong>PerlIO_canset_cnt(f)</strong></a></strong>
<dd>
<p>Implementation can adjust its idea of number of bytes in the buffer.
Do not use this - use PerlIO_fast_gets.</p>
</dd>
</li>
<dt><strong><a name="item_perlio_set_cnt"><strong>PerlIO_set_cnt(f,c)</strong></a></strong>
<dd>
<p>Obscure - set count of bytes in the buffer. Deprecated. Only usable
if <a href="#item_perlio_canset_cnt"><code>PerlIO_canset_cnt()</code></a> returns true. Currently used in only doio.c to
force count less than -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". Do not use this - use PerlIO_set_ptrcnt().</p>
</dd>
</li>
<dt><strong><a name="item_perlio_has_base"><strong>PerlIO_has_base(f)</strong></a></strong>
<dd>
<p>Returns true if implementation has a buffer, and can return pointer
to whole buffer and its size. Used by perl for <strong>-T</strong> / <strong>-B</strong> tests.
Other uses would be very obscure...</p>
</dd>
</li>
<dt><strong><a name="item_perlio_get_base"><strong>PerlIO_get_base(f)</strong></a></strong>
<dd>
<p>Return <em>start</em> of buffer. Access only positive offsets in the buffer
up to the value returned by PerlIO_get_bufsiz().</p>
</dd>
</li>
<dt><strong><a name="item_perlio_get_bufsiz"><strong>PerlIO_get_bufsiz(f)</strong></a></strong>
<dd>
<p>Return the <em>total number of bytes</em> in the buffer, this is neither the
number that can be read, nor the amount of memory allocated to the
buffer. Rather it is what the operating system and/or implementation
happened to <a href="../../lib/Pod/perlfunc.html#item_read"><code>read()</code></a> (or whatever) last time IO was requested.</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="other_functions">Other Functions</a></h2>
<dl>
<dt><strong><a name="item_perlio_apply_layers"><code>PerlIO_apply_layers(f,mode,layers)</code></a></strong>
<dd>
<p>The new interface to the USE_PERLIO implementation. The layers ":crlf"
and ":raw" are only ones allowed for other implementations and those
are silently ignored. (As of perl5.8 ":raw" is deprecated.) Use
<a href="#item_perlio_binmode"><code>PerlIO_binmode()</code></a> below for the portable case.</p>
</dd>
</li>
<dt><strong><a name="item_perlio_binmode"><code>PerlIO_binmode(f,ptype,imode,layers)</code></a></strong>
<dd>
<p>The hook used by perl's <a href="../../lib/Pod/perlfunc.html#item_binmode"><code>binmode</code></a> operator.
<strong>ptype</strong> is perl's character for the kind of IO:</p>
</dd>
<dl>
<dt><strong><a name="item__27_3c_27_read">'<' read</a></strong>
<dt><strong><a name="item__27_3e_27_write">'>' write</a></strong>
<dt><strong><a name="item__27_2b_27_read_2fwrite">'+' read/write</a></strong>
</dl>
<p><strong>imode</strong> is <code>O_BINARY</code> or <code>O_TEXT</code>.</p>
<p><strong>layers</strong> is a string of layers to apply, only ":crlf" makes sense in
the non USE_PERLIO case. (As of perl5.8 ":raw" is deprecated in favour
of passing NULL.)</p>
<p>Portable cases are:</p>
<pre>
<span class="variable">PerlIO_binmode</span><span class="operator">(</span><span class="variable">f</span><span class="operator">,</span><span class="variable">ptype</span><span class="operator">,</span><span class="variable">O_BINARY</span><span class="operator">,</span><span class="variable">Nullch</span><span class="operator">);</span>
<span class="keyword">and</span>
<span class="variable">PerlIO_binmode</span><span class="operator">(</span><span class="variable">f</span><span class="operator">,</span><span class="variable">ptype</span><span class="operator">,</span><span class="variable">O_TEXT</span><span class="operator">,</span><span class="string">":crlf"</span><span class="operator">);</span>
</pre>
<p>On Unix these calls probably have no effect whatsoever. Elsewhere
they alter "\n" to CR,LF translation and possibly cause a special text
"end of file" indicator to be written or honoured on read. The effect
of making the call after doing any IO to the handle depends on the
implementation. (It may be ignored, affect any data which is already
buffered as well, or only apply to subsequent data.)</p>
<dt><strong><a name="item_perlio_debug"><code>PerlIO_debug(fmt,...)</code></a></strong>
<dd>
<p>PerlIO_debug is a printf()-like function which can be used for
debugging. No return value. Its main use is inside PerlIO where using
real printf, <a href="../../lib/Pod/perlfunc.html#item_warn"><code>warn()</code></a> etc. would recursively call PerlIO and be a
problem.</p>
</dd>
<dd>
<p>PerlIO_debug writes to the file named by $ENV{'PERLIO_DEBUG'} typical
use might be</p>
</dd>
<dd>
<pre>
Bourne shells (sh, ksh, bash, zsh, ash, ...):
PERLIO_DEBUG=/dev/tty ./perl somescript some args</pre>
</dd>
<dd>
<pre>
Csh/Tcsh:
setenv PERLIO_DEBUG /dev/tty
./perl somescript some args</pre>
</dd>
<dd>
<pre>
If you have the "env" utility:
env PERLIO_DEBUG=/dev/tty ./perl somescript some args</pre>
</dd>
<dd>
<pre>
Win32:
set PERLIO_DEBUG=CON
perl somescript some args</pre>
</dd>
<dd>
<p>If $ENV{'PERLIO_DEBUG'} is not set <a href="#item_perlio_debug"><code>PerlIO_debug()</code></a> is a no-op.</p>
</dd>
</li>
</dl>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?