Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / man / man3 / IO::Handle.3
.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. | will give a
.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.\"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "IO::Handle 3"
.TH IO::Handle 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide"
.SH "NAME"
IO::Handle \- supply object methods for I/O handles
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use IO::Handle;
.Ve
.PP
.Vb 5
\& $io = new IO::Handle;
\& if ($io->fdopen(fileno(STDIN),"r")) {
\& print $io->getline;
\& $io->close;
\& }
.Ve
.PP
.Vb 4
\& $io = new IO::Handle;
\& if ($io->fdopen(fileno(STDOUT),"w")) {
\& $io->print("Some text\en");
\& }
.Ve
.PP
.Vb 3
\& # setvbuf is not available by default on Perls 5.8.0 and later.
\& use IO::Handle '_IOLBF';
\& $io->setvbuf($buffer_var, _IOLBF, 1024);
.Ve
.PP
.Vb 1
\& undef $io; # automatically closes the file if it's open
.Ve
.PP
.Vb 1
\& autoflush STDOUT 1;
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
\&\f(CW\*(C`IO::Handle\*(C'\fR is the base class for all other \s-1IO\s0 handle classes. It is
not intended that objects of \f(CW\*(C`IO::Handle\*(C'\fR would be created directly,
but instead \f(CW\*(C`IO::Handle\*(C'\fR is inherited from by several other classes
in the \s-1IO\s0 hierarchy.
.PP
If you are reading this documentation, looking for a replacement for
the \f(CW\*(C`FileHandle\*(C'\fR package, then I suggest you read the documentation
for \f(CW\*(C`IO::File\*(C'\fR too.
.SH "CONSTRUCTOR"
.IX Header "CONSTRUCTOR"
.IP "new ()" 4
.IX Item "new ()"
Creates a new \f(CW\*(C`IO::Handle\*(C'\fR object.
.IP "new_from_fd ( \s-1FD\s0, \s-1MODE\s0 )" 4
.IX Item "new_from_fd ( FD, MODE )"
Creates an \f(CW\*(C`IO::Handle\*(C'\fR like \f(CW\*(C`new\*(C'\fR does.
It requires two parameters, which are passed to the method \f(CW\*(C`fdopen\*(C'\fR;
if the fdopen fails, the object is destroyed. Otherwise, it is returned
to the caller.
.SH "METHODS"
.IX Header "METHODS"
See perlfunc for complete descriptions of each of the following
supported \f(CW\*(C`IO::Handle\*(C'\fR methods, which are just front ends for the
corresponding built-in functions:
.PP
.Vb 12
\& $io->close
\& $io->eof
\& $io->fileno
\& $io->format_write( [FORMAT_NAME] )
\& $io->getc
\& $io->read ( BUF, LEN, [OFFSET] )
\& $io->print ( ARGS )
\& $io->printf ( FMT, [ARGS] )
\& $io->stat
\& $io->sysread ( BUF, LEN, [OFFSET] )
\& $io->syswrite ( BUF, [LEN, [OFFSET]] )
\& $io->truncate ( LEN )
.Ve
.PP
See perlvar for complete descriptions of each of the following
supported \f(CW\*(C`IO::Handle\*(C'\fR methods. All of them return the previous
value of the attribute and takes an optional single argument that when
given will set the value. If no argument is given the previous value
is unchanged (except for \f(CW$io\fR\->autoflush will actually turn \s-1ON\s0
autoflush by default).
.PP
.Vb 7
\& $io->autoflush ( [BOOL] ) $|
\& $io->format_page_number( [NUM] ) $%
\& $io->format_lines_per_page( [NUM] ) $=
\& $io->format_lines_left( [NUM] ) $-
\& $io->format_name( [STR] ) $~
\& $io->format_top_name( [STR] ) $^
\& $io->input_line_number( [NUM]) $.
.Ve
.PP
The following methods are not supported on a per-filehandle basis.
.PP
.Vb 4
\& IO::Handle->format_line_break_characters( [STR] ) $:
\& IO::Handle->format_formfeed( [STR]) $^L
\& IO::Handle->output_field_separator( [STR] ) $,
\& IO::Handle->output_record_separator( [STR] ) $\e
.Ve
.PP
.Vb 1
\& IO::Handle->input_record_separator( [STR] ) $/
.Ve
.PP
Furthermore, for doing normal I/O you might need these:
.IP "$io\->fdopen ( \s-1FD\s0, \s-1MODE\s0 )" 4
.IX Item "$io->fdopen ( FD, MODE )"
\&\f(CW\*(C`fdopen\*(C'\fR is like an ordinary \f(CW\*(C`open\*(C'\fR except that its first parameter
is not a filename but rather a file handle name, an IO::Handle object,
or a file descriptor number.
.IP "$io\->opened" 4
.IX Item "$io->opened"
Returns true if the object is currently a valid file descriptor, false
otherwise.
.IP "$io\->getline" 4
.IX Item "$io->getline"
This works like <$io> described in \*(L"I/O Operators\*(R" in perlop
except that it's more readable and can be safely called in a
list context but still returns just one line. If used as the conditional
+within a \f(CW\*(C`while\*(C'\fR or C\-style \f(CW\*(C`for\*(C'\fR loop, however, you will need to
+emulate the functionality of <$io> with \f(CW\*(C`defined($_ = $io\->getline)\*(C'\fR.
.IP "$io\->getlines" 4
.IX Item "$io->getlines"
This works like <$io> when called in a list context to read all
the remaining lines in a file, except that it's more readable.
It will also \fIcroak()\fR if accidentally called in a scalar context.
.IP "$io\->ungetc ( \s-1ORD\s0 )" 4
.IX Item "$io->ungetc ( ORD )"
Pushes a character with the given ordinal value back onto the given
handle's input stream. Only one character of pushback per handle is
guaranteed.
.IP "$io\->write ( \s-1BUF\s0, \s-1LEN\s0 [, \s-1OFFSET\s0 ] )" 4
.IX Item "$io->write ( BUF, LEN [, OFFSET ] )"
This \f(CW\*(C`write\*(C'\fR is like \f(CW\*(C`write\*(C'\fR found in C, that is it is the
opposite of read. The wrapper for the perl \f(CW\*(C`write\*(C'\fR function is
called \f(CW\*(C`format_write\*(C'\fR.
.IP "$io\->error" 4
.IX Item "$io->error"
Returns a true value if the given handle has experienced any errors
since it was opened or since the last call to \f(CW\*(C`clearerr\*(C'\fR, or if the
handle is invalid. It only returns false for a valid handle with no
outstanding errors.
.IP "$io\->clearerr" 4
.IX Item "$io->clearerr"
Clear the given handle's error indicator. Returns \-1 if the handle is
invalid, 0 otherwise.
.IP "$io\->sync" 4
.IX Item "$io->sync"
\&\f(CW\*(C`sync\*(C'\fR synchronizes a file's in-memory state with that on the
physical medium. \f(CW\*(C`sync\*(C'\fR does not operate at the perlio api level, but
operates on the file descriptor (similar to sysread, sysseek and
systell). This means that any data held at the perlio api level will not
be synchronized. To synchronize data that is buffered at the perlio api
level you must use the flush method. \f(CW\*(C`sync\*(C'\fR is not implemented on all
platforms. Returns \*(L"0 but true\*(R" on success, \f(CW\*(C`undef\*(C'\fR on error, \f(CW\*(C`undef\*(C'\fR
for an invalid handle. See \fIfsync\fR\|(3c).
.IP "$io\->flush" 4
.IX Item "$io->flush"
\&\f(CW\*(C`flush\*(C'\fR causes perl to flush any buffered data at the perlio api level.
Any unread data in the buffer will be discarded, and any unwritten data
will be written to the underlying file descriptor. Returns \*(L"0 but true\*(R"
on success, \f(CW\*(C`undef\*(C'\fR on error.
.IP "$io\->printflush ( \s-1ARGS\s0 )" 4
.IX Item "$io->printflush ( ARGS )"
Turns on autoflush, print \s-1ARGS\s0 and then restores the autoflush status of the
\&\f(CW\*(C`IO::Handle\*(C'\fR object. Returns the return value from print.
.IP "$io\->blocking ( [ \s-1BOOL\s0 ] )" 4
.IX Item "$io->blocking ( [ BOOL ] )"
If called with an argument \f(CW\*(C`blocking\*(C'\fR will turn on non-blocking \s-1IO\s0 if
\&\f(CW\*(C`BOOL\*(C'\fR is false, and turn it off if \f(CW\*(C`BOOL\*(C'\fR is true.
.Sp
\&\f(CW\*(C`blocking\*(C'\fR will return the value of the previous setting, or the
current setting if \f(CW\*(C`BOOL\*(C'\fR is not given.
.Sp
If an error occurs \f(CW\*(C`blocking\*(C'\fR will return undef and \f(CW$!\fR will be set.
.PP
If the C functions \fIsetbuf()\fR and/or \fIsetvbuf()\fR are available, then
\&\f(CW\*(C`IO::Handle::setbuf\*(C'\fR and \f(CW\*(C`IO::Handle::setvbuf\*(C'\fR set the buffering
policy for an IO::Handle. The calling sequences for the Perl functions
are the same as their C counterparts\*(--including the constants \f(CW\*(C`_IOFBF\*(C'\fR,
\&\f(CW\*(C`_IOLBF\*(C'\fR, and \f(CW\*(C`_IONBF\*(C'\fR for \fIsetvbuf()\fR\-\-except that the buffer parameter
specifies a scalar variable to use as a buffer. You should only
change the buffer before any I/O, or immediately after calling flush.
.PP
\&\s-1WARNING:\s0 The \fIIO::Handle::setvbuf()\fR is not available by default on
Perls 5.8.0 and later because \fIsetvbuf()\fR is rather specific to using
the stdio library, while Perl prefers the new perlio subsystem instead.
.PP
\&\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
be modified\fR in any way until the IO::Handle is closed or \f(CW\*(C`setbuf\*(C'\fR or
\&\f(CW\*(C`setvbuf\*(C'\fR is called again, or memory corruption may result! Remember that
the order of global destruction is undefined, so even if your buffer
variable remains in scope until program termination, it may be undefined
before the file IO::Handle is closed. Note that you need to import the
constants \f(CW\*(C`_IOFBF\*(C'\fR, \f(CW\*(C`_IOLBF\*(C'\fR, and \f(CW\*(C`_IONBF\*(C'\fR explicitly. Like C, setbuf
returns nothing. setvbuf returns \*(L"0 but true\*(R", on success, \f(CW\*(C`undef\*(C'\fR on
failure.
.PP
Lastly, there is a special method for working under \fB\-T\fR and setuid/gid
scripts:
.IP "$io\->untaint" 4
.IX Item "$io->untaint"
Marks the object as taint\-clean, and as such data read from it will also
be considered taint\-clean. Note that this is a very trusting action to
take, and appropriate consideration for the data source and potential
vulnerability should be kept in mind. Returns 0 on success, \-1 if setting
the taint-clean flag failed. (eg invalid handle)
.SH "NOTE"
.IX Header "NOTE"
An \f(CW\*(C`IO::Handle\*(C'\fR object is a reference to a symbol/GLOB reference (see
the \f(CW\*(C`Symbol\*(C'\fR package). Some modules that
inherit from \f(CW\*(C`IO::Handle\*(C'\fR may want to keep object related variables
in the hash table part of the \s-1GLOB\s0. In an attempt to prevent modules
trampling on each other I propose the that any such module should prefix
its variables with its own name separated by _'s. For example the IO::Socket
module keeps a \f(CW\*(C`timeout\*(C'\fR variable in 'io_socket_timeout'.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
perlfunc,
\&\*(L"I/O Operators\*(R" in perlop,
IO::File
.SH "BUGS"
.IX Header "BUGS"
Due to backwards compatibility, all filehandles resemble objects
of class \f(CW\*(C`IO::Handle\*(C'\fR, or actually classes derived from that class.
They actually aren't. Which means you can't derive your own
class from \f(CW\*(C`IO::Handle\*(C'\fR and inherit those methods.
.SH "HISTORY"
.IX Header "HISTORY"
Derived from FileHandle.pm by Graham Barr <\fIgbarr@pobox.com\fR>