Use stdint.h types and change some fgets to fread.