- 论坛徽章:
- 0
|
请问是不是当描述字对应的流关闭时,其对应的描述字也同时关闭了,如下
- #include <unistd.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <errno.h>
- void err_sys(const char *errmsg);
- int main(int argc, char **argv)
- {
- FILE *fout;
- char buff[] = "yinshulei\n";
-
- if ((fout = fdopen(STDOUT_FILENO, "w")) == NULL)
- err_sys("fdopen error");
- else {
- if (fclose(fout) == EOF)
- err_sys("fclose error");
- if (write(STDOUT_FILENO, buff, strlen(buff)) != strlen(buff))
- err_sys("write error");
- }
- exit(0);
- }
- void err_sys(const char *errmsg)
- {
- perror(errmsg);
- exit(errno);
- }
复制代码
[root@localhost root]# gcc 2.c -o 2
[root@localhost root]# ./2
write error: Bad file descriptor
[root@localhost root]# |
|