a*********9 发帖数: 523 | 1 不少EXAMPLE是用fopen打开一个FP,再用这个FP作为fdopen的参数创建一个新的FP2,
然后所有读
写直接在FP2上进行。
是不是fdopen 有BUFFER 的作用呢? |
|
z***9 发帖数: 696 | 2 fdopen has nothing to do with fopen, but system call open
The fdopen() function associates a stream with the existing file
descriptor. |
|
d********f 发帖数: 8289 | 3 sorry, 我没有说清楚。我是说比如fp1 = fdopen(fd, "r"); 用过之后还能够做fp2 =
fdopen(fd, "r")吗?还是要先close了fp1?可是close了fp1, fd也就被close了,
right?
process |
|
c**t 发帖数: 2744 | 4 我想在某个routine中将STDERR定向到文件,routine结束后,取消定向。
sub func
{
open(ERROR, "> somefile");
STDERR->fdopen(\*ERROR, "w);
...
close(ERROR);
}
问题是此后STDERR都消失了,怎么让它重新回到STDERR? |
|
|
W***o 发帖数: 6519 | 6 sorry, I misspoke. fd is just an index in the file table of your own process
, fd is not a PID. To answer your question, another open is not necessary,
because the fd stays in the file table until you close it. |
|
S*A 发帖数: 7142 | 7 fd 是 file descriptor, 为什么是 process id? 不太明白。 process 是
另外一个概念啊。 |
|
p****f 发帖数: 251 | 8 you can open a file as many time as you can, each FP point to different
entry in the kernel, unless you do system call dup, which will only
duplicate the descriptor.
= |
|
|
|