>
has a higher precedence than =
, therefore
if ((byte_read_f1 = read(f1, buf1, sizeof buf1) > 0) && ...)
is equivalent to
if (byte_read_f1 = (read(f1, buf1, sizeof buf1) > 0) && ...)
which assigns 1
to byte_read_f1
if at least one byte was read.
What you want is
if ((byte_read_f1 = read(f1, buf1, sizeof buf1)) > 0 && ...)
If your program reads from other than regular files (such as standard input) then you have also to consider the case that a read() returns less bytes than requested.
For regular files, read() always returns the number of bytes requested,
with the only exception at end-of-file of course. Therefore, if the files differ in length,
then at some point, read(f1, ...)
will return a different amount than read(f2, ...)
,
or one returns zero and the other not.