isatty()函数
头文件:
?
1
|
#include <unistd.h>
|
定义函数:
?
1
|
int isatty( int desc);
|
函数说明:如果参数 desc 所代表的文件描述词为一终端机则返回1, 否则返回0.
返回值:如果文件为终端机则返回1, 否则返回0.
?
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语言sendmsg()函数:经socket传送数据
头文件:
?
1
|
#include <sys/types.h> #include <sys/socket.h>
|
定义函数:
?
1
|
int sendmsg( int s, const strcut msghdr *msg, unsigned int flags);
|
函数说明:sendmsg()用来将数据由指定的socket 传给对方主机. 参数s 为已建立好连线的socket, 如果利用UDP 协议则不需经过连线操作. 参数msg 指向欲连线的数据结构内容, 参数flags 一般默认为0, 详细描述请参考send().
结构msghdr 定义如下:
?
1
2
3
4
5
6
7
8
9
10
|
struct msghdr
{
void *msg_name; //Address to send to /receive from .
socklen_t msg_namelen; //Length of addres data
strcut iovec * msg_iov; //Vector of data to send/receive into
size_t msg_iovlen; //Number of elements in the vector
void * msg_control; //Ancillary dat
size_t msg_controllen; //Ancillary data buffer length
int msg_flags; //Flags on received message
};
|
返回值:成功则返回实际传送出去的字符数, 失败返回-1, 错误原因存于errno
错误代码:
1、EBADF 参数s 非合法的socket 处理代码.
2、EFAULT 参数中有一指针指向无法存取的内存空间
3、ENOTSOCK 参数s 为一文件描述词, 非socket.
4、EINTR 被信号所中断.
5、EAGAIN 此操作会令进程阻断, 但参数s 的socket 为不可阻断.
6、ENOBUFS 系统的缓冲内存不足
7、ENOMEM 核心内存不足 EINVAL 传给系统调用的参数不正确.
相关文章
猜你喜欢
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-25 74
-
2025-05-25 67
-
2025-05-29 64
-
2025-06-04 42
-
2025-05-27 101
热门评论