Home > Database > Mysql Tutorial > body text

open函数的返回值可能是0,1,2这三个中的任意一个吗?

WBOY
Release: 2016-06-07 15:07:24
Original
2266 people have browsed it

今天纠结dup的时候,无意间发现,open的返回让我有点不敢相信,百思不得其解。 因为我不敢相信“返回是0”,STDIN_FILENO,STDOUT_FILENO,STDERR_FILENO,分别对应的是0,1,2这三个file descriptor 问题出在下面这行代码上面 if(file_descriptor = open(./te

今天纠结dup的时候,无意间发现,open的返回值让我有点不敢相信,百思不得其解。

因为我不敢相信“返回值是0”,STDIN_FILENO,STDOUT_FILENO,STDERR_FILENO,分别对应的是0,1,2这三个file descriptor


问题出在下面这行代码上面

	if(file_descriptor = open("./text.t",O_RDWR) 
<p>我一直觉得open的返回值最小是3,但是自己写的代码出来的结果却是0,纳闷啊。。。<br>
</p>
<p>打印的结果是:</p>
<p>file descriptor is 0<br>
dup2 return value:4<br>
 dup return value 4<br>
dup2 return value:5<br>
dup return value 5<br>
dup2 return value:6<br>
dup return value 6<br>
</p>
<p>教训是没事别少写括号。。。没有必要去纠结这种优先级的问题,保持良好的习惯,写括号,OK</p>
<pre class="brush:php;toolbar:false">	if((file_descriptor = open("./text.t",O_RDWR)) 这样就OK了
<p>file descriptor is 3<br>
dup2 return value:4<br>
 dup return value 4<br>
dup2 return value:5<br>
dup return value 5<br>
dup2 return value:6<br>
dup return value 6<br>
</p>
<p>经过这次小纠结,有一点共识得到强化,open的返回值不可能是0,1,2,这三个file descriptor是一直被打开的(除非在某个进程内被暂时关闭)。</p>
<p><br>
</p>
<p><br>
</p>
<p><br>
</p>


Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template