Consider the following program:
------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main (void)
{
size_t count = (size_t) 3 << 30;
ssize_t ret;
void *buf;
int fd;
printf ("SSIZE_MAX = 0x%zx\n", (ssize_t) SSIZE_MAX);
printf ("count = 0x%zx\n", count);
if (count > SSIZE_MAX)
{
fprintf (stderr, "count is too large\n");
return 1;
}
buf = malloc (count);
if (buf == NULL)
{
fprintf (stderr, "malloc() failed\n");
return 1;
}
fd = open ("text", O_RDONLY);
if (fd == -1)
{
fprintf (stderr, "open() failed\n");
return 1;
}
ret = read (fd, buf, count);
printf ("#bytes read = 0x%zx\n", ret);
return 0;
}
------------------------------------------------------------
When I create a regular 6GB file "text" and run this program, I get:
SSIZE_MAX = 0x7fffffffffffffff
count = 0xc0000000
#bytes read = 0x7ffff000
i.e. read() has returned a value less than the byte count provided
in argument (nbyte in POSIX).
http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html
says:
The value returned may be less than nbyte if the number of bytes left
in the file is less than nbyte, if the read() request was interrupted
by a signal, or if the file is a pipe or FIFO or special file and has
fewer than nbyte bytes immediately available for reading.
Here, the file has more than nbyte bytes, there wasn't any signal,
and the file is a regular file. Therefore nbyte bytes should have
been read, not less!