kuba
kuba

Reputation: 7389

Linux read() minimum data amount

When using read() syscall in Linux for reading from whatever source (file, socket, pipe), is there a minimum data amount that can be returned (in blocking mode)? Or can the syscall even return 1 byte?

When I want to read a single int (4 or 8 bytes) from a pipe, do I still need to check the return value of read() to see if I received less than sizeof(int) bytes?

Upvotes: 2

Views: 456

Answers (1)

geekosaur
geekosaur

Reputation: 61369

There is no minimum, except on block mode devices where the minimum is the block size.

You should always check the return value; things can break, you should plan for breakage and handle short reads and errors appropriately instead of assuming the other side is always perfect.

Upvotes: 5

Related Questions