Linux C 学习之 #include <sys/types.h>的作用

#include <sys/types.h>

基本系统数据类型

是Unix/Linux系统的基本系统数据类型的头文件,含有size_t,time_t,pid_t等类型。linux编程中经常用到的头文件。

NAME
sys/types.h - data types

SYNOPSIS
#include <sys/types.h>

DESCRIPTION
The <sys/types.h> header shall include definitions for at least the following types:

blkcnt_t
Used for file block counts.

blksize_t
Used for block sizes.

clock_t
Used for system times in clock ticks or CLOCKS_PER_SEC; see <time.h> .

clockid_t
Used for clock ID type in the clock and timer functions.

dev_t Used for device IDs.

fsblkcnt_t
Used for file system block counts.

fsfilcnt_t
Used for file system file counts.

gid_t Used for group IDs.

id_t Used as a general identifier; can be used to contain at least a pid_t, uid_t, or gid_t.

ino_t Used for file serial numbers.

key_t Used for XSI interprocess communication.

mode_t Used for some file attributes.

nlink_t
Used for link counts.

off_t Used for file sizes.

pid_t Used for process IDs and process group IDs.

size_t Used for sizes of objects.

ssize_t
Used for a count of bytes or an error indication.

suseconds_t
Used for time in microseconds.

time_t Used for time in seconds.

timer_t
Used for timer ID returned by timer_create().

trace_attr_t
Used to identify a trace stream attributes object.

trace_event_id_t
Used to identify a trace event type.

trace_event_set_t
Used to identify a trace event type set.

trace_id_t
Used to identify a trace stream.

uid_t Used for user IDs.

useconds_t
Used for time in microseconds.

All of the types shall be defined as arithmetic types of an appropriate length, with the following exceptions:

key_t
Additionally:

* mode_t shall be an integer type.

* nlink_t, uid_t, gid_t, and id_t shall be integer types.

* blkcnt_t and off_t shall be signed integer types.

* fsblkcnt_t, fsfilcnt_t, and ino_t shall be defined as unsigned integer types.

* size_t shall be an unsigned integer type.

* blksize_t, pid_t, and ssize_t shall be signed integer types.

* time_t and clock_t shall be integer or real-floating types.

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
客户端: #include #include // 包含套接字函数库 #include #include // 包含AF_INET相关结构 #include // 包含AF_INET相关操作的函数 #include #include #include #define PORT 6789 #define IP_ADDR "127.0.0.1" #define SIZE 10240 int main() { struct tm *timeptr; time_t timeval; //时间变量 char tm[50]; int sockfd; // 用于保存客户套接字标识符 int len; // 用于客户消息长度 struct sockaddr_in address; // 定义客户套接字地址结构体 int result; sockfd = socket(AF_INET,SOCK_STREAM, 0); // 定义套接字类型 address.sin_family = AF_INET; // 定义套接字地址中的域 address.sin_addr.s_addr = htonl(INADDR_ANY); address.sin_addr.s_addr = inet_addr(IP_ADDR); // 定义套接字地址 address.sin_port = htons(PORT); // 定义套接字端口 char buf[100]; // 定义要传送的消息 memset(buf,0,100); char str[90]; //存贮输入的语句 char shmaddr[SIZE]; //接受服务器发送的全部聊天数据 int i=0; char myname[100]; char say[10]={"说:"}; printf("欢迎来到聊天室,请输入你的姓名:"); scanf("%s",myname); len = sizeof(address); result = connect(sockfd, (struct sockaddr *) &address, len); // 请求连接 if (result == -1) { perror("Connect failed"); return 1; } printf("%s成功登录服务器:\n",myname); pid_t pid; pid=fork(); if(pid==-1) { printf("fork failed"); } int sendbytes=0; if(pid==0) //子进程用于发送数据 { while(1) { scanf("%s",str); (void)time(&timeval); strcpy(tm,ctime(&timeval)); strcpy(buf,myname); //姓名传入buf中 strcat(buf,":"); strcat(buf,str); strcat(buf," ["); strc

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值