19,620
社区成员




int isatty(int filedes);
返回值:若为终端设备则返回1(真),否则返回0(假)
标准输入就是多行,其它单行[quote=引用 11 楼 yuelengdihai 的回复:] 根据头文件include路径平行向下搜索
根据头文件include路径平行向下搜索
[quote=引用 7 楼 yuelengdihai 的回复:] [quote=引用 4 楼 ipqtjmqj 的回复:] [quote=引用 3 楼 yuelengdihai 的回复:] 补充下楼上的:返回值:若为终端设备则返回1(真),否则返回0(假) 标准输入就是多行,其它单行int isatty(int filedes);
#include <termios.h>
int isatty(int fd)
{
struct termios ts;
return(tcgetattr(fd,&ts) != -1);
}
调用tcgetattr获取终端信息[/quote]
那tcgetattr的原理呢
我试过,不管是否重定向,fd的值是一样的,所以变化的应该是其他标志[/quote]
fd是固定的值,不会变的。tcgetattr是根据fd获取设备信息保存到ts结构体中,这个函数我也没搜到,编译到库中了[quote=引用 4 楼 ipqtjmqj 的回复:] [quote=引用 3 楼 yuelengdihai 的回复:] 补充下楼上的:返回值:若为终端设备则返回1(真),否则返回0(假) 标准输入就是多行,其它单行int isatty(int filedes);
#include <termios.h>
int isatty(int fd)
{
struct termios ts;
return(tcgetattr(fd,&ts) != -1);
}
调用tcgetattr获取终端信息[/quote]
那tcgetattr的原理呢
我试过,不管是否重定向,fd的值是一样的,所以变化的应该是其他标志[quote=引用 3 楼 yuelengdihai 的回复:] 补充下楼上的:返回值:若为终端设备则返回1(真),否则返回0(假) 标准输入就是多行,其它单行int isatty(int filedes);
#include <termios.h>
int isatty(int fd)
{
struct termios ts;
return(tcgetattr(fd,&ts) != -1);
}
调用tcgetattr获取终端信息
// 第1659行
case LS_LS:
/* This is for the 'ls' program. */
if (isatty (STDOUT_FILENO))
{
format = many_per_line;
set_quoting_style (NULL, shell_escape_quoting_style);
/* See description of qmark_funny_chars, above. */
qmark_funny_chars = true;
}
else
{
format = one_per_line;
qmark_funny_chars = false;
}
break;