曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 5207|回复: 0
打印 上一主题 下一主题

[文件I/O] fileno() -- 返回流的文件描述符

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34395
跳转到指定楼层
楼主
发表于 2010-5-28 00:13:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
原型
#include <stdio.h>
int fileno(FILE *stream);
说明
fileno() 函数返回一个和某流的文件描述符。

示例程序
#include <stdio.h>
#include <unistd.h>

int main ()
{
    FILE *stream;

    printf ("stdin is: %d\n", fileno(stdin));
    printf ("stdout is: %d\n", fileno(stdout));
    printf ("stderr is: %d\n", fileno(stderr));

    stream = fopen ("./mps.c", "r");

    printf ("new open file's fd is: %d\n", fileno(stream));

    fclose (stream);

    return (0);
}
运行输出
./fileno
stdin is: 0
stdout is: 1
stderr is: 2
new open file's fd is: 3
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-5-4 00:24 , Processed in 0.067514 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表