Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / man / man3 / IO::Handle.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 "IO::Handle 3"
132.TH IO::Handle 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide"
133.SH "NAME"
134IO::Handle \- supply object methods for I/O handles
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 1
138\& use IO::Handle;
139.Ve
140.PP
141.Vb 5
142\& $io = new IO::Handle;
143\& if ($io->fdopen(fileno(STDIN),"r")) {
144\& print $io->getline;
145\& $io->close;
146\& }
147.Ve
148.PP
149.Vb 4
150\& $io = new IO::Handle;
151\& if ($io->fdopen(fileno(STDOUT),"w")) {
152\& $io->print("Some text\en");
153\& }
154.Ve
155.PP
156.Vb 3
157\& # setvbuf is not available by default on Perls 5.8.0 and later.
158\& use IO::Handle '_IOLBF';
159\& $io->setvbuf($buffer_var, _IOLBF, 1024);
160.Ve
161.PP
162.Vb 1
163\& undef $io; # automatically closes the file if it's open
164.Ve
165.PP
166.Vb 1
167\& autoflush STDOUT 1;
168.Ve
169.SH "DESCRIPTION"
170.IX Header "DESCRIPTION"
171\&\f(CW\*(C`IO::Handle\*(C'\fR is the base class for all other \s-1IO\s0 handle classes. It is
172not intended that objects of \f(CW\*(C`IO::Handle\*(C'\fR would be created directly,
173but instead \f(CW\*(C`IO::Handle\*(C'\fR is inherited from by several other classes
174in the \s-1IO\s0 hierarchy.
175.PP
176If you are reading this documentation, looking for a replacement for
177the \f(CW\*(C`FileHandle\*(C'\fR package, then I suggest you read the documentation
178for \f(CW\*(C`IO::File\*(C'\fR too.
179.SH "CONSTRUCTOR"
180.IX Header "CONSTRUCTOR"
181.IP "new ()" 4
182.IX Item "new ()"
183Creates a new \f(CW\*(C`IO::Handle\*(C'\fR object.
184.IP "new_from_fd ( \s-1FD\s0, \s-1MODE\s0 )" 4
185.IX Item "new_from_fd ( FD, MODE )"
186Creates an \f(CW\*(C`IO::Handle\*(C'\fR like \f(CW\*(C`new\*(C'\fR does.
187It requires two parameters, which are passed to the method \f(CW\*(C`fdopen\*(C'\fR;
188if the fdopen fails, the object is destroyed. Otherwise, it is returned
189to the caller.
190.SH "METHODS"
191.IX Header "METHODS"
192See perlfunc for complete descriptions of each of the following
193supported \f(CW\*(C`IO::Handle\*(C'\fR methods, which are just front ends for the
194corresponding built-in functions:
195.PP
196.Vb 12
197\& $io->close
198\& $io->eof
199\& $io->fileno
200\& $io->format_write( [FORMAT_NAME] )
201\& $io->getc
202\& $io->read ( BUF, LEN, [OFFSET] )
203\& $io->print ( ARGS )
204\& $io->printf ( FMT, [ARGS] )
205\& $io->stat
206\& $io->sysread ( BUF, LEN, [OFFSET] )
207\& $io->syswrite ( BUF, [LEN, [OFFSET]] )
208\& $io->truncate ( LEN )
209.Ve
210.PP
211See perlvar for complete descriptions of each of the following
212supported \f(CW\*(C`IO::Handle\*(C'\fR methods. All of them return the previous
213value of the attribute and takes an optional single argument that when
214given will set the value. If no argument is given the previous value
215is unchanged (except for \f(CW$io\fR\->autoflush will actually turn \s-1ON\s0
216autoflush by default).
217.PP
218.Vb 7
219\& $io->autoflush ( [BOOL] ) $|
220\& $io->format_page_number( [NUM] ) $%
221\& $io->format_lines_per_page( [NUM] ) $=
222\& $io->format_lines_left( [NUM] ) $-
223\& $io->format_name( [STR] ) $~
224\& $io->format_top_name( [STR] ) $^
225\& $io->input_line_number( [NUM]) $.
226.Ve
227.PP
228The following methods are not supported on a per-filehandle basis.
229.PP
230.Vb 4
231\& IO::Handle->format_line_break_characters( [STR] ) $:
232\& IO::Handle->format_formfeed( [STR]) $^L
233\& IO::Handle->output_field_separator( [STR] ) $,
234\& IO::Handle->output_record_separator( [STR] ) $\e
235.Ve
236.PP
237.Vb 1
238\& IO::Handle->input_record_separator( [STR] ) $/
239.Ve
240.PP
241Furthermore, for doing normal I/O you might need these:
242.IP "$io\->fdopen ( \s-1FD\s0, \s-1MODE\s0 )" 4
243.IX Item "$io->fdopen ( FD, MODE )"
244\&\f(CW\*(C`fdopen\*(C'\fR is like an ordinary \f(CW\*(C`open\*(C'\fR except that its first parameter
245is not a filename but rather a file handle name, an IO::Handle object,
246or a file descriptor number.
247.IP "$io\->opened" 4
248.IX Item "$io->opened"
249Returns true if the object is currently a valid file descriptor, false
250otherwise.
251.IP "$io\->getline" 4
252.IX Item "$io->getline"
253This works like <$io> described in \*(L"I/O Operators\*(R" in perlop
254except that it's more readable and can be safely called in a
255list context but still returns just one line. If used as the conditional
256+within a \f(CW\*(C`while\*(C'\fR or C\-style \f(CW\*(C`for\*(C'\fR loop, however, you will need to
257+emulate the functionality of <$io> with \f(CW\*(C`defined($_ = $io\->getline)\*(C'\fR.
258.IP "$io\->getlines" 4
259.IX Item "$io->getlines"
260This works like <$io> when called in a list context to read all
261the remaining lines in a file, except that it's more readable.
262It will also \fIcroak()\fR if accidentally called in a scalar context.
263.IP "$io\->ungetc ( \s-1ORD\s0 )" 4
264.IX Item "$io->ungetc ( ORD )"
265Pushes a character with the given ordinal value back onto the given
266handle's input stream. Only one character of pushback per handle is
267guaranteed.
268.IP "$io\->write ( \s-1BUF\s0, \s-1LEN\s0 [, \s-1OFFSET\s0 ] )" 4
269.IX Item "$io->write ( BUF, LEN [, OFFSET ] )"
270This \f(CW\*(C`write\*(C'\fR is like \f(CW\*(C`write\*(C'\fR found in C, that is it is the
271opposite of read. The wrapper for the perl \f(CW\*(C`write\*(C'\fR function is
272called \f(CW\*(C`format_write\*(C'\fR.
273.IP "$io\->error" 4
274.IX Item "$io->error"
275Returns a true value if the given handle has experienced any errors
276since it was opened or since the last call to \f(CW\*(C`clearerr\*(C'\fR, or if the
277handle is invalid. It only returns false for a valid handle with no
278outstanding errors.
279.IP "$io\->clearerr" 4
280.IX Item "$io->clearerr"
281Clear the given handle's error indicator. Returns \-1 if the handle is
282invalid, 0 otherwise.
283.IP "$io\->sync" 4
284.IX Item "$io->sync"
285\&\f(CW\*(C`sync\*(C'\fR synchronizes a file's in-memory state with that on the
286physical medium. \f(CW\*(C`sync\*(C'\fR does not operate at the perlio api level, but
287operates on the file descriptor (similar to sysread, sysseek and
288systell). This means that any data held at the perlio api level will not
289be synchronized. To synchronize data that is buffered at the perlio api
290level you must use the flush method. \f(CW\*(C`sync\*(C'\fR is not implemented on all
291platforms. Returns \*(L"0 but true\*(R" on success, \f(CW\*(C`undef\*(C'\fR on error, \f(CW\*(C`undef\*(C'\fR
292for an invalid handle. See \fIfsync\fR\|(3c).
293.IP "$io\->flush" 4
294.IX Item "$io->flush"
295\&\f(CW\*(C`flush\*(C'\fR causes perl to flush any buffered data at the perlio api level.
296Any unread data in the buffer will be discarded, and any unwritten data
297will be written to the underlying file descriptor. Returns \*(L"0 but true\*(R"
298on success, \f(CW\*(C`undef\*(C'\fR on error.
299.IP "$io\->printflush ( \s-1ARGS\s0 )" 4
300.IX Item "$io->printflush ( ARGS )"
301Turns on autoflush, print \s-1ARGS\s0 and then restores the autoflush status of the
302\&\f(CW\*(C`IO::Handle\*(C'\fR object. Returns the return value from print.
303.IP "$io\->blocking ( [ \s-1BOOL\s0 ] )" 4
304.IX Item "$io->blocking ( [ BOOL ] )"
305If called with an argument \f(CW\*(C`blocking\*(C'\fR will turn on non-blocking \s-1IO\s0 if
306\&\f(CW\*(C`BOOL\*(C'\fR is false, and turn it off if \f(CW\*(C`BOOL\*(C'\fR is true.
307.Sp
308\&\f(CW\*(C`blocking\*(C'\fR will return the value of the previous setting, or the
309current setting if \f(CW\*(C`BOOL\*(C'\fR is not given.
310.Sp
311If an error occurs \f(CW\*(C`blocking\*(C'\fR will return undef and \f(CW$!\fR will be set.
312.PP
313If the C functions \fIsetbuf()\fR and/or \fIsetvbuf()\fR are available, then
314\&\f(CW\*(C`IO::Handle::setbuf\*(C'\fR and \f(CW\*(C`IO::Handle::setvbuf\*(C'\fR set the buffering
315policy for an IO::Handle. The calling sequences for the Perl functions
316are the same as their C counterparts\*(--including the constants \f(CW\*(C`_IOFBF\*(C'\fR,
317\&\f(CW\*(C`_IOLBF\*(C'\fR, and \f(CW\*(C`_IONBF\*(C'\fR for \fIsetvbuf()\fR\-\-except that the buffer parameter
318specifies a scalar variable to use as a buffer. You should only
319change the buffer before any I/O, or immediately after calling flush.
320.PP
321\&\s-1WARNING:\s0 The \fIIO::Handle::setvbuf()\fR is not available by default on
322Perls 5.8.0 and later because \fIsetvbuf()\fR is rather specific to using
323the stdio library, while Perl prefers the new perlio subsystem instead.
324.PP
325\&\s-1WARNING:\s0 A variable used as a buffer by \f(CW\*(C`setbuf\*(C'\fR or \f(CW\*(C`setvbuf\*(C'\fR \fBmust not
326be modified\fR in any way until the IO::Handle is closed or \f(CW\*(C`setbuf\*(C'\fR or
327\&\f(CW\*(C`setvbuf\*(C'\fR is called again, or memory corruption may result! Remember that
328the order of global destruction is undefined, so even if your buffer
329variable remains in scope until program termination, it may be undefined
330before the file IO::Handle is closed. Note that you need to import the
331constants \f(CW\*(C`_IOFBF\*(C'\fR, \f(CW\*(C`_IOLBF\*(C'\fR, and \f(CW\*(C`_IONBF\*(C'\fR explicitly. Like C, setbuf
332returns nothing. setvbuf returns \*(L"0 but true\*(R", on success, \f(CW\*(C`undef\*(C'\fR on
333failure.
334.PP
335Lastly, there is a special method for working under \fB\-T\fR and setuid/gid
336scripts:
337.IP "$io\->untaint" 4
338.IX Item "$io->untaint"
339Marks the object as taint\-clean, and as such data read from it will also
340be considered taint\-clean. Note that this is a very trusting action to
341take, and appropriate consideration for the data source and potential
342vulnerability should be kept in mind. Returns 0 on success, \-1 if setting
343the taint-clean flag failed. (eg invalid handle)
344.SH "NOTE"
345.IX Header "NOTE"
346An \f(CW\*(C`IO::Handle\*(C'\fR object is a reference to a symbol/GLOB reference (see
347the \f(CW\*(C`Symbol\*(C'\fR package). Some modules that
348inherit from \f(CW\*(C`IO::Handle\*(C'\fR may want to keep object related variables
349in the hash table part of the \s-1GLOB\s0. In an attempt to prevent modules
350trampling on each other I propose the that any such module should prefix
351its variables with its own name separated by _'s. For example the IO::Socket
352module keeps a \f(CW\*(C`timeout\*(C'\fR variable in 'io_socket_timeout'.
353.SH "SEE ALSO"
354.IX Header "SEE ALSO"
355perlfunc,
356\&\*(L"I/O Operators\*(R" in perlop,
357IO::File
358.SH "BUGS"
359.IX Header "BUGS"
360Due to backwards compatibility, all filehandles resemble objects
361of class \f(CW\*(C`IO::Handle\*(C'\fR, or actually classes derived from that class.
362They actually aren't. Which means you can't derive your own
363class from \f(CW\*(C`IO::Handle\*(C'\fR and inherit those methods.
364.SH "HISTORY"
365.IX Header "HISTORY"
366Derived from FileHandle.pm by Graham Barr <\fIgbarr@pobox.com\fR>