Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / html / python / lib / os-fd-ops.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="os-file-dir.html" />
<link rel="prev" href="os-newstreams.html" />
<link rel="parent" href="module-os.html" />
<link rel="next" href="os-file-dir.html" />
<meta name='aesop' content='information' />
<title>6.1.3 File Descriptor Operations </title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="6.1.2 File Object Creation"
href="os-newstreams.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="6.1 os "
href="module-os.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="6.1.4 Files and Directories"
href="os-file-dir.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="os-newstreams.html">6.1.2 File Object Creation</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-os.html">6.1 os </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="os-file-dir.html">6.1.4 Files and Directories</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION008130000000000000000"></A><A NAME="os-fd-ops"></A>
<BR>
6.1.3 File Descriptor Operations
</H2>
<P>
These functions operate on I/O streams referred to
using file descriptors.
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1558' xml:id='l2h-1558' class="function">close</tt></b>(</nobr></td>
<td><var>fd</var>)</td></tr></table></dt>
<dd>
Close file descriptor <var>fd</var>.
Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
<P>
<div class="note"><b class="label">Note:</b>
This function is intended for low-level I/O and must be applied
to a file descriptor as returned by <tt class="function">open()</tt> or
<tt class="function">pipe()</tt>. To close a ``file object'' returned by the
built-in function <tt class="function">open()</tt> or by <tt class="function">popen()</tt> or
<tt class="function">fdopen()</tt>, use its <tt class="method">close()</tt> method.
</div>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1559' xml:id='l2h-1559' class="function">dup</tt></b>(</nobr></td>
<td><var>fd</var>)</td></tr></table></dt>
<dd>
Return a duplicate of file descriptor <var>fd</var>.
Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1560' xml:id='l2h-1560' class="function">dup2</tt></b>(</nobr></td>
<td><var>fd, fd2</var>)</td></tr></table></dt>
<dd>
Duplicate file descriptor <var>fd</var> to <var>fd2</var>, closing the latter
first if necessary.
Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1561' xml:id='l2h-1561' class="function">fdatasync</tt></b>(</nobr></td>
<td><var>fd</var>)</td></tr></table></dt>
<dd>
Force write of file with filedescriptor <var>fd</var> to disk.
Does not force update of metadata.
Availability: <span class="Unix">Unix</span>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1562' xml:id='l2h-1562' class="function">fpathconf</tt></b>(</nobr></td>
<td><var>fd, name</var>)</td></tr></table></dt>
<dd>
Return system configuration information relevant to an open file.
<var>name</var> specifies the configuration value to retrieve; it may be a
string which is the name of a defined system value; these names are
specified in a number of standards (POSIX.1, <span class="Unix">Unix</span> 95, <span class="Unix">Unix</span> 98, and
others). Some platforms define additional names as well. The names
known to the host operating system are given in the
<code>pathconf_names</code> dictionary. For configuration variables not
included in that mapping, passing an integer for <var>name</var> is also
accepted.
Availability: Macintosh, <span class="Unix">Unix</span>.
<P>
If <var>name</var> is a string and is not known, <tt class="exception">ValueError</tt> is
raised. If a specific value for <var>name</var> is not supported by the
host system, even if it is included in <code>pathconf_names</code>, an
<tt class="exception">OSError</tt> is raised with <tt class="constant">errno.EINVAL</tt> for the
error number.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1563' xml:id='l2h-1563' class="function">fstat</tt></b>(</nobr></td>
<td><var>fd</var>)</td></tr></table></dt>
<dd>
Return status for file descriptor <var>fd</var>, like <tt class="function">stat()</tt>.
Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1564' xml:id='l2h-1564' class="function">fstatvfs</tt></b>(</nobr></td>
<td><var>fd</var>)</td></tr></table></dt>
<dd>
Return information about the filesystem containing the file associated
with file descriptor <var>fd</var>, like <tt class="function">statvfs()</tt>.
Availability: <span class="Unix">Unix</span>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1565' xml:id='l2h-1565' class="function">fsync</tt></b>(</nobr></td>
<td><var>fd</var>)</td></tr></table></dt>
<dd>
Force write of file with filedescriptor <var>fd</var> to disk. On <span class="Unix">Unix</span>,
this calls the native <tt class="cfunction">fsync()</tt> function; on Windows, the
MS <tt class="cfunction">_commit()</tt> function.
<P>
If you're starting with a Python file object <var>f</var>, first do
<code><var>f</var>.flush()</code>, and then do <code>os.fsync(<var>f</var>.fileno())</code>,
to ensure that all internal buffers associated with <var>f</var> are written
to disk.
Availability: Macintosh, <span class="Unix">Unix</span>, and Windows starting in 2.2.3.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1566' xml:id='l2h-1566' class="function">ftruncate</tt></b>(</nobr></td>
<td><var>fd, length</var>)</td></tr></table></dt>
<dd>
Truncate the file corresponding to file descriptor <var>fd</var>,
so that it is at most <var>length</var> bytes in size.
Availability: Macintosh, <span class="Unix">Unix</span>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1567' xml:id='l2h-1567' class="function">isatty</tt></b>(</nobr></td>
<td><var>fd</var>)</td></tr></table></dt>
<dd>
Return <code>True</code> if the file descriptor <var>fd</var> is open and
connected to a tty(-like) device, else <code>False</code>.
Availability: Macintosh, <span class="Unix">Unix</span>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1568' xml:id='l2h-1568' class="function">lseek</tt></b>(</nobr></td>
<td><var>fd, pos, how</var>)</td></tr></table></dt>
<dd>
Set the current position of file descriptor <var>fd</var> to position
<var>pos</var>, modified by <var>how</var>: <code>0</code> to set the position
relative to the beginning of the file; <code>1</code> to set it relative to
the current position; <code>2</code> to set it relative to the end of the
file.
Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1569' xml:id='l2h-1569' class="function">open</tt></b>(</nobr></td>
<td><var>file, flags</var><big>[</big><var>, mode</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Open the file <var>file</var> and set various flags according to
<var>flags</var> and possibly its mode according to <var>mode</var>.
The default <var>mode</var> is <code>0777</code> (octal), and the current umask
value is first masked out. Return the file descriptor for the newly
opened file.
Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
<P>
For a description of the flag and mode values, see the C run-time
documentation; flag constants (like <tt class="constant">O_RDONLY</tt> and
<tt class="constant">O_WRONLY</tt>) are defined in this module too (see below).
<P>
<div class="note"><b class="label">Note:</b>
This function is intended for low-level I/O. For normal usage,
use the built-in function <tt class="function">open()</tt>, which returns a ``file
object'' with <tt class="method">read()</tt> and <tt class="method">write()</tt> methods (and many
more).
</div>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1570' xml:id='l2h-1570' class="function">openpty</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Open a new pseudo-terminal pair. Return a pair of file descriptors
<code>(<var>master</var>, <var>slave</var>)</code> for the pty and the tty,
respectively. For a (slightly) more portable approach, use the
<tt class="module"><a href="module-pty.html">pty</a></tt><a id='l2h-1581' xml:id='l2h-1581'></a> module.
Availability: Macintosh, Some flavors of <span class="Unix">Unix</span>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1571' xml:id='l2h-1571' class="function">pipe</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Create a pipe. Return a pair of file descriptors <code>(<var>r</var>,
<var>w</var>)</code> usable for reading and writing, respectively.
Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1572' xml:id='l2h-1572' class="function">read</tt></b>(</nobr></td>
<td><var>fd, n</var>)</td></tr></table></dt>
<dd>
Read at most <var>n</var> bytes from file descriptor <var>fd</var>.
Return a string containing the bytes read. If the end of the file
referred to by <var>fd</var> has been reached, an empty string is
returned.
Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
<P>
<div class="note"><b class="label">Note:</b>
This function is intended for low-level I/O and must be applied
to a file descriptor as returned by <tt class="function">open()</tt> or
<tt class="function">pipe()</tt>. To read a ``file object'' returned by the
built-in function <tt class="function">open()</tt> or by <tt class="function">popen()</tt> or
<tt class="function">fdopen()</tt>, or <code>sys.stdin</code>, use its
<tt class="method">read()</tt> or <tt class="method">readline()</tt> methods.
</div>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1573' xml:id='l2h-1573' class="function">tcgetpgrp</tt></b>(</nobr></td>
<td><var>fd</var>)</td></tr></table></dt>
<dd>
Return the process group associated with the terminal given by
<var>fd</var> (an open file descriptor as returned by <tt class="function">open()</tt>).
Availability: Macintosh, <span class="Unix">Unix</span>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1574' xml:id='l2h-1574' class="function">tcsetpgrp</tt></b>(</nobr></td>
<td><var>fd, pg</var>)</td></tr></table></dt>
<dd>
Set the process group associated with the terminal given by
<var>fd</var> (an open file descriptor as returned by <tt class="function">open()</tt>)
to <var>pg</var>.
Availability: Macintosh, <span class="Unix">Unix</span>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1575' xml:id='l2h-1575' class="function">ttyname</tt></b>(</nobr></td>
<td><var>fd</var>)</td></tr></table></dt>
<dd>
Return a string which specifies the terminal device associated with
file-descriptor <var>fd</var>. If <var>fd</var> is not associated with a terminal
device, an exception is raised.
Availability:Macintosh, <span class="Unix">Unix</span>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1576' xml:id='l2h-1576' class="function">write</tt></b>(</nobr></td>
<td><var>fd, str</var>)</td></tr></table></dt>
<dd>
Write the string <var>str</var> to file descriptor <var>fd</var>.
Return the number of bytes actually written.
Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
<P>
<div class="note"><b class="label">Note:</b>
This function is intended for low-level I/O and must be applied
to a file descriptor as returned by <tt class="function">open()</tt> or
<tt class="function">pipe()</tt>. To write a ``file object'' returned by the
built-in function <tt class="function">open()</tt> or by <tt class="function">popen()</tt> or
<tt class="function">fdopen()</tt>, or <code>sys.stdout</code> or <code>sys.stderr</code>, use
its <tt class="method">write()</tt> method.
</div>
</dl>
<P>
The following data items are available for use in constructing the
<var>flags</var> parameter to the <tt class="function">open()</tt> function.
<P>
<dl><dt><b><tt id='l2h-1577' xml:id='l2h-1577'>O_RDONLY</tt></b></dt>
<dd>
<dt><b><tt id='l2h-1582' xml:id='l2h-1582'>O_WRONLY</tt></b></dt><dd>
<dt><b><tt id='l2h-1583' xml:id='l2h-1583'>O_RDWR</tt></b></dt><dd>
<dt><b><tt id='l2h-1584' xml:id='l2h-1584'>O_APPEND</tt></b></dt><dd>
<dt><b><tt id='l2h-1585' xml:id='l2h-1585'>O_CREAT</tt></b></dt><dd>
<dt><b><tt id='l2h-1586' xml:id='l2h-1586'>O_EXCL</tt></b></dt><dd>
<dt><b><tt id='l2h-1587' xml:id='l2h-1587'>O_TRUNC</tt></b></dt><dd>
Options for the <var>flag</var> argument to the <tt class="function">open()</tt> function.
These can be bit-wise OR'd together.
Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
</dd></dl>
<P>
<dl><dt><b><tt id='l2h-1578' xml:id='l2h-1578'>O_DSYNC</tt></b></dt>
<dd>
<dt><b><tt id='l2h-1588' xml:id='l2h-1588'>O_RSYNC</tt></b></dt><dd>
<dt><b><tt id='l2h-1589' xml:id='l2h-1589'>O_SYNC</tt></b></dt><dd>
<dt><b><tt id='l2h-1590' xml:id='l2h-1590'>O_NDELAY</tt></b></dt><dd>
<dt><b><tt id='l2h-1591' xml:id='l2h-1591'>O_NONBLOCK</tt></b></dt><dd>
<dt><b><tt id='l2h-1592' xml:id='l2h-1592'>O_NOCTTY</tt></b></dt><dd>
More options for the <var>flag</var> argument to the <tt class="function">open()</tt> function.
Availability: Macintosh, <span class="Unix">Unix</span>.
</dd></dl>
<P>
<dl><dt><b><tt id='l2h-1579' xml:id='l2h-1579'>O_BINARY</tt></b></dt>
<dd>
Option for the <var>flag</var> argument to the <tt class="function">open()</tt> function.
This can be bit-wise OR'd together with those listed above.
Availability: Windows.
</dd></dl>
<P>
<dl><dt><b><tt id='l2h-1580' xml:id='l2h-1580'>O_NOINHERIT</tt></b></dt>
<dd>
<dt><b><tt id='l2h-1593' xml:id='l2h-1593'>O_SHORT_LIVED</tt></b></dt><dd>
<dt><b><tt id='l2h-1594' xml:id='l2h-1594'>O_TEMPORARY</tt></b></dt><dd>
<dt><b><tt id='l2h-1595' xml:id='l2h-1595'>O_RANDOM</tt></b></dt><dd>
<dt><b><tt id='l2h-1596' xml:id='l2h-1596'>O_SEQUENTIAL</tt></b></dt><dd>
<dt><b><tt id='l2h-1597' xml:id='l2h-1597'>O_TEXT</tt></b></dt><dd>
Options for the <var>flag</var> argument to the <tt class="function">open()</tt> function.
These can be bit-wise OR'd together.
Availability: Windows.
</dd></dl>
<P>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="6.1.2 File Object Creation"
href="os-newstreams.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="6.1 os "
href="module-os.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="6.1.4 Files and Directories"
href="os-file-dir.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="os-newstreams.html">6.1.2 File Object Creation</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-os.html">6.1 os </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="os-file-dir.html">6.1.4 Files and Directories</A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>