readlink函数 linux,readv()函数 Unix/Linux

readv, writev - 读取或写入数据到多个缓冲区

内容简介

#include

ssize_t readv(intfd, const struct iovec *vector, intcount);

ssize_t writev(intfd, const struct iovec *vector, intcount);

描述

Thereadv() function reads count blocks from the file associated with the file descriptor fdinto the multiple buffers described by vector.

The writev() function writes at most count blocks described by vector to the file associated with the file descriptor fd.

The pointer vector points to a struct iovec defined in  as :

struct iovec {

void *iov_base; /* Starting address */

size_t iov_len; /* Number of bytes */

};

Buffers are processed in the order specified. The readv() function works just likeread(2) except that multiple buffers are filled.

The writev() function works just like write(2) except that multiple buffers are written out.

返回值

On success, the readv() function returns the number of bytes read; the writev() function returns the number of bytes written. On error, -1 is returned, and errno is set appropriately.

错误

The errors are as given for read(2) and write(2). Additionally the following error is defined:

标签

描述

EINVAL

The sum of the iov_len values overflows an ssize_t value. Or, the vector count count is less than zero or greater than the permitted maximum.

遵循于

4.4BSD (the readv() and writev() functions first appeared in 4.2BSD), POSIX.1-2001. Linux libc5 used size_t as the type of the count parameter, and int as return type for these functions.

LINUX 注意

POSIX.1-2001 allows an implementation to place a limit on the number of items that can be passed in vector. An implementation can advertise its limit by defining IOV_MAX in or at run time via the return value from sysconf(_SC_IOV_MAX). On Linux, the limit advertised by these mechanisms is 1024, which is the true kernel limit.

However, the glibc wrapper functions do some extra work if they detect that the underlying kernel system call failed because this limit was exceeded. In the case ofreadv() the wrapper function allocates a temporary buffer large enough for all of the items specified by vector, passes that buffer in a call to read(), copies data from the buffer to the locations specified by the iov_base fields of the elements of vector, and then frees the buffer.

The wrapper function for writev() performs the analogous task using a temporary buffer and a call to write().

BUGS

It is not advisable to mix calls to functions like readv() or writev(), which operate on file descriptors, with the functions from the stdio library; the results will be undefined and probably not what you want.

另请参阅

¥ 我要打赏

纠错/补充

收藏

加QQ群啦,易百教程官方技术学习群

注意:建议每个人选自己的技术方向加群,同一个QQ最多限加 3 个群。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值