uTools-Manuals/docs/php/dio_open.html
2019-04-08 23:22:26 +08:00

181 lines
6.8 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Opens a file (creating it if necessary) at a lower level than the
C library input/ouput stream functions allow</title>
</head>
<body class="docs"></div>
<div id="layout">
<div id="layout-content"><div id="function.dio-open" class="refentry">
<div class="refnamediv">
<h1 class="refname">dio_open</h1>
<p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5 &lt; 5.1.0)</p><p class="refpurpose"><span class="refname">dio_open</span> &mdash; <span class="dc-title">
Opens a file (creating it if necessary) at a lower level than the
C library input/ouput stream functions allow
</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.dio-open-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>dio_open</strong></span>
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code></span>
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$mode</code><span class="initializer"> = 0</span></span>
] ) : <span class="type">resource</span></div>
<p class="para rdfs-comment">
<span class="function"><strong>dio_open()</strong></span> opens a file and returns a new file
descriptor for it.
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.dio-open-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">filename</code></dt>
<dd>
<p class="para">
The pathname of the file to open.
</p>
</dd>
<dt>
<code class="parameter">flags</code></dt>
<dd>
<p class="para">
The <code class="parameter">flags</code> parameter is a bitwise-ORed
value comprising flags from the following list. This value
<em class="emphasis">must</em> include one of
<strong><code>O_RDONLY</code></strong>, <strong><code>O_WRONLY</code></strong>,
or <strong><code>O_RDWR</code></strong>. Additionally, it may include
any combination of the other flags from this list.
<ul class="itemizedlist">
<li class="listitem">
<p class="para">
<strong><code>O_RDONLY</code></strong> - opens the file for read access.
</p>
</li>
<li class="listitem">
<p class="para">
<strong><code>O_WRONLY</code></strong> - opens the file for write access.
</p>
</li>
<li class="listitem">
<p class="para">
<strong><code>O_RDWR</code></strong> - opens the file for both reading and
writing.
</p>
</li>
<li class="listitem">
<p class="para">
<strong><code>O_CREAT</code></strong> - creates the file, if it doesn&#039;t
already exist.
</p>
</li>
<li class="listitem">
<p class="para">
<strong><code>O_EXCL</code></strong> - if both <strong><code>O_CREAT</code></strong>
and <strong><code>O_EXCL</code></strong> are set and the file already
exists, <span class="function"><strong>dio_open()</strong></span> will fail.
</p>
</li>
<li class="listitem">
<p class="para">
<strong><code>O_TRUNC</code></strong> - if the file exists and is opened
for write access, the file will be truncated to zero length.
</p>
</li>
<li class="listitem">
<p class="para">
<strong><code>O_APPEND</code></strong> - write operations write data at the
end of the file.
</p>
</li>
<li class="listitem">
<p class="para">
<strong><code>O_NONBLOCK</code></strong> - sets non blocking mode.
</p>
</li>
<li class="listitem">
<p class="para">
<strong><code>O_NOCTTY</code></strong> - prevent the OS from
assigning the opened file as the process&#039;s controlling
terminal when opening a TTY device file.
</p>
</li>
</ul>
</p>
</dd>
<dt>
<code class="parameter">mode</code></dt>
<dd>
<p class="para">
If <code class="parameter">flags</code> contains
<strong><code>O_CREAT</code></strong>, <code class="parameter">mode</code> will
set the permissions of the file (creation
permissions). <code class="parameter">mode</code> is required for
correct operation when <strong><code>O_CREAT</code></strong> is
specified in <code class="parameter">flags</code> and is ignored
otherwise.
</p>
<p class="para">
The actual permissions assigned to the created file will be
affected by the process&#039;s <em class="emphasis">umask</em> setting as
per usual.
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.dio-open-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
A file descriptor or <strong><code>FALSE</code></strong> on error.
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.dio-open-examples">
<h3 class="title">范例</h3>
<div class="example" id="example-2743">
<p><strong>Example #1 Opening a file descriptor</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$fd&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dio_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'/dev/ttyS0'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">O_RDWR&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">O_NOCTTY&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">O_NONBLOCK</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">dio_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</div>
<div class="refsect1 seealso" id="refsect1-function.dio-open-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="dio_close.html" class="function" rel="rdfs-seeAlso">dio_close()</a> - Closes the file descriptor given by fd</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>