why define size_t ssize_t ?

本文详细介绍了ssize_t数据类型及其用途,ssize_t用于表示可以一次性读写的数据块大小,它类似于size_t但必须是有符号类型。文章还解释了如何使用read函数进行文件读取操作,并返回实际读取到的字节数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

why define size_t ssize_t ?

http://blog.youkuaiyun.com/yuwenliang/archive/2010/01/18/5207491.aspx

 

 

ssize_t说明

Data Type: ssize_t
This data type is used to represent the sizes of blocks that can be read or written in a single operation. It is similar to size_t , but must be a signed type.

 

Function: ssize_t read (int filedes , void *buffer , size_t size )
The read function reads up to size bytes from the file with descriptor filedes , storing the results in the buffer . (This is not necessarily a character string, and no terminating null character is added.)

The return value is the number of bytes actually read. This might be less than size ; for example, if there aren't that many bytes left in the file or if there aren't that many bytes immediately available. The exact behavior depends on what kind of file it is. Note that reading less than size bytes is not an error.

A value of zero indicates end-of-file (except if the value of the size argument is also zero). This is not considered an error. If you keep calling read while at end-of-file, it will keep returning zero and doing nothing else.

If read returns at least one character, there is no way you can tell whether end-of-file was reached. But if you did reach the end, the next read will return zero.

In case of an error, read returns -1 .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值