您的位置:首页 > 编程语言 > C语言/C++

C语言之fileno()函数

2016-04-05 22:28 423 查看
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>

fopen函数相关的:   /*
open是ANSIC标准中的C语言库函数,在不同的系统中应该调用不同的内核api  */

<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>
linux中的系统函数是open,fopen是其封装函数,个人观点。

open和fopen的区别参考这篇文

章:http://blog.csdn.net/qq_21792169/article/details/50160857
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: