How can I make the program read \"partSize\" amount of bytes and print it to the screen? Let\'s say that I am opening a text file that contains 100 characters in total. If p
You need to check the return value, and update the length in each iteration:
ssize_t count, total;
total = 0;
char *buf = BUFFER;
while (partSize) {
count = read(openDescriptorOriginal, buf, partSize);
if (count < 0) {
/* handle error */
break;
}
if (count == 0)
break;
buf += count;
total += count;
partSize -= count;
}
write (1, BUFFER, total);
total
will contain the number of bytes read.