免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 12171 | 回复: 6
打印 上一主题 下一主题

[函数] isatty()函数 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-06-07 12:08 |只看该作者 |倒序浏览
isatty()函数:
#include <unistd.h>
int isatty(int fd)
如果fd与一个打开的终端相连,则isatty()返回1,否则返回0。
怎样弄明白“fd与一个打开的终端相连”,

论坛徽章:
0
2 [报告]
发表于 2007-06-07 12:12 |只看该作者
fd is associated with an open terminal

论坛徽章:
0
3 [报告]
发表于 2007-06-07 21:40 |只看该作者
使能够切换标准输入和输出到扫描(scan)模式以及相反(即禁止回送,禁止信号,禁止典型模式和设置成从read()l立即返回字符)
#my_termios.c
#include <stdio.h>
#include <unistd.h>
struct termios tsave;
void scan_mode(void)
{
      struct termios tbuf;
      if(isatty(0))
               fatal("error");
      if(tcgetattr(0,&buf)==-1)
                fatal("getting termios error");
      tsave=tbuf;
      tbuf.c_lflag&=~(ECHO | ICANON | ISIG);
      tbuf.c_cc[VMIN]=tbuf.c_cc[VTIME]=0;
      if(tcsetattr(0,TCSANOW,&tbuf)==-1)
                fatal("setting termios error");  
}
void restore_mode(void)
{
       if(tcsetattr(0,ICSANOW,&tsave)==-1)
                fatal("restore error");  
}
...........
...........
#gcc -o my_termios my_termios.c
#./my_termios
error



??????为什么会输出error???

论坛徽章:
95
程序设计版块每日发帖之星
日期:2015-09-05 06:20:00程序设计版块每日发帖之星
日期:2015-09-17 06:20:00程序设计版块每日发帖之星
日期:2015-09-18 06:20:002015亚冠之阿尔艾因
日期:2015-09-18 10:35:08月度论坛发贴之星
日期:2015-09-30 22:25:002015亚冠之阿尔沙巴布
日期:2015-10-03 08:57:39程序设计版块每日发帖之星
日期:2015-10-05 06:20:00每日论坛发贴之星
日期:2015-10-05 06:20:002015年亚冠纪念徽章
日期:2015-10-06 10:06:482015亚冠之塔什干棉农
日期:2015-10-19 19:43:35程序设计版块每日发帖之星
日期:2015-10-21 06:20:00每日论坛发贴之星
日期:2015-09-14 06:20:00
4 [报告]
发表于 2007-06-07 21:48 |只看该作者
原帖由 w490978025 于 2007-6-7 21:40 发表
使能够切换标准输入和输出到扫描(scan)模式以及相反(即禁止回送,禁止信号,禁止典型模式和设置成从read()l立即返回字符)
#my_termios.c
#include <stdio.h>
#include <unistd.h>
struct ter ...


      if(isatty(0))
               fatal("error");

这句符合你的本意?

论坛徽章:
0
5 [报告]
发表于 2007-06-07 21:56 |只看该作者
哦。写错了
是if(!isatty(0))
               fatal("error");

论坛徽章:
0
6 [报告]
发表于 2010-08-09 15:40 |只看该作者
NAME
       isatty - does this descriptor refer to a terminal

SYNOPSIS
       #include <unistd.h>

       int isatty(int desc);

DESCRIPTION
       returns 1 if desc is an open descriptor connected to a terminal and 0 else.

CONFORMING TO
       SVr4, 4.3BSD, POSIX.1-2001

论坛徽章:
0
7 [报告]
发表于 2010-08-09 15:49 |只看该作者
man一下是最靠谱的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP