Chinaunix

标题: isatty()函数 [打印本页]

作者: w490978025    时间: 2007-06-07 12:08
标题: isatty()函数
isatty()函数:
#include <unistd.h>
int isatty(int fd)
如果fd与一个打开的终端相连,则isatty()返回1,否则返回0。
怎样弄明白“fd与一个打开的终端相连”,
作者: langue    时间: 2007-06-07 12:12
fd is associated with an open terminal
作者: w490978025    时间: 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???
作者: MMMIX    时间: 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");

这句符合你的本意?
作者: w490978025    时间: 2007-06-07 21:56
哦。写错了
是if(!isatty(0))
               fatal("error");
作者: rain_fish    时间: 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
作者: daybreakcx    时间: 2010-08-09 15:49
man一下是最靠谱的




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2