http://blog.sina.com.cn/s/blog_6a1837e9010112ah.html

 isatty(判断文件描述词是否是为终端机

相关函数 ttyname
表头文件 #include<unistd.h>
定义函数 int isatty(int desc);
函数说明 如果参数desc所代表的文件描述词为一终端机则返回1,否则返回0。
返回值 如果文件为终端机则返回1,否则返回0。

例如:

#include<stdio.h>
#include<unistd.h>

int main()
{
       int fd;

       int ret = isatty(fileno(stdout));
       printf("%d\n", ret);

       fd=open("./yushu.c", 0);

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

       close(fd);

       return 0;
}

输出结果:

1

0

相关文章:

  • 2021-06-25
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
猜你喜欢
  • 2022-01-02
  • 2021-08-02
  • 2021-10-22
  • 2022-12-23
  • 2021-07-11
  • 2022-12-23
相关资源
相似解决方案