Use int value provided by fgetc() to compare against EOF. Casting to char and back to int won't work on specific architectures.

Example on ppc64 for the old code:
fgetc() reads 0xFFFFFFFF (int, -1). Then converted to 0xFF (char, ÿ).
Then converted to 0x000000FF (int, ÿ).
Compared against EOF macro 0xFFFFFFFF (int, -1).
Obviously not the same value.