C语言ttyname()函数:返回一终端机名称
头文件:
| 1 |
#include <unistd.h>
|
定义函数:
?| 1 |
char * ttyname(int desc);
|
函数说明:如果参数desc 所代表的文件描述词为一终端机, 则会将此终端机名称由一字符串指针返回, 否则返回NULL.
返回值:如果成功则返回指向终端机名称的字符串指针, 有错误情况发生时则返回NULL.
范例
?| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
main()
{
int fd;
char * file = "/dev/tty";
fd = open (fiel, O_RDONLY);
printf("%s", file);
if(isatty(fd))
{
printf("is a tty. \n");
printf("ttyname = %s \n", ttyname(fd));
}
else
printf(" is not a tty\n");
close(fd);
}
|
执行:
?| 1 |
/dev/tty is a tty ttyname = /dev/tty
|
C语言isatty()函数:判断文件描述词是否是为终端机
头文件:
| 1 |
#include <unistd.h>
|
定义函数:
?| 1 |
int isatty(int desc);
|
函数说明:如果参数 desc 所代表的文件描述词为一终端机则返回1, 否则返回0.
返回值:如果文件为终端机则返回1, 否则返回0.








发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。