Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / man / man3 / PerlIO.3
CommitLineData
920dae64
AT
1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "PerlIO 3"
132.TH PerlIO 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide"
133.SH "NAME"
134PerlIO \- On demand loader for PerlIO layers and root of PerlIO::* name space
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 1
138\& open($fh,"<:crlf", "my.txt"); # support platform-native and CRLF text files
139.Ve
140.PP
141.Vb 2
142\& open($fh,"<","his.jpg"); # portably open a binary file for reading
143\& binmode($fh);
144.Ve
145.PP
146.Vb 2
147\& Shell:
148\& PERLIO=perlio perl ....
149.Ve
150.SH "DESCRIPTION"
151.IX Header "DESCRIPTION"
152When an undefined layer 'foo' is encountered in an \f(CW\*(C`open\*(C'\fR or
153\&\f(CW\*(C`binmode\*(C'\fR layer specification then C code performs the equivalent of:
154.PP
155.Vb 1
156\& use PerlIO 'foo';
157.Ve
158.PP
159The perl code in PerlIO.pm then attempts to locate a layer by doing
160.PP
161.Vb 1
162\& require PerlIO::foo;
163.Ve
164.PP
165Otherwise the \f(CW\*(C`PerlIO\*(C'\fR package is a place holder for additional
166PerlIO related functions.
167.PP
168The following layers are currently defined:
169.IP ":unix" 4
170.IX Item ":unix"
171Lowest level layer which provides basic PerlIO operations in terms of
172\&\s-1UNIX/POSIX\s0 numeric file descriptor calls
173(\fIopen()\fR, \fIread()\fR, \fIwrite()\fR, \fIlseek()\fR, \fIclose()\fR).
174.IP ":stdio" 4
175.IX Item ":stdio"
176Layer which calls \f(CW\*(C`fread\*(C'\fR, \f(CW\*(C`fwrite\*(C'\fR and \f(CW\*(C`fseek\*(C'\fR/\f(CW\*(C`ftell\*(C'\fR etc. Note
177that as this is \*(L"real\*(R" stdio it will ignore any layers beneath it and
178got straight to the operating system via the C library as usual.
179.IP ":perlio" 4
180.IX Item ":perlio"
181A from scratch implementation of buffering for PerlIO. Provides fast
182access to the buffer for \f(CW\*(C`sv_gets\*(C'\fR which implements perl's readline/<>
183and in general attempts to minimize data copying.
184.Sp
185\&\f(CW\*(C`:perlio\*(C'\fR will insert a \f(CW\*(C`:unix\*(C'\fR layer below itself to do low level \s-1IO\s0.
186.IP ":crlf" 4
187.IX Item ":crlf"
188A layer that implements DOS/Windows like \s-1CRLF\s0 line endings. On read
189converts pairs of \s-1CR\s0,LF to a single \*(L"\en\*(R" newline character. On write
190converts each \*(L"\en\*(R" to a \s-1CR\s0,LF pair. Note that this layer likes to be
191one of its kind: it silently ignores attempts to be pushed into the
192layer stack more than once.
193.Sp
194It currently does \fInot\fR mimic MS-DOS as far as treating of Control-Z
195as being an end-of-file marker.
196.Sp
197(Gory details follow) To be more exact what happens is this: after
198pushing itself to the stack, the \f(CW\*(C`:crlf\*(C'\fR layer checks all the layers
199below itself to find the first layer that is capable of being a \s-1CRLF\s0
200layer but is not yet enabled to be a \s-1CRLF\s0 layer. If it finds such a
201layer, it enables the CRLFness of that other deeper layer, and then
202pops itself off the stack. If not, fine, use the one we just pushed.
203.Sp
204The end result is that a \f(CW\*(C`:crlf\*(C'\fR means \*(L"please enable the first \s-1CRLF\s0
205layer you can find, and if you can't find one, here would be a good
206spot to place a new one.\*(R"
207.Sp
208Based on the \f(CW\*(C`:perlio\*(C'\fR layer.
209.IP ":mmap" 4
210.IX Item ":mmap"
211A layer which implements \*(L"reading\*(R" of files by using \f(CW\*(C`mmap()\*(C'\fR to
212make (whole) file appear in the process's address space, and then
213using that as PerlIO's \*(L"buffer\*(R". This \fImay\fR be faster in certain
214circumstances for large files, and may result in less physical memory
215use when multiple processes are reading the same file.
216.Sp
217Files which are not \f(CW\*(C`mmap()\*(C'\fR\-able revert to behaving like the \f(CW\*(C`:perlio\*(C'\fR
218layer. Writes also behave like \f(CW\*(C`:perlio\*(C'\fR layer as \f(CW\*(C`mmap()\*(C'\fR for write
219needs extra house-keeping (to extend the file) which negates any advantage.
220.Sp
221The \f(CW\*(C`:mmap\*(C'\fR layer will not exist if platform does not support \f(CW\*(C`mmap()\*(C'\fR.
222.IP ":utf8" 4
223.IX Item ":utf8"
224Declares that the stream accepts perl's internal encoding of
225characters. (Which really is \s-1UTF\-8\s0 on \s-1ASCII\s0 machines, but is
226UTF-EBCDIC on \s-1EBCDIC\s0 machines.) This allows any character perl can
227represent to be read from or written to the stream. The UTF-X encoding
228is chosen to render simple text parts (i.e. non-accented letters,
229digits and common punctuation) human readable in the encoded file.
230.Sp
231Here is how to write your native data out using \s-1UTF\-8\s0 (or \s-1UTF\-EBCDIC\s0)
232and then read it back in.
233.Sp
234.Vb 3
235\& open(F, ">:utf8", "data.utf");
236\& print F $out;
237\& close(F);
238.Ve
239.Sp
240.Vb 3
241\& open(F, "<:utf8", "data.utf");
242\& $in = <F>;
243\& close(F);
244.Ve
245.IP ":bytes" 4
246.IX Item ":bytes"
247This is the inverse of \f(CW\*(C`:utf8\*(C'\fR layer. It turns off the flag
248on the layer below so that data read from it is considered to
249be \*(L"octets\*(R" i.e. characters in range 0..255 only. Likewise
250on output perl will warn if a \*(L"wide\*(R" character is written
251to a such a stream.
252.IP ":raw" 4
253.IX Item ":raw"
254The \f(CW\*(C`:raw\*(C'\fR layer is \fIdefined\fR as being identical to calling
255\&\f(CW\*(C`binmode($fh)\*(C'\fR \- the stream is made suitable for passing binary data
256i.e. each byte is passed as\-is. The stream will still be
257buffered.
258.Sp
259In Perl 5.6 and some books the \f(CW\*(C`:raw\*(C'\fR layer (previously sometimes also
260referred to as a \*(L"discipline\*(R") is documented as the inverse of the
261\&\f(CW\*(C`:crlf\*(C'\fR layer. That is no longer the case \- other layers which would
262alter binary nature of the stream are also disabled. If you want \s-1UNIX\s0
263line endings on a platform that normally does \s-1CRLF\s0 translation, but still
264want \s-1UTF\-8\s0 or encoding defaults the appropriate thing to do is to add
265\&\f(CW\*(C`:perlio\*(C'\fR to \s-1PERLIO\s0 environment variable.
266.Sp
267The implementation of \f(CW\*(C`:raw\*(C'\fR is as a pseudo-layer which when \*(L"pushed\*(R"
268pops itself and then any layers which do not declare themselves as suitable
269for binary data. (Undoing :utf8 and :crlf are implemented by clearing
270flags rather than popping layers but that is an implementation detail.)
271.Sp
272As a consequence of the fact that \f(CW\*(C`:raw\*(C'\fR normally pops layers
273it usually only makes sense to have it as the only or first element in
274a layer specification. When used as the first element it provides
275a known base on which to build e.g.
276.Sp
277.Vb 1
278\& open($fh,":raw:utf8",...)
279.Ve
280.Sp
281will construct a \*(L"binary\*(R" stream, but then enable \s-1UTF\-8\s0 translation.
282.IP ":pop" 4
283.IX Item ":pop"
284A pseudo layer that removes the top-most layer. Gives perl code
285a way to manipulate the layer stack. Should be considered
286as experimental. Note that \f(CW\*(C`:pop\*(C'\fR only works on real layers
287and will not undo the effects of pseudo layers like \f(CW\*(C`:utf8\*(C'\fR.
288An example of a possible use might be:
289.Sp
290.Vb 5
291\& open($fh,...)
292\& ...
293\& binmode($fh,":encoding(...)"); # next chunk is encoded
294\& ...
295\& binmode($fh,":pop"); # back to un-encoded
296.Ve
297.Sp
298A more elegant (and safer) interface is needed.
299.IP ":win32" 4
300.IX Item ":win32"
301On Win32 platforms this \fIexperimental\fR layer uses native \*(L"handle\*(R" \s-1IO\s0
302rather than unix-like numeric file descriptor layer. Known to be
303buggy as of perl 5.8.2.
304.Sh "Custom Layers"
305.IX Subsection "Custom Layers"
306It is possible to write custom layers in addition to the above builtin
307ones, both in C/XS and Perl. Two such layers (and one example written
308in Perl using the latter) come with the Perl distribution.
309.IP ":encoding" 4
310.IX Item ":encoding"
311Use \f(CW\*(C`:encoding(ENCODING)\*(C'\fR either in \fIopen()\fR or \fIbinmode()\fR to install
312a layer that does transparently character set and encoding transformations,
313for example from Shift-JIS to Unicode. Note that under \f(CW\*(C`stdio\*(C'\fR
314an \f(CW\*(C`:encoding\*(C'\fR also enables \f(CW\*(C`:utf8\*(C'\fR. See PerlIO::encoding
315for more information.
316.IP ":via" 4
317.IX Item ":via"
318Use \f(CW\*(C`:via(MODULE)\*(C'\fR either in \fIopen()\fR or \fIbinmode()\fR to install a layer
319that does whatever transformation (for example compression /
320decompression, encryption / decryption) to the filehandle.
321See PerlIO::via for more information.
322.Sh "Alternatives to raw"
323.IX Subsection "Alternatives to raw"
324To get a binary stream an alternate method is to use:
325.PP
326.Vb 2
327\& open($fh,"whatever")
328\& binmode($fh);
329.Ve
330.PP
331this has advantage of being backward compatible with how such things have
332had to be coded on some platforms for years.
333.PP
334To get an un-buffered stream specify an unbuffered layer (e.g. \f(CW\*(C`:unix\*(C'\fR)
335in the open call:
336.PP
337.Vb 1
338\& open($fh,"<:unix",$path)
339.Ve
340.Sh "Defaults and how to override them"
341.IX Subsection "Defaults and how to override them"
342If the platform is MS-DOS like and normally does \s-1CRLF\s0 to \*(L"\en\*(R"
343translation for text files then the default layers are :
344.PP
345.Vb 1
346\& unix crlf
347.Ve
348.PP
349(The low level \*(L"unix\*(R" layer may be replaced by a platform specific low
350level layer.)
351.PP
352Otherwise if \f(CW\*(C`Configure\*(C'\fR found out how to do \*(L"fast\*(R" \s-1IO\s0 using system's
353stdio, then the default layers are:
354.PP
355.Vb 1
356\& unix stdio
357.Ve
358.PP
359Otherwise the default layers are
360.PP
361.Vb 1
362\& unix perlio
363.Ve
364.PP
365These defaults may change once perlio has been better tested and tuned.
366.PP
367The default can be overridden by setting the environment variable
368\&\s-1PERLIO\s0 to a space separated list of layers (\f(CW\*(C`unix\*(C'\fR or platform low
369level layer is always pushed first).
370.PP
371This can be used to see the effect of/bugs in the various layers e.g.
372.PP
373.Vb 3
374\& cd .../perl/t
375\& PERLIO=stdio ./perl harness
376\& PERLIO=perlio ./perl harness
377.Ve
378.PP
379For the various value of \s-1PERLIO\s0 see \*(L"\s-1PERLIO\s0\*(R" in perlrun.
380.Sh "Querying the layers of filehandles"
381.IX Subsection "Querying the layers of filehandles"
382The following returns the \fBnames\fR of the PerlIO layers on a filehandle.
383.PP
384.Vb 1
385\& my @layers = PerlIO::get_layers($fh); # Or FH, *FH, "FH".
386.Ve
387.PP
388The layers are returned in the order an \fIopen()\fR or \fIbinmode()\fR call would
389use them. Note that the \*(L"default stack\*(R" depends on the operating
390system and on the Perl version, and both the compile-time and
391runtime configurations of Perl.
392.PP
393The following table summarizes the default layers on UNIX-like and
394DOS-like platforms and depending on the setting of the \f(CW$ENV{PERLIO}\fR:
395.PP
396.Vb 6
397\& PERLIO UNIX-like DOS-like
398\& ------ --------- --------
399\& unset / "" unix perlio / stdio [1] unix crlf
400\& stdio unix perlio / stdio [1] stdio
401\& perlio unix perlio unix perlio
402\& mmap unix mmap unix mmap
403.Ve
404.PP
405.Vb 2
406\& # [1] "stdio" if Configure found out how to do "fast stdio" (depends
407\& # on the stdio implementation) and in Perl 5.8, otherwise "unix perlio"
408.Ve
409.PP
410By default the layers from the input side of the filehandle is
411returned, to get the output side use the optional \f(CW\*(C`output\*(C'\fR argument:
412.PP
413.Vb 1
414\& my @layers = PerlIO::get_layers($fh, output => 1);
415.Ve
416.PP
417(Usually the layers are identical on either side of a filehandle but
418for example with sockets there may be differences, or if you have
419been using the \f(CW\*(C`open\*(C'\fR pragma.)
420.PP
421There is no \fIset_layers()\fR, nor does \fIget_layers()\fR return a tied array
422mirroring the stack, or anything fancy like that. This is not
423accidental or unintentional. The PerlIO layer stack is a bit more
424complicated than just a stack (see for example the behaviour of \f(CW\*(C`:raw\*(C'\fR).
425You are supposed to use \fIopen()\fR and \fIbinmode()\fR to manipulate the stack.
426.PP
427\&\fBImplementation details follow, please close your eyes.\fR
428.PP
429The arguments to layers are by default returned in parenthesis after
430the name of the layer, and certain layers (like \f(CW\*(C`utf8\*(C'\fR) are not real
431layers but instead flags on real layers: to get all of these returned
432separately use the optional \f(CW\*(C`details\*(C'\fR argument:
433.PP
434.Vb 1
435\& my @layer_and_args_and_flags = PerlIO::get_layers($fh, details => 1);
436.Ve
437.PP
438The result will be up to be three times the number of layers:
439the first element will be a name, the second element the arguments
440(unspecified arguments will be \f(CW\*(C`undef\*(C'\fR), the third element the flags,
441the fourth element a name again, and so forth.
442.PP
443\&\fBYou may open your eyes now.\fR
444.SH "AUTHOR"
445.IX Header "AUTHOR"
446Nick Ing-Simmons <nick@ing\-simmons.net>
447.SH "SEE ALSO"
448.IX Header "SEE ALSO"
449\&\*(L"binmode\*(R" in perlfunc, \*(L"open\*(R" in perlfunc, perlunicode, perliol,
450Encode