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