赞
踩
open函数相关的: /* open 是系统调用 返回的是文件句柄*/
- <span style="font-size:18px;">#include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
-
- int open(const char *pathname, int flags);
- int open(const char *pathname, int flags, mode_t mode);</span>
- <span style="font-size:18px;">#include <stdio.h>
-
- FILE *fopen(const char *path, const char *mode);
-
- FILE *fdopen(int fd, const char *mode);
-
- FILE *freopen(const char *path, const char *mode, FILE *stream);</span>
函数说明:fileno()用来取得参数stream 指定的文件流所使用的文件描述词.
- <span style="font-size:18px;">#include <stdio.h>
-
- void clearerr(FILE *stream);
-
- int feof(FILE *stream);
-
- int ferror(FILE *stream);
-
- int fileno(FILE *stream);</span>
举例说明:
- <span style="font-size:18px;">#include <stdio.h>
-
- int main(int argc, char **argv)
-
- {
- FILE * fp;
- int fd;
- fp = fopen("/etc/passwd", "r");
- fd = fileno(fp);
- printf("fd=%d\n", fd);
- fclose(fp);
- return 0;
- }</span>
open和fopen的区别参考这篇文
章:http://blog.csdn.net/qq_21792169/article/details/50160857
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。