| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 605 人关注过本帖
标题:fcntl() function question?
只看楼主 加入收藏
Linux_good
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-6-21
收藏
 问题点数:0 回复次数:7 
fcntl() function question?
why? follow program output: fd = 0.

#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int fd;

if ((fd = fcntl(STDOUT_FILENO, F_GETFD, 0)) == -1)
{
printf("fcntl error.\n");
}

printf("fd = %d\n", fd);

exit(0);
}

I think output: fd = 1. where error?
搜索更多相关主题的帖子: function question include follow 
2006-06-22 15:18
–★–
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1512
专家分:0
注 册:2006-5-1
收藏
得分:0 
Sorry,your program cannot run under my Turbo C or Visual C++ compilers.

落霞与孤鹜齐飞,秋水共长天一色! 心有多大,路有多宽。三教九流,鸡鸣狗盗。兼收并蓄,海纳百川。
2006-06-22 16:03
Linux_good
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-6-21
收藏
得分:0 
compiler cc or gcc
2006-06-22 16:06
–★–
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1512
专家分:0
注 册:2006-5-1
收藏
得分:0 
I have no such compilers available.
May be somebody could help you.

落霞与孤鹜齐飞,秋水共长天一色! 心有多大,路有多宽。三教九流,鸡鸣狗盗。兼收并蓄,海纳百川。
2006-06-22 16:11
cordier
Rank: 2
等 级:论坛游民
威 望:1
帖 子:449
专家分:14
注 册:2006-2-9
收藏
得分:0 
From what have discussed above, i found my English is bad.

2006-06-23 08:31
–★–
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1512
专家分:0
注 册:2006-5-1
收藏
得分:0 
以下是Linux_good在2006-6-22 15:18:28的发言(翻译):
为什么? 下列程序输出: fd = 0.


#include <sys/types.h>

#include <unistd.h>

#include <fcntl.h>

#include <stdio.h>

#include <stdlib.h>


int main(void)

{

int fd;


if ((fd = fcntl(STDOUT_FILENO, F_GETFD, 0)) == -1)

{

printf("fcntl error.\n");

}


printf("fd = %d\n", fd);


exit(0);

}


我认为输出应为: fd = 1. 哪儿错了?


[译者注]楼主用的是cc或gcc编译器。


落霞与孤鹜齐飞,秋水共长天一色! 心有多大,路有多宽。三教九流,鸡鸣狗盗。兼收并蓄,海纳百川。
2006-06-23 08:39
aogun
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:638
专家分:0
注 册:2006-4-5
收藏
得分:0 
int fcntl(int fd,int cmd,long arg);
函数的返回值代表是否成功,如果成功,则返回0,失败则返回-1,为什么lz会认为返回1呢?

世界上总共有 10 种人,一种懂得什么是二进制 ,一种不懂。
2006-06-23 17:35
aogun
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:638
专家分:0
注 册:2006-4-5
收藏
得分:0 
而且lz的理解似乎有点错误,fd代表欲设置的文件描述,怎么用来接收返回的错误值呢?

世界上总共有 10 种人,一种懂得什么是二进制 ,一种不懂。
2006-06-23 17:38
快速回复:fcntl() function question?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012252 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved