Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / html / python / lib / os-fd-ops.html
CommitLineData
86530b38
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="lib.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="lib.html" title='Python Library Reference' />
8<link rel='contents' href='contents.html' title="Contents" />
9<link rel='index' href='genindex.html' title='Index' />
10<link rel='last' href='about.html' title='About this document...' />
11<link rel='help' href='about.html' title='About this document...' />
12<link rel="next" href="os-file-dir.html" />
13<link rel="prev" href="os-newstreams.html" />
14<link rel="parent" href="module-os.html" />
15<link rel="next" href="os-file-dir.html" />
16<meta name='aesop' content='information' />
17<title>6.1.3 File Descriptor Operations </title>
18</head>
19<body>
20<DIV CLASS="navigation">
21<div id='top-navigation-panel' xml:id='top-navigation-panel'>
22<table align="center" width="100%" cellpadding="0" cellspacing="2">
23<tr>
24<td class='online-navigation'><a rel="prev" title="6.1.2 File Object Creation"
25 href="os-newstreams.html"><img src='../icons/previous.png'
26 border='0' height='32' alt='Previous Page' width='32' /></A></td>
27<td class='online-navigation'><a rel="parent" title="6.1 os "
28 href="module-os.html"><img src='../icons/up.png'
29 border='0' height='32' alt='Up One Level' width='32' /></A></td>
30<td class='online-navigation'><a rel="next" title="6.1.4 Files and Directories"
31 href="os-file-dir.html"><img src='../icons/next.png'
32 border='0' height='32' alt='Next Page' width='32' /></A></td>
33<td align="center" width="100%">Python Library Reference</td>
34<td class='online-navigation'><a rel="contents" title="Table of Contents"
35 href="contents.html"><img src='../icons/contents.png'
36 border='0' height='32' alt='Contents' width='32' /></A></td>
37<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
38 border='0' height='32' alt='Module Index' width='32' /></a></td>
39<td class='online-navigation'><a rel="index" title="Index"
40 href="genindex.html"><img src='../icons/index.png'
41 border='0' height='32' alt='Index' width='32' /></A></td>
42</tr></table>
43<div class='online-navigation'>
44<b class="navlabel">Previous:</b>
45<a class="sectref" rel="prev" href="os-newstreams.html">6.1.2 File Object Creation</A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="module-os.html">6.1 os </A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="os-file-dir.html">6.1.4 Files and Directories</A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H2><A NAME="SECTION008130000000000000000"></A><A NAME="os-fd-ops"></A>
56<BR>
576.1.3 File Descriptor Operations
58</H2>
59
60<P>
61These functions operate on I/O streams referred to
62using file descriptors.
63
64<P>
65<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
66 <td><nobr><b><tt id='l2h-1558' xml:id='l2h-1558' class="function">close</tt></b>(</nobr></td>
67 <td><var>fd</var>)</td></tr></table></dt>
68<dd>
69Close file descriptor <var>fd</var>.
70Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
71
72<P>
73<div class="note"><b class="label">Note:</b>
74This function is intended for low-level I/O and must be applied
75to a file descriptor as returned by <tt class="function">open()</tt> or
76<tt class="function">pipe()</tt>. To close a ``file object'' returned by the
77built-in function <tt class="function">open()</tt> or by <tt class="function">popen()</tt> or
78<tt class="function">fdopen()</tt>, use its <tt class="method">close()</tt> method.
79</div>
80</dl>
81
82<P>
83<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
84 <td><nobr><b><tt id='l2h-1559' xml:id='l2h-1559' class="function">dup</tt></b>(</nobr></td>
85 <td><var>fd</var>)</td></tr></table></dt>
86<dd>
87Return a duplicate of file descriptor <var>fd</var>.
88Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
89</dl>
90
91<P>
92<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
93 <td><nobr><b><tt id='l2h-1560' xml:id='l2h-1560' class="function">dup2</tt></b>(</nobr></td>
94 <td><var>fd, fd2</var>)</td></tr></table></dt>
95<dd>
96Duplicate file descriptor <var>fd</var> to <var>fd2</var>, closing the latter
97first if necessary.
98Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
99</dl>
100
101<P>
102<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
103 <td><nobr><b><tt id='l2h-1561' xml:id='l2h-1561' class="function">fdatasync</tt></b>(</nobr></td>
104 <td><var>fd</var>)</td></tr></table></dt>
105<dd>
106Force write of file with filedescriptor <var>fd</var> to disk.
107Does not force update of metadata.
108Availability: <span class="Unix">Unix</span>.
109</dl>
110
111<P>
112<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
113 <td><nobr><b><tt id='l2h-1562' xml:id='l2h-1562' class="function">fpathconf</tt></b>(</nobr></td>
114 <td><var>fd, name</var>)</td></tr></table></dt>
115<dd>
116Return system configuration information relevant to an open file.
117<var>name</var> specifies the configuration value to retrieve; it may be a
118string which is the name of a defined system value; these names are
119specified in a number of standards (POSIX.1, <span class="Unix">Unix</span> 95, <span class="Unix">Unix</span> 98, and
120others). Some platforms define additional names as well. The names
121known to the host operating system are given in the
122<code>pathconf_names</code> dictionary. For configuration variables not
123included in that mapping, passing an integer for <var>name</var> is also
124accepted.
125Availability: Macintosh, <span class="Unix">Unix</span>.
126
127<P>
128If <var>name</var> is a string and is not known, <tt class="exception">ValueError</tt> is
129raised. If a specific value for <var>name</var> is not supported by the
130host system, even if it is included in <code>pathconf_names</code>, an
131<tt class="exception">OSError</tt> is raised with <tt class="constant">errno.EINVAL</tt> for the
132error number.
133</dl>
134
135<P>
136<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
137 <td><nobr><b><tt id='l2h-1563' xml:id='l2h-1563' class="function">fstat</tt></b>(</nobr></td>
138 <td><var>fd</var>)</td></tr></table></dt>
139<dd>
140Return status for file descriptor <var>fd</var>, like <tt class="function">stat()</tt>.
141Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
142</dl>
143
144<P>
145<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
146 <td><nobr><b><tt id='l2h-1564' xml:id='l2h-1564' class="function">fstatvfs</tt></b>(</nobr></td>
147 <td><var>fd</var>)</td></tr></table></dt>
148<dd>
149Return information about the filesystem containing the file associated
150with file descriptor <var>fd</var>, like <tt class="function">statvfs()</tt>.
151Availability: <span class="Unix">Unix</span>.
152</dl>
153
154<P>
155<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
156 <td><nobr><b><tt id='l2h-1565' xml:id='l2h-1565' class="function">fsync</tt></b>(</nobr></td>
157 <td><var>fd</var>)</td></tr></table></dt>
158<dd>
159Force write of file with filedescriptor <var>fd</var> to disk. On <span class="Unix">Unix</span>,
160this calls the native <tt class="cfunction">fsync()</tt> function; on Windows, the
161MS <tt class="cfunction">_commit()</tt> function.
162
163<P>
164If you're starting with a Python file object <var>f</var>, first do
165<code><var>f</var>.flush()</code>, and then do <code>os.fsync(<var>f</var>.fileno())</code>,
166to ensure that all internal buffers associated with <var>f</var> are written
167to disk.
168Availability: Macintosh, <span class="Unix">Unix</span>, and Windows starting in 2.2.3.
169</dl>
170
171<P>
172<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
173 <td><nobr><b><tt id='l2h-1566' xml:id='l2h-1566' class="function">ftruncate</tt></b>(</nobr></td>
174 <td><var>fd, length</var>)</td></tr></table></dt>
175<dd>
176Truncate the file corresponding to file descriptor <var>fd</var>,
177so that it is at most <var>length</var> bytes in size.
178Availability: Macintosh, <span class="Unix">Unix</span>.
179</dl>
180
181<P>
182<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
183 <td><nobr><b><tt id='l2h-1567' xml:id='l2h-1567' class="function">isatty</tt></b>(</nobr></td>
184 <td><var>fd</var>)</td></tr></table></dt>
185<dd>
186Return <code>True</code> if the file descriptor <var>fd</var> is open and
187connected to a tty(-like) device, else <code>False</code>.
188Availability: Macintosh, <span class="Unix">Unix</span>.
189</dl>
190
191<P>
192<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
193 <td><nobr><b><tt id='l2h-1568' xml:id='l2h-1568' class="function">lseek</tt></b>(</nobr></td>
194 <td><var>fd, pos, how</var>)</td></tr></table></dt>
195<dd>
196Set the current position of file descriptor <var>fd</var> to position
197<var>pos</var>, modified by <var>how</var>: <code>0</code> to set the position
198relative to the beginning of the file; <code>1</code> to set it relative to
199the current position; <code>2</code> to set it relative to the end of the
200file.
201Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
202</dl>
203
204<P>
205<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
206 <td><nobr><b><tt id='l2h-1569' xml:id='l2h-1569' class="function">open</tt></b>(</nobr></td>
207 <td><var>file, flags</var><big>[</big><var>, mode</var><big>]</big><var></var>)</td></tr></table></dt>
208<dd>
209Open the file <var>file</var> and set various flags according to
210<var>flags</var> and possibly its mode according to <var>mode</var>.
211The default <var>mode</var> is <code>0777</code> (octal), and the current umask
212value is first masked out. Return the file descriptor for the newly
213opened file.
214Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
215
216<P>
217For a description of the flag and mode values, see the C run-time
218documentation; flag constants (like <tt class="constant">O_RDONLY</tt> and
219<tt class="constant">O_WRONLY</tt>) are defined in this module too (see below).
220
221<P>
222<div class="note"><b class="label">Note:</b>
223This function is intended for low-level I/O. For normal usage,
224use the built-in function <tt class="function">open()</tt>, which returns a ``file
225object'' with <tt class="method">read()</tt> and <tt class="method">write()</tt> methods (and many
226more).
227</div>
228</dl>
229
230<P>
231<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
232 <td><nobr><b><tt id='l2h-1570' xml:id='l2h-1570' class="function">openpty</tt></b>(</nobr></td>
233 <td><var></var>)</td></tr></table></dt>
234<dd>
235Open a new pseudo-terminal pair. Return a pair of file descriptors
236<code>(<var>master</var>, <var>slave</var>)</code> for the pty and the tty,
237respectively. For a (slightly) more portable approach, use the
238<tt class="module"><a href="module-pty.html">pty</a></tt><a id='l2h-1581' xml:id='l2h-1581'></a> module.
239Availability: Macintosh, Some flavors of <span class="Unix">Unix</span>.
240</dl>
241
242<P>
243<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
244 <td><nobr><b><tt id='l2h-1571' xml:id='l2h-1571' class="function">pipe</tt></b>(</nobr></td>
245 <td><var></var>)</td></tr></table></dt>
246<dd>
247Create a pipe. Return a pair of file descriptors <code>(<var>r</var>,
248<var>w</var>)</code> usable for reading and writing, respectively.
249Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
250</dl>
251
252<P>
253<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
254 <td><nobr><b><tt id='l2h-1572' xml:id='l2h-1572' class="function">read</tt></b>(</nobr></td>
255 <td><var>fd, n</var>)</td></tr></table></dt>
256<dd>
257Read at most <var>n</var> bytes from file descriptor <var>fd</var>.
258Return a string containing the bytes read. If the end of the file
259referred to by <var>fd</var> has been reached, an empty string is
260returned.
261Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
262
263<P>
264<div class="note"><b class="label">Note:</b>
265This function is intended for low-level I/O and must be applied
266to a file descriptor as returned by <tt class="function">open()</tt> or
267<tt class="function">pipe()</tt>. To read a ``file object'' returned by the
268built-in function <tt class="function">open()</tt> or by <tt class="function">popen()</tt> or
269<tt class="function">fdopen()</tt>, or <code>sys.stdin</code>, use its
270<tt class="method">read()</tt> or <tt class="method">readline()</tt> methods.
271</div>
272</dl>
273
274<P>
275<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
276 <td><nobr><b><tt id='l2h-1573' xml:id='l2h-1573' class="function">tcgetpgrp</tt></b>(</nobr></td>
277 <td><var>fd</var>)</td></tr></table></dt>
278<dd>
279Return the process group associated with the terminal given by
280<var>fd</var> (an open file descriptor as returned by <tt class="function">open()</tt>).
281Availability: Macintosh, <span class="Unix">Unix</span>.
282</dl>
283
284<P>
285<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
286 <td><nobr><b><tt id='l2h-1574' xml:id='l2h-1574' class="function">tcsetpgrp</tt></b>(</nobr></td>
287 <td><var>fd, pg</var>)</td></tr></table></dt>
288<dd>
289Set the process group associated with the terminal given by
290<var>fd</var> (an open file descriptor as returned by <tt class="function">open()</tt>)
291to <var>pg</var>.
292Availability: Macintosh, <span class="Unix">Unix</span>.
293</dl>
294
295<P>
296<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
297 <td><nobr><b><tt id='l2h-1575' xml:id='l2h-1575' class="function">ttyname</tt></b>(</nobr></td>
298 <td><var>fd</var>)</td></tr></table></dt>
299<dd>
300Return a string which specifies the terminal device associated with
301file-descriptor <var>fd</var>. If <var>fd</var> is not associated with a terminal
302device, an exception is raised.
303Availability:Macintosh, <span class="Unix">Unix</span>.
304</dl>
305
306<P>
307<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
308 <td><nobr><b><tt id='l2h-1576' xml:id='l2h-1576' class="function">write</tt></b>(</nobr></td>
309 <td><var>fd, str</var>)</td></tr></table></dt>
310<dd>
311Write the string <var>str</var> to file descriptor <var>fd</var>.
312Return the number of bytes actually written.
313Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
314
315<P>
316<div class="note"><b class="label">Note:</b>
317This function is intended for low-level I/O and must be applied
318to a file descriptor as returned by <tt class="function">open()</tt> or
319<tt class="function">pipe()</tt>. To write a ``file object'' returned by the
320built-in function <tt class="function">open()</tt> or by <tt class="function">popen()</tt> or
321<tt class="function">fdopen()</tt>, or <code>sys.stdout</code> or <code>sys.stderr</code>, use
322its <tt class="method">write()</tt> method.
323</div>
324</dl>
325
326<P>
327The following data items are available for use in constructing the
328<var>flags</var> parameter to the <tt class="function">open()</tt> function.
329
330<P>
331<dl><dt><b><tt id='l2h-1577' xml:id='l2h-1577'>O_RDONLY</tt></b></dt>
332<dd>
333<dt><b><tt id='l2h-1582' xml:id='l2h-1582'>O_WRONLY</tt></b></dt><dd>
334<dt><b><tt id='l2h-1583' xml:id='l2h-1583'>O_RDWR</tt></b></dt><dd>
335<dt><b><tt id='l2h-1584' xml:id='l2h-1584'>O_APPEND</tt></b></dt><dd>
336<dt><b><tt id='l2h-1585' xml:id='l2h-1585'>O_CREAT</tt></b></dt><dd>
337<dt><b><tt id='l2h-1586' xml:id='l2h-1586'>O_EXCL</tt></b></dt><dd>
338<dt><b><tt id='l2h-1587' xml:id='l2h-1587'>O_TRUNC</tt></b></dt><dd>
339Options for the <var>flag</var> argument to the <tt class="function">open()</tt> function.
340These can be bit-wise OR'd together.
341Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
342</dd></dl>
343
344<P>
345<dl><dt><b><tt id='l2h-1578' xml:id='l2h-1578'>O_DSYNC</tt></b></dt>
346<dd>
347<dt><b><tt id='l2h-1588' xml:id='l2h-1588'>O_RSYNC</tt></b></dt><dd>
348<dt><b><tt id='l2h-1589' xml:id='l2h-1589'>O_SYNC</tt></b></dt><dd>
349<dt><b><tt id='l2h-1590' xml:id='l2h-1590'>O_NDELAY</tt></b></dt><dd>
350<dt><b><tt id='l2h-1591' xml:id='l2h-1591'>O_NONBLOCK</tt></b></dt><dd>
351<dt><b><tt id='l2h-1592' xml:id='l2h-1592'>O_NOCTTY</tt></b></dt><dd>
352More options for the <var>flag</var> argument to the <tt class="function">open()</tt> function.
353Availability: Macintosh, <span class="Unix">Unix</span>.
354</dd></dl>
355
356<P>
357<dl><dt><b><tt id='l2h-1579' xml:id='l2h-1579'>O_BINARY</tt></b></dt>
358<dd>
359Option for the <var>flag</var> argument to the <tt class="function">open()</tt> function.
360This can be bit-wise OR'd together with those listed above.
361Availability: Windows.
362</dd></dl>
363
364<P>
365<dl><dt><b><tt id='l2h-1580' xml:id='l2h-1580'>O_NOINHERIT</tt></b></dt>
366<dd>
367<dt><b><tt id='l2h-1593' xml:id='l2h-1593'>O_SHORT_LIVED</tt></b></dt><dd>
368<dt><b><tt id='l2h-1594' xml:id='l2h-1594'>O_TEMPORARY</tt></b></dt><dd>
369<dt><b><tt id='l2h-1595' xml:id='l2h-1595'>O_RANDOM</tt></b></dt><dd>
370<dt><b><tt id='l2h-1596' xml:id='l2h-1596'>O_SEQUENTIAL</tt></b></dt><dd>
371<dt><b><tt id='l2h-1597' xml:id='l2h-1597'>O_TEXT</tt></b></dt><dd>
372Options for the <var>flag</var> argument to the <tt class="function">open()</tt> function.
373These can be bit-wise OR'd together.
374Availability: Windows.
375</dd></dl>
376
377<P>
378
379<DIV CLASS="navigation">
380<div class='online-navigation'>
381<p></p><hr />
382<table align="center" width="100%" cellpadding="0" cellspacing="2">
383<tr>
384<td class='online-navigation'><a rel="prev" title="6.1.2 File Object Creation"
385 href="os-newstreams.html"><img src='../icons/previous.png'
386 border='0' height='32' alt='Previous Page' width='32' /></A></td>
387<td class='online-navigation'><a rel="parent" title="6.1 os "
388 href="module-os.html"><img src='../icons/up.png'
389 border='0' height='32' alt='Up One Level' width='32' /></A></td>
390<td class='online-navigation'><a rel="next" title="6.1.4 Files and Directories"
391 href="os-file-dir.html"><img src='../icons/next.png'
392 border='0' height='32' alt='Next Page' width='32' /></A></td>
393<td align="center" width="100%">Python Library Reference</td>
394<td class='online-navigation'><a rel="contents" title="Table of Contents"
395 href="contents.html"><img src='../icons/contents.png'
396 border='0' height='32' alt='Contents' width='32' /></A></td>
397<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
398 border='0' height='32' alt='Module Index' width='32' /></a></td>
399<td class='online-navigation'><a rel="index" title="Index"
400 href="genindex.html"><img src='../icons/index.png'
401 border='0' height='32' alt='Index' width='32' /></A></td>
402</tr></table>
403<div class='online-navigation'>
404<b class="navlabel">Previous:</b>
405<a class="sectref" rel="prev" href="os-newstreams.html">6.1.2 File Object Creation</A>
406<b class="navlabel">Up:</b>
407<a class="sectref" rel="parent" href="module-os.html">6.1 os </A>
408<b class="navlabel">Next:</b>
409<a class="sectref" rel="next" href="os-file-dir.html">6.1.4 Files and Directories</A>
410</div>
411</div>
412<hr />
413<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
414</DIV>
415<!--End of Navigation Panel-->
416<ADDRESS>
417See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
418</ADDRESS>
419</BODY>
420</HTML>