'unistd.h'函数'read'的读取限制是多少? [英] What is the reading limit of function 'read' in 'unistd.h'?

查看:227
本文介绍了'unistd.h'函数'read'的读取限制是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准的unix C有这样的功能:

pre $ ssize_t read(int fd,void * buf,size_t count);

但这个读取函数读取的最大字节数是多少?

解决方案通常,它可以读取 buf 中可用的字节数。实际上,底层设备驱动程序(无论是文件系统还是网络,还是管道)在没有任何可用的情况下将返回比您想要的更少的内容。



因此, read 的特定行为取决于内核中的底层驱动程序。



这就是为什么它很重要总是检查读取的返回值,并检查读取的实际字节。


Standard unix C has this function:

ssize_t read(int fd, void *buf, size_t count);

But what is the maximum bytes that this 'read' function can read 1 time?

解决方案

Generally it can read as many bytes as there are available in buf. In reality, the underlying device driver (be it the filesystem or the network, or a pipe), would return less than what you want in case there is nothing more available.

So, the particular behaviour of read depends on the underlying driver in the kernel.

This is why it's important to always check the return value of read and examine the actual bytes read.

这篇关于'unistd.h'函数'read'的读取限制是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆